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

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

Issue 10704026: Reland DownloadItem::Observer::OnDownloadDestroyed() replaces DownloadItem::REMOVING (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge Created 8 years, 5 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 <vector> 5 #include <vector>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 } 76 }
77 } 77 }
78 78
79 bool DownloadTestObserver::IsFinished() const { 79 bool DownloadTestObserver::IsFinished() const {
80 if (finished_downloads_.size() - finished_downloads_at_construction_ >= 80 if (finished_downloads_.size() - finished_downloads_at_construction_ >=
81 wait_count_) 81 wait_count_)
82 return true; 82 return true;
83 return (finish_on_select_file_ && select_file_dialog_seen_); 83 return (finish_on_select_file_ && select_file_dialog_seen_);
84 } 84 }
85 85
86 void DownloadTestObserver::OnDownloadDestroyed(DownloadItem* download) {
87 // Stop observing. Do not do anything with it, as it is about to be gone.
88 DownloadSet::iterator it = downloads_observed_.find(download);
89 ASSERT_TRUE(it != downloads_observed_.end());
90 downloads_observed_.erase(it);
91 download->RemoveObserver(this);
92 }
93
86 void DownloadTestObserver::OnDownloadUpdated(DownloadItem* download) { 94 void DownloadTestObserver::OnDownloadUpdated(DownloadItem* download) {
87 // The REMOVING state indicates that the download is being destroyed.
88 // Stop observing. Do not do anything with it, as it is about to be gone.
89 if (download->GetState() == DownloadItem::REMOVING) {
90 DownloadSet::iterator it = downloads_observed_.find(download);
91 ASSERT_TRUE(it != downloads_observed_.end());
92 downloads_observed_.erase(it);
93 download->RemoveObserver(this);
94 return;
95 }
96
97 // Real UI code gets the user's response after returning from the observer. 95 // Real UI code gets the user's response after returning from the observer.
98 if (download->GetSafetyState() == DownloadItem::DANGEROUS && 96 if (download->GetSafetyState() == DownloadItem::DANGEROUS &&
99 !ContainsKey(dangerous_downloads_seen_, download->GetId())) { 97 !ContainsKey(dangerous_downloads_seen_, download->GetId())) {
100 dangerous_downloads_seen_.insert(download->GetId()); 98 dangerous_downloads_seen_.insert(download->GetId());
101 99
102 // Calling DangerousDownloadValidated() at this point will 100 // Calling DangerousDownloadValidated() at this point will
103 // cause the download to be completed twice. Do what the real UI 101 // cause the download to be completed twice. Do what the real UI
104 // code does: make the call as a delayed task. 102 // code does: make the call as a delayed task.
105 switch (dangerous_download_action_) { 103 switch (dangerous_download_action_) {
106 case ON_DANGEROUS_DOWNLOAD_ACCEPT: 104 case ON_DANGEROUS_DOWNLOAD_ACCEPT:
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 268 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
271 download_manager_->AddObserver(this); 269 download_manager_->AddObserver(this);
272 ui_test_utils::RunMessageLoop(); 270 ui_test_utils::RunMessageLoop();
273 } 271 }
274 272
275 void DownloadTestFlushObserver::ModelChanged(DownloadManager* manager) { 273 void DownloadTestFlushObserver::ModelChanged(DownloadManager* manager) {
276 // Model has changed, so there may be more DownloadItems to observe. 274 // Model has changed, so there may be more DownloadItems to observe.
277 CheckDownloadsInProgress(true); 275 CheckDownloadsInProgress(true);
278 } 276 }
279 277
278 void DownloadTestFlushObserver::OnDownloadDestroyed(DownloadItem* download) {
279 // Stop observing. Do not do anything with it, as it is about to be gone.
280 DownloadSet::iterator it = downloads_observed_.find(download);
281 ASSERT_TRUE(it != downloads_observed_.end());
282 downloads_observed_.erase(it);
283 download->RemoveObserver(this);
284 }
285
280 void DownloadTestFlushObserver::OnDownloadUpdated(DownloadItem* download) { 286 void DownloadTestFlushObserver::OnDownloadUpdated(DownloadItem* download) {
281 // The REMOVING state indicates that the download is being destroyed.
282 // Stop observing. Do not do anything with it, as it is about to be gone.
283 if (download->GetState() == DownloadItem::REMOVING) {
284 DownloadSet::iterator it = downloads_observed_.find(download);
285 ASSERT_TRUE(it != downloads_observed_.end());
286 downloads_observed_.erase(it);
287 download->RemoveObserver(this);
288 return;
289 }
290
291 // No change in DownloadItem set on manager. 287 // No change in DownloadItem set on manager.
292 CheckDownloadsInProgress(false); 288 CheckDownloadsInProgress(false);
293 } 289 }
294 290
295 DownloadTestFlushObserver::~DownloadTestFlushObserver() { 291 DownloadTestFlushObserver::~DownloadTestFlushObserver() {
296 download_manager_->RemoveObserver(this); 292 download_manager_->RemoveObserver(this);
297 for (DownloadSet::iterator it = downloads_observed_.begin(); 293 for (DownloadSet::iterator it = downloads_observed_.begin();
298 it != downloads_observed_.end(); ++it) { 294 it != downloads_observed_.end(); ++it) {
299 (*it)->RemoveObserver(this); 295 (*it)->RemoveObserver(this);
300 } 296 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 if (waiting_) 390 if (waiting_)
395 MessageLoopForUI::current()->Quit(); 391 MessageLoopForUI::current()->Quit();
396 } 392 }
397 393
398 const content::DownloadUrlParameters::OnStartedCallback 394 const content::DownloadUrlParameters::OnStartedCallback
399 DownloadTestItemCreationObserver::callback() { 395 DownloadTestItemCreationObserver::callback() {
400 return base::Bind( 396 return base::Bind(
401 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); 397 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this);
402 } 398 }
403 399
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698