Index: content/browser/browser_thread_impl.cc |
diff --git a/content/browser/browser_thread_impl.cc b/content/browser/browser_thread_impl.cc |
index 7b118d6c817ab2e228aab2e3ef3e571c34d3e0dd..d3c416d687f5a8986d107b2969f153cb96cdffad 100644 |
--- a/content/browser/browser_thread_impl.cc |
+++ b/content/browser/browser_thread_impl.cc |
@@ -31,6 +31,57 @@ static const char* g_browser_thread_names[BrowserThread::ID_COUNT] = { |
"Chrome_IOThread", // IO |
}; |
+// An implementation of MessageLoopProxy to be used in conjunction |
+// with BrowserThread. |
+class BrowserThreadMessageLoopProxy : public base::MessageLoopProxy { |
+ public: |
+ explicit BrowserThreadMessageLoopProxy(BrowserThread::ID identifier) |
+ : id_(identifier) { |
+ } |
+ |
+ // MessageLoopProxy implementation. |
+ virtual bool PostDelayedTask( |
+ const tracked_objects::Location& from_here, |
+ const base::Closure& task, base::TimeDelta delay) OVERRIDE { |
+ return BrowserThread::PostDelayedTask(id_, from_here, task, delay); |
+ } |
+ |
+ virtual bool PostNonNestableDelayedTask( |
+ const tracked_objects::Location& from_here, |
+ const base::Closure& task, |
+ base::TimeDelta delay) OVERRIDE { |
+ return BrowserThread::PostNonNestableDelayedTask(id_, from_here, task, |
+ delay); |
+ } |
+ |
+ virtual bool RunsTasksOnCurrentThread() const OVERRIDE { |
+ return BrowserThread::CurrentlyOn(id_); |
+ } |
+ |
+ protected: |
+ virtual ~BrowserThreadMessageLoopProxy() {} |
+ |
+ private: |
+ BrowserThread::ID id_; |
+ DISALLOW_COPY_AND_ASSIGN(BrowserThreadMessageLoopProxy); |
+}; |
+ |
+// A separate helper is used just for the proxies, in order to avoid needing |
+// to initialize the globals to create a proxy. |
+struct BrowserThreadProxies { |
+ BrowserThreadProxies() { |
+ for (int i = 0; i < BrowserThread::ID_COUNT; ++i) { |
+ proxies[i] = |
+ new BrowserThreadMessageLoopProxy(static_cast<BrowserThread::ID>(i)); |
+ } |
+ } |
+ |
+ scoped_refptr<base::MessageLoopProxy> proxies[BrowserThread::ID_COUNT]; |
+}; |
+ |
+base::LazyInstance<BrowserThreadProxies>::Leaky |
+ g_proxies = LAZY_INSTANCE_INITIALIZER; |
+ |
struct BrowserThreadGlobals { |
BrowserThreadGlobals() |
: blocking_pool(new base::SequencedWorkerPool(3, "BrowserBlocking")) { |
@@ -274,41 +325,6 @@ bool BrowserThreadImpl::PostTaskHelper( |
return !!message_loop; |
} |
-// An implementation of MessageLoopProxy to be used in conjunction |
-// with BrowserThread. |
-class BrowserThreadMessageLoopProxy : public base::MessageLoopProxy { |
- public: |
- explicit BrowserThreadMessageLoopProxy(BrowserThread::ID identifier) |
- : id_(identifier) { |
- } |
- |
- // MessageLoopProxy implementation. |
- virtual bool PostDelayedTask( |
- const tracked_objects::Location& from_here, |
- const base::Closure& task, base::TimeDelta delay) OVERRIDE { |
- return BrowserThread::PostDelayedTask(id_, from_here, task, delay); |
- } |
- |
- virtual bool PostNonNestableDelayedTask( |
- const tracked_objects::Location& from_here, |
- const base::Closure& task, |
- base::TimeDelta delay) OVERRIDE { |
- return BrowserThread::PostNonNestableDelayedTask(id_, from_here, task, |
- delay); |
- } |
- |
- virtual bool RunsTasksOnCurrentThread() const OVERRIDE { |
- return BrowserThread::CurrentlyOn(id_); |
- } |
- |
- protected: |
- virtual ~BrowserThreadMessageLoopProxy() {} |
- |
- private: |
- BrowserThread::ID id_; |
- DISALLOW_COPY_AND_ASSIGN(BrowserThreadMessageLoopProxy); |
-}; |
- |
// static |
bool BrowserThread::PostBlockingPoolTask( |
const tracked_objects::Location& from_here, |
@@ -477,7 +493,7 @@ bool BrowserThread::GetCurrentThreadIdentifier(ID* identifier) { |
// static |
scoped_refptr<base::MessageLoopProxy> |
BrowserThread::GetMessageLoopProxyForThread(ID identifier) { |
- return make_scoped_refptr(new BrowserThreadMessageLoopProxy(identifier)); |
+ return g_proxies.Get().proxies[identifier]; |
} |
// static |