Chromium Code Reviews| 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" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/message_loop/message_loop_proxy.h" | 14 #include "base/message_loop/message_loop_proxy.h" |
| 15 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
| 16 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
| 17 #include "content/public/browser/browser_thread_delegate.h" | 17 #include "content/public/browser/browser_thread_delegate.h" |
| 18 | 18 |
| 19 #if defined(OS_ANDROID) | |
| 20 #include "base/android/jni_android.h" | |
| 21 #endif | |
| 22 | |
| 19 namespace content { | 23 namespace content { |
| 20 | 24 |
| 21 namespace { | 25 namespace { |
| 22 | 26 |
| 23 // Friendly names for the well-known threads. | 27 // Friendly names for the well-known threads. |
| 24 static const char* g_browser_thread_names[BrowserThread::ID_COUNT] = { | 28 static const char* g_browser_thread_names[BrowserThread::ID_COUNT] = { |
| 25 "", // UI (name assembled in browser_main.cc). | 29 "", // UI (name assembled in browser_main.cc). |
| 26 "Chrome_DBThread", // DB | 30 "Chrome_DBThread", // DB |
| 27 "Chrome_FileThread", // FILE | 31 "Chrome_FileThread", // FILE |
| 28 "Chrome_FileUserBlockingThread", // FILE_USER_BLOCKING | 32 "Chrome_FileUserBlockingThread", // FILE_USER_BLOCKING |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 NOINLINE void BrowserThreadImpl::IOThreadRun(base::MessageLoop* message_loop) { | 215 NOINLINE void BrowserThreadImpl::IOThreadRun(base::MessageLoop* message_loop) { |
| 212 volatile int line_number = __LINE__; | 216 volatile int line_number = __LINE__; |
| 213 Thread::Run(message_loop); | 217 Thread::Run(message_loop); |
| 214 CHECK_GT(line_number, 0); | 218 CHECK_GT(line_number, 0); |
| 215 } | 219 } |
| 216 | 220 |
| 217 MSVC_POP_WARNING() | 221 MSVC_POP_WARNING() |
| 218 MSVC_ENABLE_OPTIMIZE(); | 222 MSVC_ENABLE_OPTIMIZE(); |
| 219 | 223 |
| 220 void BrowserThreadImpl::Run(base::MessageLoop* message_loop) { | 224 void BrowserThreadImpl::Run(base::MessageLoop* message_loop) { |
| 225 #if defined(OS_ANDROID) | |
| 226 // Not to reset thread name to "Thread-???" by VM, attach VM with thread name. | |
|
sky
2014/06/19 20:48:17
This comment makes no sense.
byungchul
2014/06/19 20:56:30
Otherwise, VM resets thread name.
| |
| 227 // Though it may create unnecessary VM thread objects, keeping thread name | |
| 228 // gives more benefit in debugging in the platform. | |
| 229 if (!thread_name().empty()) { | |
| 230 base::android::AttachCurrentThreadWithName(thread_name()); | |
|
sky
2014/06/19 20:48:17
I'm not familiar with thread_name(). Isn't it prop
byungchul
2014/06/19 20:56:30
Yes, but jvm's AttachCurrentThread() resets thread
| |
| 231 } | |
| 232 #endif | |
| 233 | |
| 221 BrowserThread::ID thread_id = ID_COUNT; | 234 BrowserThread::ID thread_id = ID_COUNT; |
| 222 if (!GetCurrentThreadIdentifier(&thread_id)) | 235 if (!GetCurrentThreadIdentifier(&thread_id)) |
| 223 return Thread::Run(message_loop); | 236 return Thread::Run(message_loop); |
| 224 | 237 |
| 225 switch (thread_id) { | 238 switch (thread_id) { |
| 226 case BrowserThread::UI: | 239 case BrowserThread::UI: |
| 227 return UIThreadRun(message_loop); | 240 return UIThreadRun(message_loop); |
| 228 case BrowserThread::DB: | 241 case BrowserThread::DB: |
| 229 return DBThreadRun(message_loop); | 242 return DBThreadRun(message_loop); |
| 230 case BrowserThread::FILE: | 243 case BrowserThread::FILE: |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 517 AtomicWord* storage = reinterpret_cast<AtomicWord*>( | 530 AtomicWord* storage = reinterpret_cast<AtomicWord*>( |
| 518 &globals.thread_delegates[identifier]); | 531 &globals.thread_delegates[identifier]); |
| 519 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( | 532 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( |
| 520 storage, reinterpret_cast<AtomicWord>(delegate)); | 533 storage, reinterpret_cast<AtomicWord>(delegate)); |
| 521 | 534 |
| 522 // This catches registration when previously registered. | 535 // This catches registration when previously registered. |
| 523 DCHECK(!delegate || !old_pointer); | 536 DCHECK(!delegate || !old_pointer); |
| 524 } | 537 } |
| 525 | 538 |
| 526 } // namespace content | 539 } // namespace content |
| OLD | NEW |