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

Side by Side Diff: base/message_loop/message_loop.cc

Issue 2407313002: Disallow nesting on some BrowserThreads. (Closed)
Patch Set: self-review Created 4 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 | « base/message_loop/message_loop.h ('k') | content/browser/browser_thread_impl.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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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 "base/message_loop/message_loop.h" 5 #include "base/message_loop/message_loop.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 } 209 }
210 210
211 void MessageLoop::RemoveDestructionObserver( 211 void MessageLoop::RemoveDestructionObserver(
212 DestructionObserver* destruction_observer) { 212 DestructionObserver* destruction_observer) {
213 DCHECK_EQ(this, current()); 213 DCHECK_EQ(this, current());
214 destruction_observers_.RemoveObserver(destruction_observer); 214 destruction_observers_.RemoveObserver(destruction_observer);
215 } 215 }
216 216
217 void MessageLoop::AddNestingObserver(NestingObserver* observer) { 217 void MessageLoop::AddNestingObserver(NestingObserver* observer) {
218 DCHECK_EQ(this, current()); 218 DCHECK_EQ(this, current());
219 CHECK(allow_nesting_);
219 nesting_observers_.AddObserver(observer); 220 nesting_observers_.AddObserver(observer);
220 } 221 }
221 222
222 void MessageLoop::RemoveNestingObserver(NestingObserver* observer) { 223 void MessageLoop::RemoveNestingObserver(NestingObserver* observer) {
223 DCHECK_EQ(this, current()); 224 DCHECK_EQ(this, current());
225 CHECK(allow_nesting_);
224 nesting_observers_.RemoveObserver(observer); 226 nesting_observers_.RemoveObserver(observer);
225 } 227 }
226 228
227 void MessageLoop::QuitWhenIdle() { 229 void MessageLoop::QuitWhenIdle() {
228 DCHECK_EQ(this, current()); 230 DCHECK_EQ(this, current());
229 if (run_loop_) { 231 if (run_loop_) {
230 run_loop_->QuitWhenIdle(); 232 run_loop_->QuitWhenIdle();
231 } else { 233 } else {
232 NOTREACHED() << "Must be inside Run to call QuitWhenIdle"; 234 NOTREACHED() << "Must be inside Run to call QuitWhenIdle";
233 } 235 }
(...skipping 16 matching lines...) Expand all
250 MessageLoop::current()->QuitWhenIdle(); 252 MessageLoop::current()->QuitWhenIdle();
251 } 253 }
252 254
253 // static 255 // static
254 Closure MessageLoop::QuitWhenIdleClosure() { 256 Closure MessageLoop::QuitWhenIdleClosure() {
255 return Bind(&QuitCurrentWhenIdle); 257 return Bind(&QuitCurrentWhenIdle);
256 } 258 }
257 259
258 void MessageLoop::SetNestableTasksAllowed(bool allowed) { 260 void MessageLoop::SetNestableTasksAllowed(bool allowed) {
259 if (allowed) { 261 if (allowed) {
262 CHECK(allow_nesting_);
263
260 // Kick the native pump just in case we enter a OS-driven nested message 264 // Kick the native pump just in case we enter a OS-driven nested message
261 // loop. 265 // loop.
262 pump_->ScheduleWork(); 266 pump_->ScheduleWork();
263 } 267 }
264 nestable_tasks_allowed_ = allowed; 268 nestable_tasks_allowed_ = allowed;
265 } 269 }
266 270
267 bool MessageLoop::NestableTasksAllowed() const { 271 bool MessageLoop::NestableTasksAllowed() const {
268 return nestable_tasks_allowed_; 272 return nestable_tasks_allowed_;
269 } 273 }
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 void MessageLoop::SetThreadTaskRunnerHandle() { 364 void MessageLoop::SetThreadTaskRunnerHandle() {
361 DCHECK_EQ(this, current()); 365 DCHECK_EQ(this, current());
362 // Clear the previous thread task runner first, because only one can exist at 366 // Clear the previous thread task runner first, because only one can exist at
363 // a time. 367 // a time.
364 thread_task_runner_handle_.reset(); 368 thread_task_runner_handle_.reset();
365 thread_task_runner_handle_.reset(new ThreadTaskRunnerHandle(task_runner_)); 369 thread_task_runner_handle_.reset(new ThreadTaskRunnerHandle(task_runner_));
366 } 370 }
367 371
368 void MessageLoop::RunHandler() { 372 void MessageLoop::RunHandler() {
369 DCHECK_EQ(this, current()); 373 DCHECK_EQ(this, current());
374 DCHECK(run_loop_);
375 CHECK(allow_nesting_ || run_loop_->run_depth_ == 1);
370 pump_->Run(this); 376 pump_->Run(this);
371 } 377 }
372 378
373 bool MessageLoop::ProcessNextDelayedNonNestableTask() { 379 bool MessageLoop::ProcessNextDelayedNonNestableTask() {
374 if (run_loop_->run_depth_ != 1) 380 if (run_loop_->run_depth_ != 1)
375 return false; 381 return false;
376 382
377 if (deferred_non_nestable_work_queue_.empty()) 383 if (deferred_non_nestable_work_queue_.empty())
378 return false; 384 return false;
379 385
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
646 persistent, 652 persistent,
647 mode, 653 mode,
648 controller, 654 controller,
649 delegate); 655 delegate);
650 } 656 }
651 #endif 657 #endif
652 658
653 #endif // !defined(OS_NACL_SFI) 659 #endif // !defined(OS_NACL_SFI)
654 660
655 } // namespace base 661 } // namespace base
OLDNEW
« no previous file with comments | « base/message_loop/message_loop.h ('k') | content/browser/browser_thread_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698