| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/download/download_status_updater.h" | 5 #include "chrome/browser/download/download_status_updater.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "chrome/browser/download/download_util.h" |
| 11 | 12 |
| 12 DownloadStatusUpdater::DownloadStatusUpdater() { | 13 DownloadStatusUpdater::DownloadStatusUpdater() { |
| 13 } | 14 } |
| 14 | 15 |
| 15 DownloadStatusUpdater::~DownloadStatusUpdater() { | 16 DownloadStatusUpdater::~DownloadStatusUpdater() { |
| 16 for (std::set<content::DownloadManager*>::iterator it = managers_.begin(); | 17 for (std::set<content::DownloadManager*>::iterator it = managers_.begin(); |
| 17 it != managers_.end(); ++it) | 18 it != managers_.end(); ++it) |
| 18 (*it)->RemoveObserver(this); | 19 (*it)->RemoveObserver(this); |
| 19 | 20 |
| 20 for (std::set<content::DownloadItem*>::iterator it = items_.begin(); | 21 for (std::set<content::DownloadItem*>::iterator it = items_.begin(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 51 | 52 |
| 52 // Methods inherited from content::DownloadManager::Observer. | 53 // Methods inherited from content::DownloadManager::Observer. |
| 53 void DownloadStatusUpdater::ModelChanged(content::DownloadManager* manager) { | 54 void DownloadStatusUpdater::ModelChanged(content::DownloadManager* manager) { |
| 54 std::vector<content::DownloadItem*> downloads; | 55 std::vector<content::DownloadItem*> downloads; |
| 55 manager->SearchDownloads(string16(), &downloads); | 56 manager->SearchDownloads(string16(), &downloads); |
| 56 | 57 |
| 57 for (std::vector<content::DownloadItem*>::iterator it = downloads.begin(); | 58 for (std::vector<content::DownloadItem*>::iterator it = downloads.begin(); |
| 58 it != downloads.end(); ++it) { | 59 it != downloads.end(); ++it) { |
| 59 UpdateItem(*it); | 60 UpdateItem(*it); |
| 60 } | 61 } |
| 62 |
| 63 UpdateAppIconDownloadProgress(); |
| 61 } | 64 } |
| 62 | 65 |
| 63 void DownloadStatusUpdater::ManagerGoingDown( | 66 void DownloadStatusUpdater::ManagerGoingDown( |
| 64 content::DownloadManager* manager) { | 67 content::DownloadManager* manager) { |
| 65 DCHECK(ContainsKey(managers_, manager)); | 68 DCHECK(ContainsKey(managers_, manager)); |
| 66 managers_.erase(manager); | 69 managers_.erase(manager); |
| 67 manager->RemoveObserver(this); | 70 manager->RemoveObserver(this); |
| 68 // Item removal will be handled in response to DownloadItem REMOVING | 71 // Item removal will be handled in response to DownloadItem REMOVING |
| 69 // notification (in the !IN_PROGRESS conditional branch in UpdateItem). | 72 // notification (in the !IN_PROGRESS conditional branch in UpdateItem). |
| 70 } | 73 } |
| 71 | 74 |
| 72 void DownloadStatusUpdater::SelectFileDialogDisplayed( | 75 void DownloadStatusUpdater::SelectFileDialogDisplayed( |
| 73 content::DownloadManager* manager, int32 id) { | 76 content::DownloadManager* manager, int32 id) { |
| 74 } | 77 } |
| 75 | 78 |
| 76 // Methods inherited from content::DownloadItem::Observer. | 79 // Methods inherited from content::DownloadItem::Observer. |
| 77 void DownloadStatusUpdater::OnDownloadUpdated( | 80 void DownloadStatusUpdater::OnDownloadUpdated( |
| 78 content::DownloadItem* download) { | 81 content::DownloadItem* download) { |
| 79 UpdateItem(download); | 82 UpdateItem(download); |
| 83 UpdateAppIconDownloadProgress(); |
| 80 } | 84 } |
| 81 | 85 |
| 82 void DownloadStatusUpdater::OnDownloadOpened(content::DownloadItem* download) { | 86 void DownloadStatusUpdater::OnDownloadOpened(content::DownloadItem* download) { |
| 83 } | 87 } |
| 84 | 88 |
| 89 void DownloadStatusUpdater::UpdateAppIconDownloadProgress() { |
| 90 float progress = 0; |
| 91 int download_count = 0; |
| 92 bool progress_known = GetProgress(&progress, &download_count); |
| 93 download_util::UpdateAppIconDownloadProgress(download_count, |
| 94 progress_known, |
| 95 progress); |
| 96 } |
| 97 |
| 85 // React to a transition that a download associated with one of our | 98 // React to a transition that a download associated with one of our |
| 86 // download managers has made. Our goal is to have only IN_PROGRESS | 99 // download managers has made. Our goal is to have only IN_PROGRESS |
| 87 // items on our set list, as they're the only ones that have relevance | 100 // items on our set list, as they're the only ones that have relevance |
| 88 // to GetProgress() return values. | 101 // to GetProgress() return values. |
| 89 void DownloadStatusUpdater::UpdateItem(content::DownloadItem* download) { | 102 void DownloadStatusUpdater::UpdateItem(content::DownloadItem* download) { |
| 90 if (download->GetState() == content::DownloadItem::IN_PROGRESS) { | 103 if (download->GetState() == content::DownloadItem::IN_PROGRESS) { |
| 91 if (!ContainsKey(items_, download)) { | 104 if (!ContainsKey(items_, download)) { |
| 92 items_.insert(download); | 105 items_.insert(download); |
| 93 download->AddObserver(this); | 106 download->AddObserver(this); |
| 94 } | 107 } |
| 95 } else { | 108 } else { |
| 96 if (ContainsKey(items_, download)) { | 109 if (ContainsKey(items_, download)) { |
| 97 items_.erase(download); | 110 items_.erase(download); |
| 98 download->RemoveObserver(this); | 111 download->RemoveObserver(this); |
| 99 } | 112 } |
| 100 } | 113 } |
| 101 } | 114 } |
| OLD | NEW |