Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: chrome/browser/browser_thread.cc

Issue 5024003: Reland r65996. Disallows Singletons on non-joinable thread. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Allow another use that should be fixed. Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ceee/ie/broker/executors_manager.h ('k') | net/base/dns_reload_timer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "chrome/browser/browser_thread.h" 5 #include "chrome/browser/browser_thread.h"
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
9 #include "base/thread_restrictions.h"
9 10
10 // Friendly names for the well-known threads. 11 // Friendly names for the well-known threads.
11 static const char* browser_thread_names[BrowserThread::ID_COUNT] = { 12 static const char* browser_thread_names[BrowserThread::ID_COUNT] = {
12 "", // UI (name assembled in browser_main.cc). 13 "", // UI (name assembled in browser_main.cc).
13 "Chrome_DBThread", // DB 14 "Chrome_DBThread", // DB
14 "Chrome_WebKitThread", // WEBKIT 15 "Chrome_WebKitThread", // WEBKIT
15 "Chrome_FileThread", // FILE 16 "Chrome_FileThread", // FILE
16 "Chrome_ProcessLauncherThread", // PROCESS_LAUNCHER 17 "Chrome_ProcessLauncherThread", // PROCESS_LAUNCHER
17 "Chrome_CacheThread", // CACHE 18 "Chrome_CacheThread", // CACHE
18 "Chrome_IOThread", // IO 19 "Chrome_IOThread", // IO
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 106
106 // static 107 // static
107 bool BrowserThread::IsWellKnownThread(ID identifier) { 108 bool BrowserThread::IsWellKnownThread(ID identifier) {
108 AutoLock lock(lock_); 109 AutoLock lock(lock_);
109 return (identifier >= 0 && identifier < ID_COUNT && 110 return (identifier >= 0 && identifier < ID_COUNT &&
110 browser_threads_[identifier]); 111 browser_threads_[identifier]);
111 } 112 }
112 113
113 // static 114 // static
114 bool BrowserThread::CurrentlyOn(ID identifier) { 115 bool BrowserThread::CurrentlyOn(ID identifier) {
116 // We shouldn't use MessageLoop::current() since it uses LazyInstance which
117 // may be deleted by ~AtExitManager when a WorkerPool thread calls this
118 // function.
119 // http://crbug.com/63678
120 base::ThreadRestrictions::ScopedAllowSingleton allow_singleton;
115 AutoLock lock(lock_); 121 AutoLock lock(lock_);
116 DCHECK(identifier >= 0 && identifier < ID_COUNT); 122 DCHECK(identifier >= 0 && identifier < ID_COUNT);
117 return browser_threads_[identifier] && 123 return browser_threads_[identifier] &&
118 browser_threads_[identifier]->message_loop() == MessageLoop::current(); 124 browser_threads_[identifier]->message_loop() == MessageLoop::current();
119 } 125 }
120 126
121 // static 127 // static
122 bool BrowserThread::IsMessageLoopValid(ID identifier) { 128 bool BrowserThread::IsMessageLoopValid(ID identifier) {
123 AutoLock lock(lock_); 129 AutoLock lock(lock_);
124 DCHECK(identifier >= 0 && identifier < ID_COUNT); 130 DCHECK(identifier >= 0 && identifier < ID_COUNT);
(...skipping 28 matching lines...) Expand all
153 bool BrowserThread::PostNonNestableDelayedTask( 159 bool BrowserThread::PostNonNestableDelayedTask(
154 ID identifier, 160 ID identifier,
155 const tracked_objects::Location& from_here, 161 const tracked_objects::Location& from_here,
156 Task* task, 162 Task* task,
157 int64 delay_ms) { 163 int64 delay_ms) {
158 return PostTaskHelper(identifier, from_here, task, delay_ms, false); 164 return PostTaskHelper(identifier, from_here, task, delay_ms, false);
159 } 165 }
160 166
161 // static 167 // static
162 bool BrowserThread::GetCurrentThreadIdentifier(ID* identifier) { 168 bool BrowserThread::GetCurrentThreadIdentifier(ID* identifier) {
169 // We shouldn't use MessageLoop::current() since it uses LazyInstance which
170 // may be deleted by ~AtExitManager when a WorkerPool thread calls this
171 // function.
172 // http://crbug.com/63678
173 base::ThreadRestrictions::ScopedAllowSingleton allow_singleton;
163 MessageLoop* cur_message_loop = MessageLoop::current(); 174 MessageLoop* cur_message_loop = MessageLoop::current();
164 for (int i = 0; i < ID_COUNT; ++i) { 175 for (int i = 0; i < ID_COUNT; ++i) {
165 if (browser_threads_[i] && 176 if (browser_threads_[i] &&
166 browser_threads_[i]->message_loop() == cur_message_loop) { 177 browser_threads_[i]->message_loop() == cur_message_loop) {
167 *identifier = browser_threads_[i]->identifier_; 178 *identifier = browser_threads_[i]->identifier_;
168 return true; 179 return true;
169 } 180 }
170 } 181 }
171 182
172 return false; 183 return false;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 } 224 }
214 } else { 225 } else {
215 delete task; 226 delete task;
216 } 227 }
217 228
218 if (!guaranteed_to_outlive_target_thread) 229 if (!guaranteed_to_outlive_target_thread)
219 lock_.Release(); 230 lock_.Release();
220 231
221 return !!message_loop; 232 return !!message_loop;
222 } 233 }
OLDNEW
« no previous file with comments | « ceee/ie/broker/executors_manager.h ('k') | net/base/dns_reload_timer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698