| Index: content/browser/browser_thread_impl.cc
|
| diff --git a/content/browser/browser_thread_impl.cc b/content/browser/browser_thread_impl.cc
|
| index 297bb30d7cbbcc660439f6b19738ae13eea039b1..50108d9105044cdcc37aa2fb9fbe7882fe14d51a 100644
|
| --- a/content/browser/browser_thread_impl.cc
|
| +++ b/content/browser/browser_thread_impl.cc
|
| @@ -175,53 +175,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, int64 delay_ms) OVERRIDE {
|
| - return BrowserThread::PostDelayedTask(id_, from_here, task, delay_ms);
|
| - }
|
| - 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,
|
| - int64 delay_ms) OVERRIDE {
|
| - return BrowserThread::PostNonNestableDelayedTask(id_, from_here, task,
|
| - delay_ms);
|
| - }
|
| - 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,
|
| @@ -389,9 +342,30 @@ bool BrowserThread::GetCurrentThreadIdentifier(ID* identifier) {
|
| // static
|
| scoped_refptr<base::MessageLoopProxy>
|
| BrowserThread::GetMessageLoopProxyForThread(ID identifier) {
|
| - scoped_refptr<base::MessageLoopProxy> proxy(
|
| - new BrowserThreadMessageLoopProxy(identifier));
|
| - return proxy;
|
| + if (g_globals == NULL)
|
| + return NULL;
|
| +
|
| + BrowserThread::ID current_thread;
|
| + bool guaranteed_to_outlive_target_thread =
|
| + GetCurrentThreadIdentifier(¤t_thread) &&
|
| + current_thread <= identifier;
|
| +
|
| + BrowserThreadGlobals& globals = g_globals.Get();
|
| + if (!guaranteed_to_outlive_target_thread)
|
| + globals.lock.Acquire();
|
| +
|
| + base::Thread* thread = globals.threads[identifier];
|
| + if (!thread) {
|
| + if (!guaranteed_to_outlive_target_thread)
|
| + globals.lock.Release();
|
| + return NULL;
|
| + }
|
| + scoped_refptr<base::MessageLoopProxy> loop = thread->message_loop_proxy();
|
| +
|
| + if (!guaranteed_to_outlive_target_thread)
|
| + globals.lock.Release();
|
| +
|
| + return loop;
|
| }
|
|
|
| // static
|
|
|