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

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

Issue 1398153002: Don't use base::MessageLoop::{Quit,QuitClosure} in content/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « content/gpu/gpu_child_thread.cc ('k') | content/public/test/javascript_test_observer.cc » ('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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 RunMessageLoop(); 42 RunMessageLoop();
43 waiting_ = false; 43 waiting_ = false;
44 return event_seen_; 44 return event_seen_;
45 } 45 }
46 46
47 void DownloadUpdatedObserver::OnDownloadUpdated(DownloadItem* item) { 47 void DownloadUpdatedObserver::OnDownloadUpdated(DownloadItem* item) {
48 DCHECK_EQ(item_, item); 48 DCHECK_EQ(item_, item);
49 if (filter_.Run(item_)) 49 if (filter_.Run(item_))
50 event_seen_ = true; 50 event_seen_ = true;
51 if (waiting_ && event_seen_) 51 if (waiting_ && event_seen_)
52 base::MessageLoopForUI::current()->Quit(); 52 base::MessageLoopForUI::current()->QuitWhenIdle();
53 } 53 }
54 54
55 void DownloadUpdatedObserver::OnDownloadDestroyed(DownloadItem* item) { 55 void DownloadUpdatedObserver::OnDownloadDestroyed(DownloadItem* item) {
56 DCHECK_EQ(item_, item); 56 DCHECK_EQ(item_, item);
57 item_->RemoveObserver(this); 57 item_->RemoveObserver(this);
58 item_ = NULL; 58 item_ = NULL;
59 if (waiting_) 59 if (waiting_)
60 base::MessageLoopForUI::current()->Quit(); 60 base::MessageLoopForUI::current()->QuitWhenIdle();
61 } 61 }
62 62
63 DownloadTestObserver::DownloadTestObserver( 63 DownloadTestObserver::DownloadTestObserver(
64 DownloadManager* download_manager, 64 DownloadManager* download_manager,
65 size_t wait_count, 65 size_t wait_count,
66 DangerousDownloadAction dangerous_download_action) 66 DangerousDownloadAction dangerous_download_action)
67 : download_manager_(download_manager), 67 : download_manager_(download_manager),
68 wait_count_(wait_count), 68 wait_count_(wait_count),
69 finished_downloads_at_construction_(0), 69 finished_downloads_at_construction_(0),
70 waiting_(false), 70 waiting_(false),
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 finished_downloads_.insert(download); 209 finished_downloads_.insert(download);
210 210
211 // Record the state. 211 // Record the state.
212 states_observed_[download->GetState()]++; // Initializes to 0 the first time. 212 states_observed_[download->GetState()]++; // Initializes to 0 the first time.
213 213
214 SignalIfFinished(); 214 SignalIfFinished();
215 } 215 }
216 216
217 void DownloadTestObserver::SignalIfFinished() { 217 void DownloadTestObserver::SignalIfFinished() {
218 if (waiting_ && IsFinished()) 218 if (waiting_ && IsFinished())
219 base::MessageLoopForUI::current()->Quit(); 219 base::MessageLoopForUI::current()->QuitWhenIdle();
220 } 220 }
221 221
222 void DownloadTestObserver::AcceptDangerousDownload(uint32 download_id) { 222 void DownloadTestObserver::AcceptDangerousDownload(uint32 download_id) {
223 // Download manager was shutdown before the UI thread could accept the 223 // Download manager was shutdown before the UI thread could accept the
224 // download. 224 // download.
225 if (!download_manager_) 225 if (!download_manager_)
226 return; 226 return;
227 DownloadItem* download = download_manager_->GetDownload(download_id); 227 DownloadItem* download = download_manager_->GetDownload(download_id);
228 if (download && !download->IsDone()) 228 if (download && !download->IsDone())
229 download->ValidateDangerousDownload(); 229 download->ValidateDangerousDownload();
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 BrowserThread::IO, FROM_HERE, 399 BrowserThread::IO, FROM_HERE,
400 base::Bind(&DownloadTestFlushObserver::PingIOThread, this, cycle)); 400 base::Bind(&DownloadTestFlushObserver::PingIOThread, this, cycle));
401 } 401 }
402 402
403 void DownloadTestFlushObserver::PingIOThread(int cycle) { 403 void DownloadTestFlushObserver::PingIOThread(int cycle) {
404 if (--cycle) { 404 if (--cycle) {
405 BrowserThread::PostTask( 405 BrowserThread::PostTask(
406 BrowserThread::UI, FROM_HERE, 406 BrowserThread::UI, FROM_HERE,
407 base::Bind(&DownloadTestFlushObserver::PingFileThread, this, cycle)); 407 base::Bind(&DownloadTestFlushObserver::PingFileThread, this, cycle));
408 } else { 408 } else {
409 BrowserThread::PostTask( 409 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
410 BrowserThread::UI, FROM_HERE, base::MessageLoop::QuitClosure()); 410 base::MessageLoop::QuitWhenIdleClosure());
411 } 411 }
412 } 412 }
413 413
414 DownloadTestItemCreationObserver::DownloadTestItemCreationObserver() 414 DownloadTestItemCreationObserver::DownloadTestItemCreationObserver()
415 : download_id_(DownloadItem::kInvalidId), 415 : download_id_(DownloadItem::kInvalidId),
416 interrupt_reason_(DOWNLOAD_INTERRUPT_REASON_NONE), 416 interrupt_reason_(DOWNLOAD_INTERRUPT_REASON_NONE),
417 called_back_count_(0), 417 called_back_count_(0),
418 waiting_(false) { 418 waiting_(false) {
419 } 419 }
420 420
(...skipping 15 matching lines...) Expand all
436 DownloadInterruptReason interrupt_reason) { 436 DownloadInterruptReason interrupt_reason) {
437 DCHECK_CURRENTLY_ON(BrowserThread::UI); 437 DCHECK_CURRENTLY_ON(BrowserThread::UI);
438 438
439 if (item) 439 if (item)
440 download_id_ = item->GetId(); 440 download_id_ = item->GetId();
441 interrupt_reason_ = interrupt_reason; 441 interrupt_reason_ = interrupt_reason;
442 ++called_back_count_; 442 ++called_back_count_;
443 DCHECK_EQ(1u, called_back_count_); 443 DCHECK_EQ(1u, called_back_count_);
444 444
445 if (waiting_) 445 if (waiting_)
446 base::MessageLoopForUI::current()->Quit(); 446 base::MessageLoopForUI::current()->QuitWhenIdle();
447 } 447 }
448 448
449 const DownloadUrlParameters::OnStartedCallback 449 const DownloadUrlParameters::OnStartedCallback
450 DownloadTestItemCreationObserver::callback() { 450 DownloadTestItemCreationObserver::callback() {
451 return base::Bind( 451 return base::Bind(
452 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this); 452 &DownloadTestItemCreationObserver::DownloadItemCreationCallback, this);
453 } 453 }
454 454
455 } // namespace content 455 } // namespace content
OLDNEW
« no previous file with comments | « content/gpu/gpu_child_thread.cc ('k') | content/public/test/javascript_test_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698