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

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

Issue 10704026: Reland DownloadItem::Observer::OnDownloadDestroyed() replaces DownloadItem::REMOVING (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: lint Created 8 years, 4 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"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 } 61 }
62 62
63 UpdateAppIconDownloadProgress(); 63 UpdateAppIconDownloadProgress();
64 } 64 }
65 65
66 void DownloadStatusUpdater::ManagerGoingDown( 66 void DownloadStatusUpdater::ManagerGoingDown(
67 content::DownloadManager* manager) { 67 content::DownloadManager* manager) {
68 DCHECK(ContainsKey(managers_, manager)); 68 DCHECK(ContainsKey(managers_, manager));
69 managers_.erase(manager); 69 managers_.erase(manager);
70 manager->RemoveObserver(this); 70 manager->RemoveObserver(this);
71 // Item removal will be handled in response to DownloadItem REMOVING
72 // notification (in the !IN_PROGRESS conditional branch in UpdateItem).
73 } 71 }
74 72
75 // Methods inherited from content::DownloadItem::Observer. 73 // Methods inherited from content::DownloadItem::Observer.
76 void DownloadStatusUpdater::OnDownloadUpdated( 74 void DownloadStatusUpdater::OnDownloadUpdated(
77 content::DownloadItem* download) { 75 content::DownloadItem* download) {
78 UpdateItem(download); 76 UpdateItem(download);
79 UpdateAppIconDownloadProgress(); 77 UpdateAppIconDownloadProgress();
80 } 78 }
81 79
80 void DownloadStatusUpdater::OnDownloadDestroyed(
81 content::DownloadItem* download) {
82 if (ContainsKey(items_, download)) {
83 items_.erase(download);
84 download->RemoveObserver(this);
85 }
86 UpdateAppIconDownloadProgress();
Randy Smith (Not in Mondays) 2012/08/09 17:03:44 I don't actually think you need this--OnDownloadDe
benjhayden 2012/08/09 18:35:06 I don't know this code, but it appears that UAIDP
Randy Smith (Not in Mondays) 2012/08/09 20:27:32 The major issue here is my distinction between the
87 }
88
82 void DownloadStatusUpdater::OnDownloadOpened(content::DownloadItem* download) { 89 void DownloadStatusUpdater::OnDownloadOpened(content::DownloadItem* download) {
83 } 90 }
84 91
85 void DownloadStatusUpdater::UpdateAppIconDownloadProgress() { 92 void DownloadStatusUpdater::UpdateAppIconDownloadProgress() {
86 float progress = 0; 93 float progress = 0;
87 int download_count = 0; 94 int download_count = 0;
88 bool progress_known = GetProgress(&progress, &download_count); 95 bool progress_known = GetProgress(&progress, &download_count);
89 download_util::UpdateAppIconDownloadProgress(download_count, 96 download_util::UpdateAppIconDownloadProgress(download_count,
90 progress_known, 97 progress_known,
91 progress); 98 progress);
92 } 99 }
93 100
94 // React to a transition that a download associated with one of our 101 // React to a transition that a download associated with one of our
95 // download managers has made. Our goal is to have only IN_PROGRESS 102 // download managers has made. Our goal is to have only IN_PROGRESS
96 // items on our set list, as they're the only ones that have relevance 103 // items on our set list, as they're the only ones that have relevance
97 // to GetProgress() return values. 104 // to GetProgress() return values.
98 void DownloadStatusUpdater::UpdateItem(content::DownloadItem* download) { 105 void DownloadStatusUpdater::UpdateItem(content::DownloadItem* download) {
99 if (download->GetState() == content::DownloadItem::IN_PROGRESS) { 106 if (download->GetState() == content::DownloadItem::IN_PROGRESS) {
100 if (!ContainsKey(items_, download)) { 107 if (!ContainsKey(items_, download)) {
101 items_.insert(download); 108 items_.insert(download);
102 download->AddObserver(this); 109 download->AddObserver(this);
103 } 110 }
104 } else { 111 } else {
105 if (ContainsKey(items_, download)) { 112 if (ContainsKey(items_, download)) {
106 items_.erase(download); 113 items_.erase(download);
107 download->RemoveObserver(this); 114 download->RemoveObserver(this);
108 } 115 }
109 } 116 }
110 } 117 }
OLDNEW
« no previous file with comments | « chrome/browser/download/download_status_updater.h ('k') | chrome/browser/download/download_test_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698