Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1781)

Side by Side Diff: chrome/browser/download/download_status_updater.cc

Issue 9361046: Revert 121031 - Eliminate DownloadProgressUpdated. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
12 11
13 DownloadStatusUpdater::DownloadStatusUpdater() { 12 DownloadStatusUpdater::DownloadStatusUpdater() {
14 } 13 }
15 14
16 DownloadStatusUpdater::~DownloadStatusUpdater() { 15 DownloadStatusUpdater::~DownloadStatusUpdater() {
17 for (std::set<content::DownloadManager*>::iterator it = managers_.begin(); 16 for (std::set<content::DownloadManager*>::iterator it = managers_.begin();
18 it != managers_.end(); ++it) 17 it != managers_.end(); ++it)
19 (*it)->RemoveObserver(this); 18 (*it)->RemoveObserver(this);
20 19
21 for (std::set<content::DownloadItem*>::iterator it = items_.begin(); 20 for (std::set<content::DownloadItem*>::iterator it = items_.begin();
(...skipping 30 matching lines...) Expand all
52 51
53 // Methods inherited from content::DownloadManager::Observer. 52 // Methods inherited from content::DownloadManager::Observer.
54 void DownloadStatusUpdater::ModelChanged(content::DownloadManager* manager) { 53 void DownloadStatusUpdater::ModelChanged(content::DownloadManager* manager) {
55 std::vector<content::DownloadItem*> downloads; 54 std::vector<content::DownloadItem*> downloads;
56 manager->SearchDownloads(string16(), &downloads); 55 manager->SearchDownloads(string16(), &downloads);
57 56
58 for (std::vector<content::DownloadItem*>::iterator it = downloads.begin(); 57 for (std::vector<content::DownloadItem*>::iterator it = downloads.begin();
59 it != downloads.end(); ++it) { 58 it != downloads.end(); ++it) {
60 UpdateItem(*it); 59 UpdateItem(*it);
61 } 60 }
62
63 UpdateAppIconDownloadProgress();
64 } 61 }
65 62
66 void DownloadStatusUpdater::ManagerGoingDown( 63 void DownloadStatusUpdater::ManagerGoingDown(
67 content::DownloadManager* manager) { 64 content::DownloadManager* manager) {
68 DCHECK(ContainsKey(managers_, manager)); 65 DCHECK(ContainsKey(managers_, manager));
69 managers_.erase(manager); 66 managers_.erase(manager);
70 manager->RemoveObserver(this); 67 manager->RemoveObserver(this);
71 // Item removal will be handled in response to DownloadItem REMOVING 68 // Item removal will be handled in response to DownloadItem REMOVING
72 // notification (in the !IN_PROGRESS conditional branch in UpdateItem). 69 // notification (in the !IN_PROGRESS conditional branch in UpdateItem).
73 } 70 }
74 71
75 void DownloadStatusUpdater::SelectFileDialogDisplayed( 72 void DownloadStatusUpdater::SelectFileDialogDisplayed(
76 content::DownloadManager* manager, int32 id) { 73 content::DownloadManager* manager, int32 id) {
77 } 74 }
78 75
79 // Methods inherited from content::DownloadItem::Observer. 76 // Methods inherited from content::DownloadItem::Observer.
80 void DownloadStatusUpdater::OnDownloadUpdated( 77 void DownloadStatusUpdater::OnDownloadUpdated(
81 content::DownloadItem* download) { 78 content::DownloadItem* download) {
82 UpdateItem(download); 79 UpdateItem(download);
83 UpdateAppIconDownloadProgress();
84 } 80 }
85 81
86 void DownloadStatusUpdater::OnDownloadOpened(content::DownloadItem* download) { 82 void DownloadStatusUpdater::OnDownloadOpened(content::DownloadItem* download) {
87 } 83 }
88 84
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
98 // React to a transition that a download associated with one of our 85 // React to a transition that a download associated with one of our
99 // download managers has made. Our goal is to have only IN_PROGRESS 86 // download managers has made. Our goal is to have only IN_PROGRESS
100 // items on our set list, as they're the only ones that have relevance 87 // items on our set list, as they're the only ones that have relevance
101 // to GetProgress() return values. 88 // to GetProgress() return values.
102 void DownloadStatusUpdater::UpdateItem(content::DownloadItem* download) { 89 void DownloadStatusUpdater::UpdateItem(content::DownloadItem* download) {
103 if (download->GetState() == content::DownloadItem::IN_PROGRESS) { 90 if (download->GetState() == content::DownloadItem::IN_PROGRESS) {
104 if (!ContainsKey(items_, download)) { 91 if (!ContainsKey(items_, download)) {
105 items_.insert(download); 92 items_.insert(download);
106 download->AddObserver(this); 93 download->AddObserver(this);
107 } 94 }
108 } else { 95 } else {
109 if (ContainsKey(items_, download)) { 96 if (ContainsKey(items_, download)) {
110 items_.erase(download); 97 items_.erase(download);
111 download->RemoveObserver(this); 98 download->RemoveObserver(this);
112 } 99 }
113 } 100 }
114 } 101 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_status_updater.h ('k') | content/browser/download/download_manager_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698