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

Side by Side Diff: tools/gn/scheduler.cc

Issue 2085023004: Remove calls to deprecated MessageLoop methods in tools. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "tools/gn/scheduler.h" 5 #include "tools/gn/scheduler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/single_thread_task_runner.h"
11 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
12 #include "build/build_config.h" 13 #include "build/build_config.h"
13 #include "tools/gn/standard_out.h" 14 #include "tools/gn/standard_out.h"
14 #include "tools/gn/switches.h" 15 #include "tools/gn/switches.h"
15 #include "tools/gn/target.h" 16 #include "tools/gn/target.h"
16 17
17 #if defined(OS_WIN) 18 #if defined(OS_WIN)
18 #include <windows.h> 19 #include <windows.h>
19 #else 20 #else
20 #include <unistd.h> 21 #include <unistd.h>
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 pool_->Shutdown(); 95 pool_->Shutdown();
95 return !local_is_failed; 96 return !local_is_failed;
96 } 97 }
97 98
98 void Scheduler::Log(const std::string& verb, const std::string& msg) { 99 void Scheduler::Log(const std::string& verb, const std::string& msg) {
99 if (base::MessageLoop::current() == &main_loop_) { 100 if (base::MessageLoop::current() == &main_loop_) {
100 LogOnMainThread(verb, msg); 101 LogOnMainThread(verb, msg);
101 } else { 102 } else {
102 // The run loop always joins on the sub threads, so the lifetime of this 103 // The run loop always joins on the sub threads, so the lifetime of this
103 // object outlives the invocations of this function, hence "unretained". 104 // object outlives the invocations of this function, hence "unretained".
104 main_loop_.PostTask(FROM_HERE, 105 main_loop_.task_runner()->PostTask(
105 base::Bind(&Scheduler::LogOnMainThread, 106 FROM_HERE, base::Bind(&Scheduler::LogOnMainThread,
106 base::Unretained(this), verb, msg)); 107 base::Unretained(this), verb, msg));
107 } 108 }
108 } 109 }
109 110
110 void Scheduler::FailWithError(const Err& err) { 111 void Scheduler::FailWithError(const Err& err) {
111 DCHECK(err.has_error()); 112 DCHECK(err.has_error());
112 { 113 {
113 base::AutoLock lock(lock_); 114 base::AutoLock lock(lock_);
114 115
115 if (is_failed_ || has_been_shutdown_) 116 if (is_failed_ || has_been_shutdown_)
116 return; // Ignore errors once we see one. 117 return; // Ignore errors once we see one.
117 is_failed_ = true; 118 is_failed_ = true;
118 } 119 }
119 120
120 if (base::MessageLoop::current() == &main_loop_) { 121 if (base::MessageLoop::current() == &main_loop_) {
121 FailWithErrorOnMainThread(err); 122 FailWithErrorOnMainThread(err);
122 } else { 123 } else {
123 // The run loop always joins on the sub threads, so the lifetime of this 124 // The run loop always joins on the sub threads, so the lifetime of this
124 // object outlives the invocations of this function, hence "unretained". 125 // object outlives the invocations of this function, hence "unretained".
125 main_loop_.PostTask(FROM_HERE, 126 main_loop_.task_runner()->PostTask(
126 base::Bind(&Scheduler::FailWithErrorOnMainThread, 127 FROM_HERE, base::Bind(&Scheduler::FailWithErrorOnMainThread,
127 base::Unretained(this), err)); 128 base::Unretained(this), err));
128 } 129 }
129 } 130 }
130 131
131 void Scheduler::ScheduleWork(const base::Closure& work) { 132 void Scheduler::ScheduleWork(const base::Closure& work) {
132 IncrementWorkCount(); 133 IncrementWorkCount();
133 pool_->PostWorkerTaskWithShutdownBehavior( 134 pool_->PostWorkerTaskWithShutdownBehavior(
134 FROM_HERE, base::Bind(&Scheduler::DoWork, 135 FROM_HERE, base::Bind(&Scheduler::DoWork,
135 base::Unretained(this), work), 136 base::Unretained(this), work),
136 base::SequencedWorkerPool::BLOCK_SHUTDOWN); 137 base::SequencedWorkerPool::BLOCK_SHUTDOWN);
137 } 138 }
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 204
204 void Scheduler::IncrementWorkCount() { 205 void Scheduler::IncrementWorkCount() {
205 base::AtomicRefCountInc(&work_count_); 206 base::AtomicRefCountInc(&work_count_);
206 } 207 }
207 208
208 void Scheduler::DecrementWorkCount() { 209 void Scheduler::DecrementWorkCount() {
209 if (!base::AtomicRefCountDec(&work_count_)) { 210 if (!base::AtomicRefCountDec(&work_count_)) {
210 if (base::MessageLoop::current() == &main_loop_) { 211 if (base::MessageLoop::current() == &main_loop_) {
211 OnComplete(); 212 OnComplete();
212 } else { 213 } else {
213 main_loop_.PostTask(FROM_HERE, 214 main_loop_.task_runner()->PostTask(
214 base::Bind(&Scheduler::OnComplete, 215 FROM_HERE,
215 base::Unretained(this))); 216 base::Bind(&Scheduler::OnComplete, base::Unretained(this)));
216 } 217 }
217 } 218 }
218 } 219 }
219 220
220 void Scheduler::LogOnMainThread(const std::string& verb, 221 void Scheduler::LogOnMainThread(const std::string& verb,
221 const std::string& msg) { 222 const std::string& msg) {
222 OutputString(verb, DECORATION_YELLOW); 223 OutputString(verb, DECORATION_YELLOW);
223 OutputString(" " + msg + "\n"); 224 OutputString(" " + msg + "\n");
224 } 225 }
225 226
226 void Scheduler::FailWithErrorOnMainThread(const Err& err) { 227 void Scheduler::FailWithErrorOnMainThread(const Err& err) {
227 err.PrintToStdout(); 228 err.PrintToStdout();
228 runner_.Quit(); 229 runner_.Quit();
229 } 230 }
230 231
231 void Scheduler::DoWork(const base::Closure& closure) { 232 void Scheduler::DoWork(const base::Closure& closure) {
232 closure.Run(); 233 closure.Run();
233 DecrementWorkCount(); 234 DecrementWorkCount();
234 } 235 }
235 236
236 void Scheduler::OnComplete() { 237 void Scheduler::OnComplete() {
237 // Should be called on the main thread. 238 // Should be called on the main thread.
238 DCHECK(base::MessageLoop::current() == main_loop()); 239 DCHECK(base::MessageLoop::current() == main_loop());
239 runner_.Quit(); 240 runner_.Quit();
240 } 241 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698