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

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
« no previous file with comments | « content/public/browser/download_manager.h ('k') | content/public/test/mock_download_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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) {
299 if ((*it)->GetState() == DownloadItem::IN_PROGRESS) 296 if ((*it)->GetState() == DownloadItem::IN_PROGRESS)
300 count++; 297 count++;
301 if (observe_downloads) { 298 if (observe_downloads) {
302 if (downloads_observed_.find(*it) == downloads_observed_.end()) { 299 if (downloads_observed_.find(*it) == downloads_observed_.end()) {
303 (*it)->AddObserver(this); 300 (*it)->AddObserver(this);
304 downloads_observed_.insert(*it); 301 downloads_observed_.insert(*it);
305 } 302 }
306 // Download items are forever, and we don't want to make 303 // Download items are forever, and we don't want to make
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 MessageLoopForUI::current()->Quit(); 376 MessageLoopForUI::current()->Quit();
380 } 377 }
381 378
382 const DownloadUrlParameters::OnStartedCallback 379 const DownloadUrlParameters::OnStartedCallback
383 DownloadTestItemCreationObserver::callback() { 380 DownloadTestItemCreationObserver::callback() {
384 return base::Bind( 381 return base::Bind(
385 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); 382 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this);
386 } 383 }
387 384
388 } // namespace content 385 } // namespace content
OLDNEW
« no previous file with comments | « content/public/browser/download_manager.h ('k') | content/public/test/mock_download_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698