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

Side by Side Diff: content/public/test/download_test_observer.cc

Issue 10913015: Reland DownloadManager::GetAllDownloads actually does now (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 3 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 "content/public/test/download_test_observer.h" 5 #include "content/public/test/download_test_observer.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 DownloadInFinalState(download); 131 DownloadInFinalState(download);
132 } 132 }
133 133
134 void DownloadTestObserver::ModelChanged(DownloadManager* manager) { 134 void DownloadTestObserver::ModelChanged(DownloadManager* manager) {
135 DCHECK_EQ(manager, download_manager_); 135 DCHECK_EQ(manager, download_manager_);
136 136
137 // Regenerate DownloadItem observers. If there are any download items 137 // Regenerate DownloadItem observers. If there are any download items
138 // in our final state, note them in |finished_downloads_| 138 // in our final state, note them in |finished_downloads_|
139 // (done by |OnDownloadUpdated()|). 139 // (done by |OnDownloadUpdated()|).
140 std::vector<DownloadItem*> downloads; 140 std::vector<DownloadItem*> downloads;
141 download_manager_->GetAllDownloads(FilePath(), &downloads); 141 download_manager_->GetAllDownloads(&downloads);
142 // As a test class, we're generally interested in whatever's there,
143 // so we include temporary downloads.
144 download_manager_->GetTemporaryDownloads(FilePath(), &downloads);
145 142
146 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); 143 for (std::vector<DownloadItem*>::iterator it = downloads.begin();
147 it != downloads.end(); ++it) { 144 it != downloads.end(); ++it) {
148 OnDownloadUpdated(*it); // Safe to call multiple times; checks state. 145 OnDownloadUpdated(*it); // Safe to call multiple times; checks state.
149 146
150 DownloadSet::const_iterator finished_it(finished_downloads_.find(*it)); 147 DownloadSet::const_iterator finished_it(finished_downloads_.find(*it));
151 DownloadSet::iterator observed_it(downloads_observed_.find(*it)); 148 DownloadSet::iterator observed_it(downloads_observed_.find(*it));
152 149
153 // If it isn't finished and we're aren't observing it, start. 150 // If it isn't finished and we're aren't observing it, start.
154 if (finished_it == finished_downloads_.end() && 151 if (finished_it == finished_downloads_.end() &&
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 283
287 // If we're waiting for that flush point, check the number 284 // If we're waiting for that flush point, check the number
288 // of downloads in the IN_PROGRESS state and take appropriate 285 // of downloads in the IN_PROGRESS state and take appropriate
289 // action. If requested, also observes all downloads while iterating. 286 // action. If requested, also observes all downloads while iterating.
290 void DownloadTestFlushObserver::CheckDownloadsInProgress( 287 void DownloadTestFlushObserver::CheckDownloadsInProgress(
291 bool observe_downloads) { 288 bool observe_downloads) {
292 if (waiting_for_zero_inprogress_) { 289 if (waiting_for_zero_inprogress_) {
293 int count = 0; 290 int count = 0;
294 291
295 std::vector<DownloadItem*> downloads; 292 std::vector<DownloadItem*> downloads;
296 download_manager_->SearchDownloads(string16(), &downloads); 293 download_manager_->GetAllDownloads(&downloads);
297 for (std::vector<DownloadItem*>::iterator it = downloads.begin(); 294 for (std::vector<DownloadItem*>::iterator it = downloads.begin();
298 it != downloads.end(); ++it) { 295 it != downloads.end(); ++it) {
296 if ((*it)->IsTemporary())
297 continue;
Randy Smith (Not in Mondays) 2012/09/05 17:45:43 I think you could let this include temporary downl
benjhayden 2012/09/05 20:56:57 Done.
299 if ((*it)->GetState() == DownloadItem::IN_PROGRESS) 298 if ((*it)->GetState() == DownloadItem::IN_PROGRESS)
300 count++; 299 count++;
301 if (observe_downloads) { 300 if (observe_downloads) {
302 if (downloads_observed_.find(*it) == downloads_observed_.end()) { 301 if (downloads_observed_.find(*it) == downloads_observed_.end()) {
303 (*it)->AddObserver(this); 302 (*it)->AddObserver(this);
304 downloads_observed_.insert(*it); 303 downloads_observed_.insert(*it);
305 } 304 }
306 // Download items are forever, and we don't want to make 305 // Download items are forever, and we don't want to make
307 // assumptions about future state transitions, so once we 306 // assumptions about future state transitions, so once we
308 // start observing them, we don't stop until destruction. 307 // start observing them, we don't stop until destruction.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 MessageLoopForUI::current()->Quit(); 378 MessageLoopForUI::current()->Quit();
380 } 379 }
381 380
382 const DownloadUrlParameters::OnStartedCallback 381 const DownloadUrlParameters::OnStartedCallback
383 DownloadTestItemCreationObserver::callback() { 382 DownloadTestItemCreationObserver::callback() {
384 return base::Bind( 383 return base::Bind(
385 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); 384 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this);
386 } 385 }
387 386
388 } // namespace content 387 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698