| 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> |
| 8 |
| 7 #include "base/atomicops.h" | 9 #include "base/atomicops.h" |
| 8 #include "base/bind.h" | 10 #include "base/bind.h" |
| 9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 10 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 11 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 12 #include "base/message_loop_proxy.h" | 14 #include "base/message_loop_proxy.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 15 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
| 17 #include "content/public/browser/browser_thread_delegate.h" |
| 15 | 18 |
| 16 namespace content { | 19 namespace content { |
| 17 | 20 |
| 18 namespace { | 21 namespace { |
| 19 | 22 |
| 20 // Friendly names for the well-known threads. | 23 // Friendly names for the well-known threads. |
| 21 static const char* g_browser_thread_names[BrowserThread::ID_COUNT] = { | 24 static const char* g_browser_thread_names[BrowserThread::ID_COUNT] = { |
| 22 "", // UI (name assembled in browser_main.cc). | 25 "", // UI (name assembled in browser_main.cc). |
| 23 "Chrome_DBThread", // DB | 26 "Chrome_DBThread", // DB |
| 24 "Chrome_WebKitThread", // WEBKIT_DEPRECATED | 27 "Chrome_WebKitThread", // WEBKIT_DEPRECATED |
| 25 "Chrome_FileThread", // FILE | 28 "Chrome_FileThread", // FILE |
| 26 "Chrome_FileUserBlockingThread", // FILE_USER_BLOCKING | 29 "Chrome_FileUserBlockingThread", // FILE_USER_BLOCKING |
| 27 "Chrome_ProcessLauncherThread", // PROCESS_LAUNCHER | 30 "Chrome_ProcessLauncherThread", // PROCESS_LAUNCHER |
| 28 "Chrome_CacheThread", // CACHE | 31 "Chrome_CacheThread", // CACHE |
| 29 "Chrome_IOThread", // IO | 32 "Chrome_IOThread", // IO |
| 30 }; | 33 }; |
| 31 | 34 |
| 32 struct BrowserThreadGlobals { | 35 struct BrowserThreadGlobals { |
| 33 BrowserThreadGlobals() | 36 BrowserThreadGlobals() |
| 34 : blocking_pool(new base::SequencedWorkerPool(3, "BrowserBlocking")) { | 37 : blocking_pool(new base::SequencedWorkerPool(3, "BrowserBlocking")) { |
| 35 memset(threads, 0, | 38 memset(threads, 0, BrowserThread::ID_COUNT * sizeof(threads[0])); |
| 36 BrowserThread::ID_COUNT * sizeof(BrowserThreadImpl*)); | |
| 37 memset(thread_delegates, 0, | 39 memset(thread_delegates, 0, |
| 38 BrowserThread::ID_COUNT * sizeof(BrowserThreadDelegate*)); | 40 BrowserThread::ID_COUNT * sizeof(thread_delegates[0])); |
| 39 } | 41 } |
| 40 | 42 |
| 41 // This lock protects |threads|. Do not read or modify that array | 43 // This lock protects |threads|. Do not read or modify that array |
| 42 // without holding this lock. Do not block while holding this lock. | 44 // without holding this lock. Do not block while holding this lock. |
| 43 base::Lock lock; | 45 base::Lock lock; |
| 44 | 46 |
| 45 // This array is protected by |lock|. The threads are not owned by this | 47 // This array is protected by |lock|. The threads are not owned by this |
| 46 // array. Typically, the threads are owned on the UI thread by | 48 // array. Typically, the threads are owned on the UI thread by |
| 47 // content::BrowserMainLoop. BrowserThreadImpl objects remove themselves from | 49 // content::BrowserMainLoop. BrowserThreadImpl objects remove themselves from |
| 48 // this array upon destruction. | 50 // this array upon destruction. |
| (...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 AtomicWord* storage = reinterpret_cast<AtomicWord*>( | 392 AtomicWord* storage = reinterpret_cast<AtomicWord*>( |
| 391 &globals.thread_delegates[identifier]); | 393 &globals.thread_delegates[identifier]); |
| 392 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( | 394 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( |
| 393 storage, reinterpret_cast<AtomicWord>(delegate)); | 395 storage, reinterpret_cast<AtomicWord>(delegate)); |
| 394 | 396 |
| 395 // This catches registration when previously registered. | 397 // This catches registration when previously registered. |
| 396 DCHECK(!delegate || !old_pointer); | 398 DCHECK(!delegate || !old_pointer); |
| 397 } | 399 } |
| 398 | 400 |
| 399 } // namespace content | 401 } // namespace content |
| OLD | NEW |