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

Side by Side Diff: base/run_loop.cc

Issue 2548883002: Revert of Add thread checking to RunLoop, deprecate MessageLoopRunner. (Closed)
Patch Set: Created 4 years 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 | « base/run_loop.h ('k') | chrome/browser/chromeos/file_manager/zip_file_creator_browsertest.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 "base/run_loop.h" 5 #include "base/run_loop.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/tracked_objects.h" 8 #include "base/tracked_objects.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 10
11 namespace base { 11 namespace base {
12 12
13 RunLoop::RunLoop() 13 RunLoop::RunLoop()
14 : loop_(MessageLoop::current()), 14 : loop_(MessageLoop::current()),
15 previous_run_loop_(NULL), 15 previous_run_loop_(NULL),
16 run_depth_(0), 16 run_depth_(0),
17 run_called_(false), 17 run_called_(false),
18 quit_called_(false), 18 quit_called_(false),
19 running_(false), 19 running_(false),
20 quit_when_idle_received_(false), 20 quit_when_idle_received_(false),
21 weak_factory_(this) { 21 weak_factory_(this) {
22 } 22 }
23 23
24 RunLoop::~RunLoop() { 24 RunLoop::~RunLoop() {
25 } 25 }
26 26
27 void RunLoop::Run() { 27 void RunLoop::Run() {
28 DCHECK(thread_checker_.CalledOnValidThread());
29 if (!BeforeRun()) 28 if (!BeforeRun())
30 return; 29 return;
31 30
32 // Use task stopwatch to exclude the loop run time from the current task, if 31 // Use task stopwatch to exclude the loop run time from the current task, if
33 // any. 32 // any.
34 tracked_objects::TaskStopwatch stopwatch; 33 tracked_objects::TaskStopwatch stopwatch;
35 stopwatch.Start(); 34 stopwatch.Start();
36 loop_->RunHandler(); 35 loop_->RunHandler();
37 stopwatch.Stop(); 36 stopwatch.Stop();
38 37
39 AfterRun(); 38 AfterRun();
40 } 39 }
41 40
42 void RunLoop::RunUntilIdle() { 41 void RunLoop::RunUntilIdle() {
43 quit_when_idle_received_ = true; 42 quit_when_idle_received_ = true;
44 Run(); 43 Run();
45 } 44 }
46 45
47 void RunLoop::Quit() { 46 void RunLoop::Quit() {
48 DCHECK(thread_checker_.CalledOnValidThread());
49 quit_called_ = true; 47 quit_called_ = true;
50 if (running_ && loop_->run_loop_ == this) { 48 if (running_ && loop_->run_loop_ == this) {
51 // This is the inner-most RunLoop, so quit now. 49 // This is the inner-most RunLoop, so quit now.
52 loop_->QuitNow(); 50 loop_->QuitNow();
53 } 51 }
54 } 52 }
55 53
56 void RunLoop::QuitWhenIdle() { 54 void RunLoop::QuitWhenIdle() {
57 DCHECK(thread_checker_.CalledOnValidThread());
58 quit_when_idle_received_ = true; 55 quit_when_idle_received_ = true;
59 } 56 }
60 57
61 base::Closure RunLoop::QuitClosure() { 58 base::Closure RunLoop::QuitClosure() {
62 return base::Bind(&RunLoop::Quit, weak_factory_.GetWeakPtr()); 59 return base::Bind(&RunLoop::Quit, weak_factory_.GetWeakPtr());
63 } 60 }
64 61
65 base::Closure RunLoop::QuitWhenIdleClosure() { 62 base::Closure RunLoop::QuitWhenIdleClosure() {
66 return base::Bind(&RunLoop::QuitWhenIdle, weak_factory_.GetWeakPtr()); 63 return base::Bind(&RunLoop::QuitWhenIdle, weak_factory_.GetWeakPtr());
67 } 64 }
(...skipping 23 matching lines...) Expand all
91 88
92 // Pop RunLoop stack: 89 // Pop RunLoop stack:
93 loop_->run_loop_ = previous_run_loop_; 90 loop_->run_loop_ = previous_run_loop_;
94 91
95 // Execute deferred QuitNow, if any: 92 // Execute deferred QuitNow, if any:
96 if (previous_run_loop_ && previous_run_loop_->quit_called_) 93 if (previous_run_loop_ && previous_run_loop_->quit_called_)
97 loop_->QuitNow(); 94 loop_->QuitNow();
98 } 95 }
99 96
100 } // namespace base 97 } // namespace base
OLDNEW
« no previous file with comments | « base/run_loop.h ('k') | chrome/browser/chromeos/file_manager/zip_file_creator_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698