Commit dfcbd5a7 authored by rsleevi@chromium.org's avatar rsleevi@chromium.org

Ensure that content will consistently return the same MessageLoopProxy for a given BrowserThread

BUG=378079
R=jam@chromium.org

Review URL: https://codereview.chromium.org/314053003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276334 0039d316-1c4b-4281-b951-d872f2087c98
parent cf0d342b
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment