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

Unified Diff: content/browser/browser_thread_impl.cc

Issue 314053003: Ensure that content will consistently return the same MessageLoopProxy for a given BrowserThread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698