| 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.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 return BrowserThreadImpl::PostTaskHelper( | 486 return BrowserThreadImpl::PostTaskHelper( |
| 487 identifier, from_here, task, delay, false); | 487 identifier, from_here, task, delay, false); |
| 488 } | 488 } |
| 489 | 489 |
| 490 // static | 490 // static |
| 491 bool BrowserThread::PostTaskAndReply( | 491 bool BrowserThread::PostTaskAndReply( |
| 492 ID identifier, | 492 ID identifier, |
| 493 const tracked_objects::Location& from_here, | 493 const tracked_objects::Location& from_here, |
| 494 const base::Closure& task, | 494 const base::Closure& task, |
| 495 const base::Closure& reply) { | 495 const base::Closure& reply) { |
| 496 return GetMessageLoopProxyForThread(identifier)->PostTaskAndReply(from_here, | 496 return GetTaskRunnerForThread(identifier) |
| 497 task, | 497 ->PostTaskAndReply(from_here, task, reply); |
| 498 reply); | |
| 499 } | 498 } |
| 500 | 499 |
| 501 // static | 500 // static |
| 502 bool BrowserThread::GetCurrentThreadIdentifier(ID* identifier) { | 501 bool BrowserThread::GetCurrentThreadIdentifier(ID* identifier) { |
| 503 if (g_globals == NULL) | 502 if (g_globals == NULL) |
| 504 return false; | 503 return false; |
| 505 | 504 |
| 506 base::MessageLoop* cur_message_loop = base::MessageLoop::current(); | 505 base::MessageLoop* cur_message_loop = base::MessageLoop::current(); |
| 507 BrowserThreadGlobals& globals = g_globals.Get(); | 506 BrowserThreadGlobals& globals = g_globals.Get(); |
| 508 // Profiler to track potential contention on |globals.lock|. This only does | 507 // Profiler to track potential contention on |globals.lock|. This only does |
| 509 // real work on canary and local dev builds, so the cost of having this here | 508 // real work on canary and local dev builds, so the cost of having this here |
| 510 // should be minimal. | 509 // should be minimal. |
| 511 tracked_objects::ScopedTracker tracking_profile(FROM_HERE); | 510 tracked_objects::ScopedTracker tracking_profile(FROM_HERE); |
| 512 base::AutoLock lock(globals.lock); | 511 base::AutoLock lock(globals.lock); |
| 513 for (int i = 0; i < ID_COUNT; ++i) { | 512 for (int i = 0; i < ID_COUNT; ++i) { |
| 514 if (globals.threads[i] && | 513 if (globals.threads[i] && |
| 515 globals.threads[i]->message_loop() == cur_message_loop) { | 514 globals.threads[i]->message_loop() == cur_message_loop) { |
| 516 *identifier = globals.threads[i]->identifier_; | 515 *identifier = globals.threads[i]->identifier_; |
| 517 return true; | 516 return true; |
| 518 } | 517 } |
| 519 } | 518 } |
| 520 | 519 |
| 521 return false; | 520 return false; |
| 522 } | 521 } |
| 523 | 522 |
| 524 // static | 523 // static |
| 525 scoped_refptr<base::SingleThreadTaskRunner> | 524 scoped_refptr<base::SingleThreadTaskRunner> |
| 526 BrowserThread::GetMessageLoopProxyForThread(ID identifier) { | 525 BrowserThread::GetTaskRunnerForThread(ID identifier) { |
| 527 return g_task_runners.Get().proxies[identifier]; | 526 return g_task_runners.Get().proxies[identifier]; |
| 528 } | 527 } |
| 529 | 528 |
| 530 // static | 529 // static |
| 531 base::MessageLoop* BrowserThread::UnsafeGetMessageLoopForThread(ID identifier) { | 530 base::MessageLoop* BrowserThread::UnsafeGetMessageLoopForThread(ID identifier) { |
| 532 if (g_globals == NULL) | 531 if (g_globals == NULL) |
| 533 return NULL; | 532 return NULL; |
| 534 | 533 |
| 535 BrowserThreadGlobals& globals = g_globals.Get(); | 534 BrowserThreadGlobals& globals = g_globals.Get(); |
| 536 base::AutoLock lock(globals.lock); | 535 base::AutoLock lock(globals.lock); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 548 AtomicWord* storage = reinterpret_cast<AtomicWord*>( | 547 AtomicWord* storage = reinterpret_cast<AtomicWord*>( |
| 549 &globals.thread_delegates[identifier]); | 548 &globals.thread_delegates[identifier]); |
| 550 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( | 549 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( |
| 551 storage, reinterpret_cast<AtomicWord>(delegate)); | 550 storage, reinterpret_cast<AtomicWord>(delegate)); |
| 552 | 551 |
| 553 // This catches registration when previously registered. | 552 // This catches registration when previously registered. |
| 554 DCHECK(!delegate || !old_pointer); | 553 DCHECK(!delegate || !old_pointer); |
| 555 } | 554 } |
| 556 | 555 |
| 557 } // namespace content | 556 } // namespace content |
| OLD | NEW |