OLD | NEW |
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/browser/browser_thread_impl.h" | 5 #include "content/browser/browser_thread_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 bool BrowserThread::CurrentlyOn(ID identifier) { | 354 bool BrowserThread::CurrentlyOn(ID identifier) { |
355 // We shouldn't use MessageLoop::current() since it uses LazyInstance which | 355 // We shouldn't use MessageLoop::current() since it uses LazyInstance which |
356 // may be deleted by ~AtExitManager when a WorkerPool thread calls this | 356 // may be deleted by ~AtExitManager when a WorkerPool thread calls this |
357 // function. | 357 // function. |
358 // http://crbug.com/63678 | 358 // http://crbug.com/63678 |
359 base::ThreadRestrictions::ScopedAllowSingleton allow_singleton; | 359 base::ThreadRestrictions::ScopedAllowSingleton allow_singleton; |
360 BrowserThreadGlobals& globals = g_globals.Get(); | 360 BrowserThreadGlobals& globals = g_globals.Get(); |
361 base::AutoLock lock(globals.lock); | 361 base::AutoLock lock(globals.lock); |
362 DCHECK(identifier >= 0 && identifier < ID_COUNT); | 362 DCHECK(identifier >= 0 && identifier < ID_COUNT); |
363 return globals.threads[identifier] && | 363 return globals.threads[identifier] && |
364 globals.threads[identifier]->message_loop() == | 364 globals.threads[identifier]->message_loop() == MessageLoop::current(); |
365 MessageLoop::current(); | |
366 } | 365 } |
367 | 366 |
368 // static | 367 // static |
369 bool BrowserThread::IsMessageLoopValid(ID identifier) { | 368 bool BrowserThread::IsMessageLoopValid(ID identifier) { |
370 if (g_globals == NULL) | 369 if (g_globals == NULL) |
371 return false; | 370 return false; |
372 | 371 |
373 BrowserThreadGlobals& globals = g_globals.Get(); | 372 BrowserThreadGlobals& globals = g_globals.Get(); |
374 base::AutoLock lock(globals.lock); | 373 base::AutoLock lock(globals.lock); |
375 DCHECK(identifier >= 0 && identifier < ID_COUNT); | 374 DCHECK(identifier >= 0 && identifier < ID_COUNT); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 return true; | 442 return true; |
444 } | 443 } |
445 } | 444 } |
446 | 445 |
447 return false; | 446 return false; |
448 } | 447 } |
449 | 448 |
450 // static | 449 // static |
451 scoped_refptr<base::MessageLoopProxy> | 450 scoped_refptr<base::MessageLoopProxy> |
452 BrowserThread::GetMessageLoopProxyForThread(ID identifier) { | 451 BrowserThread::GetMessageLoopProxyForThread(ID identifier) { |
453 scoped_refptr<base::MessageLoopProxy> proxy( | 452 return make_scoped_refptr(new BrowserThreadMessageLoopProxy(identifier)); |
454 new BrowserThreadMessageLoopProxy(identifier)); | |
455 return proxy; | |
456 } | 453 } |
457 | 454 |
458 // static | 455 // static |
459 MessageLoop* BrowserThread::UnsafeGetMessageLoopForThread(ID identifier) { | 456 MessageLoop* BrowserThread::UnsafeGetMessageLoopForThread(ID identifier) { |
460 if (g_globals == NULL) | 457 if (g_globals == NULL) |
461 return NULL; | 458 return NULL; |
462 | 459 |
463 BrowserThreadGlobals& globals = g_globals.Get(); | 460 BrowserThreadGlobals& globals = g_globals.Get(); |
464 base::AutoLock lock(globals.lock); | 461 base::AutoLock lock(globals.lock); |
465 base::Thread* thread = globals.threads[identifier]; | 462 base::Thread* thread = globals.threads[identifier]; |
(...skipping 10 matching lines...) Expand all Loading... |
476 AtomicWord* storage = reinterpret_cast<AtomicWord*>( | 473 AtomicWord* storage = reinterpret_cast<AtomicWord*>( |
477 &globals.thread_delegates[identifier]); | 474 &globals.thread_delegates[identifier]); |
478 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( | 475 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( |
479 storage, reinterpret_cast<AtomicWord>(delegate)); | 476 storage, reinterpret_cast<AtomicWord>(delegate)); |
480 | 477 |
481 // This catches registration when previously registered. | 478 // This catches registration when previously registered. |
482 DCHECK(!delegate || !old_pointer); | 479 DCHECK(!delegate || !old_pointer); |
483 } | 480 } |
484 | 481 |
485 } // namespace content | 482 } // namespace content |
OLD | NEW |