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" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 DCHECK(!ContainsKey(managers_, manager)); | 48 DCHECK(!ContainsKey(managers_, manager)); |
49 managers_.insert(manager); | 49 managers_.insert(manager); |
50 manager->AddObserver(this); | 50 manager->AddObserver(this); |
51 } | 51 } |
52 | 52 |
53 // Methods inherited from content::DownloadManager::Observer. | 53 // Methods inherited from content::DownloadManager::Observer. |
54 void DownloadStatusUpdater::ModelChanged(content::DownloadManager* manager) { | 54 void DownloadStatusUpdater::ModelChanged(content::DownloadManager* manager) { |
55 std::vector<content::DownloadItem*> downloads; | 55 std::vector<content::DownloadItem*> downloads; |
56 manager->SearchDownloads(string16(), &downloads); | 56 manager->SearchDownloads(string16(), &downloads); |
57 | 57 |
58 std::vector<content::DownloadItem*> added_downloads; | |
58 for (std::vector<content::DownloadItem*>::iterator it = downloads.begin(); | 59 for (std::vector<content::DownloadItem*>::iterator it = downloads.begin(); |
59 it != downloads.end(); ++it) { | 60 it != downloads.end(); ++it) { |
60 UpdateItem(*it); | 61 if (UpdateItem(*it)) |
62 added_downloads.push_back(*it); | |
61 } | 63 } |
62 | 64 |
63 UpdateAppIconDownloadProgress(); | 65 for (std::vector<content::DownloadItem*>::iterator it = |
66 added_downloads.begin(); | |
67 it != added_downloads.end(); | |
68 ++it) { | |
69 UpdateAppIconDownloadProgress(*it); | |
70 } | |
64 } | 71 } |
65 | 72 |
66 void DownloadStatusUpdater::ManagerGoingDown( | 73 void DownloadStatusUpdater::ManagerGoingDown( |
67 content::DownloadManager* manager) { | 74 content::DownloadManager* manager) { |
68 DCHECK(ContainsKey(managers_, manager)); | 75 DCHECK(ContainsKey(managers_, manager)); |
69 managers_.erase(manager); | 76 managers_.erase(manager); |
70 manager->RemoveObserver(this); | 77 manager->RemoveObserver(this); |
71 } | 78 } |
72 | 79 |
73 // Methods inherited from content::DownloadItem::Observer. | 80 // Methods inherited from content::DownloadItem::Observer. |
74 void DownloadStatusUpdater::OnDownloadUpdated( | 81 void DownloadStatusUpdater::OnDownloadUpdated( |
75 content::DownloadItem* download) { | 82 content::DownloadItem* download) { |
76 UpdateItem(download); | 83 UpdateItem(download); |
77 UpdateAppIconDownloadProgress(); | 84 UpdateAppIconDownloadProgress(download); |
78 } | 85 } |
79 | 86 |
80 void DownloadStatusUpdater::OnDownloadDestroyed( | 87 void DownloadStatusUpdater::OnDownloadDestroyed( |
81 content::DownloadItem* download) { | 88 content::DownloadItem* download) { |
82 if (ContainsKey(items_, download)) { | 89 if (ContainsKey(items_, download)) { |
83 items_.erase(download); | 90 items_.erase(download); |
84 download->RemoveObserver(this); | 91 download->RemoveObserver(this); |
85 } | 92 } |
86 UpdateAppIconDownloadProgress(); | 93 UpdateAppIconDownloadProgress(download); |
87 } | 94 } |
88 | 95 |
89 void DownloadStatusUpdater::OnDownloadOpened(content::DownloadItem* download) { | 96 void DownloadStatusUpdater::OnDownloadOpened(content::DownloadItem* download) { |
90 } | 97 } |
91 | 98 |
92 void DownloadStatusUpdater::UpdateAppIconDownloadProgress() { | 99 #if defined(USE_AURA) || defined(ANDROID) |
asanka
2012/08/11 05:29:20
defined(OS_ANDROID)?
Avi (use Gerrit)
2012/08/11 16:29:03
Done.
| |
93 float progress = 0; | 100 void DownloadStatusUpdater::UpdateAppIconDownloadProgress( |
94 int download_count = 0; | 101 content::DownloadItem* download) { |
95 bool progress_known = GetProgress(&progress, &download_count); | 102 // TODO(davemoore): Implement once UX for aura download is decided <104742> |
96 download_util::UpdateAppIconDownloadProgress(download_count, | 103 // TODO(avi): Implement for Android? |
97 progress_known, | |
98 progress); | |
99 } | 104 } |
105 #endif | |
100 | 106 |
101 // React to a transition that a download associated with one of our | 107 // React to a transition that a download associated with one of our |
102 // download managers has made. Our goal is to have only IN_PROGRESS | 108 // download managers has made. Our goal is to have only IN_PROGRESS |
103 // items on our set list, as they're the only ones that have relevance | 109 // items on our set list, as they're the only ones that have relevance |
104 // to GetProgress() return values. | 110 // to GetProgress() return values. |
105 void DownloadStatusUpdater::UpdateItem(content::DownloadItem* download) { | 111 bool DownloadStatusUpdater::UpdateItem(content::DownloadItem* download) { |
106 if (download->GetState() == content::DownloadItem::IN_PROGRESS) { | 112 if (download->GetState() == content::DownloadItem::IN_PROGRESS) { |
107 if (!ContainsKey(items_, download)) { | 113 if (!ContainsKey(items_, download)) { |
108 items_.insert(download); | 114 items_.insert(download); |
109 download->AddObserver(this); | 115 download->AddObserver(this); |
116 return true; | |
110 } | 117 } |
111 } else { | 118 } else { |
112 if (ContainsKey(items_, download)) { | 119 if (ContainsKey(items_, download)) { |
113 items_.erase(download); | 120 items_.erase(download); |
114 download->RemoveObserver(this); | 121 download->RemoveObserver(this); |
115 } | 122 } |
116 } | 123 } |
124 | |
125 return false; | |
117 } | 126 } |
OLD | NEW |