| 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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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() == |
| 365 base::MessageLoop::current(); | 365 base::MessageLoop::current(); |
| 366 } | 366 } |
| 367 | 367 |
| 368 static const char* GetThreadName(BrowserThread::ID thread) { |
| 369 if (BrowserThread::UI < thread && thread < BrowserThread::ID_COUNT) |
| 370 return g_browser_thread_names[thread]; |
| 371 if (thread == BrowserThread::UI) |
| 372 return "Chrome_UIThread"; |
| 373 return "Unknown Thread"; |
| 374 } |
| 375 |
| 376 // static |
| 377 std::string BrowserThread::GetDCheckCurrentlyOnErrorMessage(ID expected) { |
| 378 const std::string& message_loop_name = |
| 379 base::MessageLoop::current()->thread_name(); |
| 380 ID actual_browser_thread; |
| 381 const char* actual_name = "Unknown Thread"; |
| 382 if (!message_loop_name.empty()) { |
| 383 actual_name = message_loop_name.c_str(); |
| 384 } else if (GetCurrentThreadIdentifier(&actual_browser_thread)) { |
| 385 actual_name = GetThreadName(actual_browser_thread); |
| 386 } |
| 387 std::string result = "Must be called on "; |
| 388 result += GetThreadName(expected); |
| 389 result += "; actually called on "; |
| 390 result += actual_name; |
| 391 result += "."; |
| 392 return result; |
| 393 } |
| 394 |
| 368 // static | 395 // static |
| 369 bool BrowserThread::IsMessageLoopValid(ID identifier) { | 396 bool BrowserThread::IsMessageLoopValid(ID identifier) { |
| 370 if (g_globals == NULL) | 397 if (g_globals == NULL) |
| 371 return false; | 398 return false; |
| 372 | 399 |
| 373 BrowserThreadGlobals& globals = g_globals.Get(); | 400 BrowserThreadGlobals& globals = g_globals.Get(); |
| 374 base::AutoLock lock(globals.lock); | 401 base::AutoLock lock(globals.lock); |
| 375 DCHECK(identifier >= 0 && identifier < ID_COUNT); | 402 DCHECK(identifier >= 0 && identifier < ID_COUNT); |
| 376 return globals.threads[identifier] && | 403 return globals.threads[identifier] && |
| 377 globals.threads[identifier]->message_loop(); | 404 globals.threads[identifier]->message_loop(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 AtomicWord* storage = reinterpret_cast<AtomicWord*>( | 501 AtomicWord* storage = reinterpret_cast<AtomicWord*>( |
| 475 &globals.thread_delegates[identifier]); | 502 &globals.thread_delegates[identifier]); |
| 476 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( | 503 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( |
| 477 storage, reinterpret_cast<AtomicWord>(delegate)); | 504 storage, reinterpret_cast<AtomicWord>(delegate)); |
| 478 | 505 |
| 479 // This catches registration when previously registered. | 506 // This catches registration when previously registered. |
| 480 DCHECK(!delegate || !old_pointer); | 507 DCHECK(!delegate || !old_pointer); |
| 481 } | 508 } |
| 482 | 509 |
| 483 } // namespace content | 510 } // namespace content |
| OLD | NEW |