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.h" | 13 #include "base/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 namespace content { | 19 namespace content { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 // Friendly names for the well-known threads. | 23 // Friendly names for the well-known threads. |
24 static const char* g_browser_thread_names[BrowserThread::ID_COUNT] = { | 24 static const char* g_browser_thread_names[BrowserThread::ID_COUNT] = { |
25 "", // UI (name assembled in browser_main.cc). | 25 "", // UI (name assembled in browser_main.cc). |
26 "Chrome_DBThread", // DB | 26 "Chrome_DBThread", // DB |
27 "Chrome_WebKitThread", // WEBKIT_DEPRECATED | |
28 "Chrome_FileThread", // FILE | 27 "Chrome_FileThread", // FILE |
29 "Chrome_FileUserBlockingThread", // FILE_USER_BLOCKING | 28 "Chrome_FileUserBlockingThread", // FILE_USER_BLOCKING |
30 "Chrome_ProcessLauncherThread", // PROCESS_LAUNCHER | 29 "Chrome_ProcessLauncherThread", // PROCESS_LAUNCHER |
31 "Chrome_CacheThread", // CACHE | 30 "Chrome_CacheThread", // CACHE |
32 "Chrome_IOThread", // IO | 31 "Chrome_IOThread", // IO |
33 }; | 32 }; |
34 | 33 |
35 struct BrowserThreadGlobals { | 34 struct BrowserThreadGlobals { |
36 BrowserThreadGlobals() | 35 BrowserThreadGlobals() |
37 : blocking_pool(new base::SequencedWorkerPool(3, "BrowserBlocking")) { | 36 : blocking_pool(new base::SequencedWorkerPool(3, "BrowserBlocking")) { |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 Thread::Run(message_loop); | 122 Thread::Run(message_loop); |
124 CHECK_GT(line_number, 0); | 123 CHECK_GT(line_number, 0); |
125 } | 124 } |
126 | 125 |
127 NOINLINE void BrowserThreadImpl::DBThreadRun(base::MessageLoop* message_loop) { | 126 NOINLINE void BrowserThreadImpl::DBThreadRun(base::MessageLoop* message_loop) { |
128 volatile int line_number = __LINE__; | 127 volatile int line_number = __LINE__; |
129 Thread::Run(message_loop); | 128 Thread::Run(message_loop); |
130 CHECK_GT(line_number, 0); | 129 CHECK_GT(line_number, 0); |
131 } | 130 } |
132 | 131 |
133 NOINLINE void BrowserThreadImpl::WebKitThreadRun( | |
134 base::MessageLoop* message_loop) { | |
135 volatile int line_number = __LINE__; | |
136 Thread::Run(message_loop); | |
137 CHECK_GT(line_number, 0); | |
138 } | |
139 | |
140 NOINLINE void BrowserThreadImpl::FileThreadRun( | 132 NOINLINE void BrowserThreadImpl::FileThreadRun( |
141 base::MessageLoop* message_loop) { | 133 base::MessageLoop* message_loop) { |
142 volatile int line_number = __LINE__; | 134 volatile int line_number = __LINE__; |
143 Thread::Run(message_loop); | 135 Thread::Run(message_loop); |
144 CHECK_GT(line_number, 0); | 136 CHECK_GT(line_number, 0); |
145 } | 137 } |
146 | 138 |
147 NOINLINE void BrowserThreadImpl::FileUserBlockingThreadRun( | 139 NOINLINE void BrowserThreadImpl::FileUserBlockingThreadRun( |
148 base::MessageLoop* message_loop) { | 140 base::MessageLoop* message_loop) { |
149 volatile int line_number = __LINE__; | 141 volatile int line_number = __LINE__; |
(...skipping 27 matching lines...) Expand all Loading... |
177 void BrowserThreadImpl::Run(base::MessageLoop* message_loop) { | 169 void BrowserThreadImpl::Run(base::MessageLoop* message_loop) { |
178 BrowserThread::ID thread_id; | 170 BrowserThread::ID thread_id; |
179 if (!GetCurrentThreadIdentifier(&thread_id)) | 171 if (!GetCurrentThreadIdentifier(&thread_id)) |
180 return Thread::Run(message_loop); | 172 return Thread::Run(message_loop); |
181 | 173 |
182 switch (thread_id) { | 174 switch (thread_id) { |
183 case BrowserThread::UI: | 175 case BrowserThread::UI: |
184 return UIThreadRun(message_loop); | 176 return UIThreadRun(message_loop); |
185 case BrowserThread::DB: | 177 case BrowserThread::DB: |
186 return DBThreadRun(message_loop); | 178 return DBThreadRun(message_loop); |
187 case BrowserThread::WEBKIT_DEPRECATED: | |
188 return WebKitThreadRun(message_loop); | |
189 case BrowserThread::FILE: | 179 case BrowserThread::FILE: |
190 return FileThreadRun(message_loop); | 180 return FileThreadRun(message_loop); |
191 case BrowserThread::FILE_USER_BLOCKING: | 181 case BrowserThread::FILE_USER_BLOCKING: |
192 return FileUserBlockingThreadRun(message_loop); | 182 return FileUserBlockingThreadRun(message_loop); |
193 case BrowserThread::PROCESS_LAUNCHER: | 183 case BrowserThread::PROCESS_LAUNCHER: |
194 return ProcessLauncherThreadRun(message_loop); | 184 return ProcessLauncherThreadRun(message_loop); |
195 case BrowserThread::CACHE: | 185 case BrowserThread::CACHE: |
196 return CacheThreadRun(message_loop); | 186 return CacheThreadRun(message_loop); |
197 case BrowserThread::IO: | 187 case BrowserThread::IO: |
198 return IOThreadRun(message_loop); | 188 return IOThreadRun(message_loop); |
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
483 AtomicWord* storage = reinterpret_cast<AtomicWord*>( | 473 AtomicWord* storage = reinterpret_cast<AtomicWord*>( |
484 &globals.thread_delegates[identifier]); | 474 &globals.thread_delegates[identifier]); |
485 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( | 475 AtomicWord old_pointer = base::subtle::NoBarrier_AtomicExchange( |
486 storage, reinterpret_cast<AtomicWord>(delegate)); | 476 storage, reinterpret_cast<AtomicWord>(delegate)); |
487 | 477 |
488 // This catches registration when previously registered. | 478 // This catches registration when previously registered. |
489 DCHECK(!delegate || !old_pointer); | 479 DCHECK(!delegate || !old_pointer); |
490 } | 480 } |
491 | 481 |
492 } // namespace content | 482 } // namespace content |
OLD | NEW |