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

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

Issue 14335017: content: Use base::MessageLoop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 7 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 RunMessageLoop(); 71 RunMessageLoop();
72 waiting_ = false; 72 waiting_ = false;
73 return event_seen_; 73 return event_seen_;
74 } 74 }
75 75
76 void DownloadUpdatedObserver::OnDownloadUpdated(DownloadItem* item) { 76 void DownloadUpdatedObserver::OnDownloadUpdated(DownloadItem* item) {
77 DCHECK_EQ(item_, item); 77 DCHECK_EQ(item_, item);
78 if (filter_.Run(item_)) 78 if (filter_.Run(item_))
79 event_seen_ = true; 79 event_seen_ = true;
80 if (waiting_ && event_seen_) 80 if (waiting_ && event_seen_)
81 MessageLoopForUI::current()->Quit(); 81 base::MessageLoopForUI::current()->Quit();
82 } 82 }
83 83
84 void DownloadUpdatedObserver::OnDownloadDestroyed(DownloadItem* item) { 84 void DownloadUpdatedObserver::OnDownloadDestroyed(DownloadItem* item) {
85 DCHECK_EQ(item_, item); 85 DCHECK_EQ(item_, item);
86 item_->RemoveObserver(this); 86 item_->RemoveObserver(this);
87 item_ = NULL; 87 item_ = NULL;
88 if (waiting_) 88 if (waiting_)
89 MessageLoopForUI::current()->Quit(); 89 base::MessageLoopForUI::current()->Quit();
90 } 90 }
91 91
92 DownloadTestObserver::DownloadTestObserver( 92 DownloadTestObserver::DownloadTestObserver(
93 DownloadManager* download_manager, 93 DownloadManager* download_manager,
94 size_t wait_count, 94 size_t wait_count,
95 DangerousDownloadAction dangerous_download_action) 95 DangerousDownloadAction dangerous_download_action)
96 : download_manager_(download_manager), 96 : download_manager_(download_manager),
97 wait_count_(wait_count), 97 wait_count_(wait_count),
98 finished_downloads_at_construction_(0), 98 finished_downloads_at_construction_(0),
99 waiting_(false), 99 waiting_(false),
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 finished_downloads_.insert(download); 224 finished_downloads_.insert(download);
225 225
226 // Record the state. 226 // Record the state.
227 states_observed_[download->GetState()]++; // Initializes to 0 the first time. 227 states_observed_[download->GetState()]++; // Initializes to 0 the first time.
228 228
229 SignalIfFinished(); 229 SignalIfFinished();
230 } 230 }
231 231
232 void DownloadTestObserver::SignalIfFinished() { 232 void DownloadTestObserver::SignalIfFinished() {
233 if (waiting_ && IsFinished()) 233 if (waiting_ && IsFinished())
234 MessageLoopForUI::current()->Quit(); 234 base::MessageLoopForUI::current()->Quit();
235 } 235 }
236 236
237 DownloadTestObserverTerminal::DownloadTestObserverTerminal( 237 DownloadTestObserverTerminal::DownloadTestObserverTerminal(
238 DownloadManager* download_manager, 238 DownloadManager* download_manager,
239 size_t wait_count, 239 size_t wait_count,
240 DangerousDownloadAction dangerous_download_action) 240 DangerousDownloadAction dangerous_download_action)
241 : DownloadTestObserver(download_manager, 241 : DownloadTestObserver(download_manager,
242 wait_count, 242 wait_count,
243 dangerous_download_action) { 243 dangerous_download_action) {
244 // You can't rely on overriden virtual functions in a base class constructor; 244 // You can't rely on overriden virtual functions in a base class constructor;
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 base::Bind(&DownloadTestFlushObserver::PingIOThread, this, cycle)); 372 base::Bind(&DownloadTestFlushObserver::PingIOThread, this, cycle));
373 } 373 }
374 374
375 void DownloadTestFlushObserver::PingIOThread(int cycle) { 375 void DownloadTestFlushObserver::PingIOThread(int cycle) {
376 if (--cycle) { 376 if (--cycle) {
377 BrowserThread::PostTask( 377 BrowserThread::PostTask(
378 BrowserThread::UI, FROM_HERE, 378 BrowserThread::UI, FROM_HERE,
379 base::Bind(&DownloadTestFlushObserver::PingFileThread, this, cycle)); 379 base::Bind(&DownloadTestFlushObserver::PingFileThread, this, cycle));
380 } else { 380 } else {
381 BrowserThread::PostTask( 381 BrowserThread::PostTask(
382 BrowserThread::UI, FROM_HERE, MessageLoop::QuitClosure()); 382 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure());
383 } 383 }
384 } 384 }
385 385
386 DownloadTestItemCreationObserver::DownloadTestItemCreationObserver() 386 DownloadTestItemCreationObserver::DownloadTestItemCreationObserver()
387 : download_id_(DownloadId::Invalid().local()), 387 : download_id_(DownloadId::Invalid().local()),
388 error_(net::OK), 388 error_(net::OK),
389 called_back_count_(0), 389 called_back_count_(0),
390 waiting_(false) { 390 waiting_(false) {
391 } 391 }
392 392
(...skipping 15 matching lines...) Expand all
408 net::Error error) { 408 net::Error error) {
409 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 409 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
410 410
411 if (item) 411 if (item)
412 download_id_ = item->GetId(); 412 download_id_ = item->GetId();
413 error_ = error; 413 error_ = error;
414 ++called_back_count_; 414 ++called_back_count_;
415 DCHECK_EQ(1u, called_back_count_); 415 DCHECK_EQ(1u, called_back_count_);
416 416
417 if (waiting_) 417 if (waiting_)
418 MessageLoopForUI::current()->Quit(); 418 base::MessageLoopForUI::current()->Quit();
419 } 419 }
420 420
421 const DownloadUrlParameters::OnStartedCallback 421 const DownloadUrlParameters::OnStartedCallback
422 DownloadTestItemCreationObserver::callback() { 422 DownloadTestItemCreationObserver::callback() {
423 return base::Bind( 423 return base::Bind(
424 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); 424 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this);
425 } 425 }
426 426
427 } // namespace content 427 } // namespace content
OLDNEW
« no previous file with comments | « content/ppapi_plugin/ppapi_thread.cc ('k') | content/public/test/fake_speech_recognition_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698