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

Unified Diff: content/public/browser/browser_thread.h

Issue 8477004: Have content/ create and destroy its own threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More IWYU, missing link-time dependency for Chrome Frame. Created 9 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 side-by-side diff with in-line comments
Download patch
Index: content/public/browser/browser_thread.h
diff --git a/content/public/browser/browser_thread.h b/content/public/browser/browser_thread.h
index 66dc009beaf26dbf8f08a81d828fba11cc2777b6..83b639e6446474568c280e143b0b7018b0b61d0a 100644
--- a/content/public/browser/browser_thread.h
+++ b/content/public/browser/browser_thread.h
@@ -6,10 +6,10 @@
#define CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_H_
#pragma once
+#include "base/basictypes.h"
#include "base/callback.h"
-#include "base/synchronization/lock.h"
#include "base/task.h"
-#include "base/threading/thread.h"
+#include "base/tracked_objects.h"
#include "content/common/content_export.h"
#if defined(UNIT_TEST)
@@ -18,12 +18,12 @@
namespace base {
class MessageLoopProxy;
+class Thread;
}
namespace content {
class BrowserThreadImpl;
-class DeprecatedBrowserThread;
///////////////////////////////////////////////////////////////////////////////
// BrowserThread
@@ -47,7 +47,7 @@ class DeprecatedBrowserThread;
// task is posted to is guaranteed to outlive the current thread, then no locks
// are used. You should never need to cache pointers to MessageLoops, since
// they're not thread safe.
-class CONTENT_EXPORT BrowserThread : public base::Thread {
+class CONTENT_EXPORT BrowserThread {
public:
// An enumeration of the well-known threads.
// NOTE: threads must be listed in the order of their life-time, with each
@@ -170,6 +170,23 @@ class CONTENT_EXPORT BrowserThread : public base::Thread {
static scoped_refptr<base::MessageLoopProxy> GetMessageLoopProxyForThread(
ID identifier);
+ // Gets the Thread object for the specified thread, or NULL if the
+ // thread has not been created (or has been destroyed during
+ // shutdown).
+ //
+ // Before calling this, you must have called content::ContentMain
+ // with a command-line that would specify a browser process (e.g. an
+ // empty command line).
+ //
+ // This is unsafe as your pointer may become invalid close to
+ // shutdown.
+ //
+ // TODO(joi): Remove this once clients such as BrowserProcessImpl
+ // (and classes that call things like
+ // g_browser_process->file_thread()) are switched to using
+ // MessageLoopProxy.
+ static base::Thread* UnsafeGetBrowserThread(ID identifier);
+
// Use these templates in conjuction with RefCountedThreadSafe when you want
// to ensure that an object is deleted on a specific thread. This is needed
// when an object can hop between threads (i.e. IO -> FILE -> IO), and thread
@@ -213,40 +230,10 @@ class CONTENT_EXPORT BrowserThread : public base::Thread {
struct DeleteOnWebKitThread : public DeleteOnThread<WEBKIT> { };
private:
- // Construct a BrowserThread with the supplied identifier. It is an error
- // to construct a BrowserThread that already exists.
- explicit BrowserThread(ID identifier);
-
- // Special constructor for the main (UI) thread and unittests. We use a dummy
- // thread here since the main thread already exists.
- BrowserThread(ID identifier, MessageLoop* message_loop);
-
- virtual ~BrowserThread();
+ friend class BrowserThreadImpl;
- // Common initialization code for the constructors.
- void Initialize();
-
- // Constructors are only available through this subclass.
- friend class content::BrowserThreadImpl;
-
- // TODO(joi): Remove.
- friend class DeprecatedBrowserThread;
-
- // The identifier of this thread. Only one thread can exist with a given
- // identifier at a given time.
- // TODO(joi): Move to BrowserThreadImpl, and make constructors here
- // do-nothing.
- ID identifier_;
-};
-
-// Temporary escape hatch for chrome/ to construct BrowserThread,
-// until we make content/ construct its own threads.
-class CONTENT_EXPORT DeprecatedBrowserThread : public BrowserThread {
- public:
- explicit DeprecatedBrowserThread(BrowserThread::ID identifier);
- DeprecatedBrowserThread(BrowserThread::ID identifier,
- MessageLoop* message_loop);
- virtual ~DeprecatedBrowserThread();
+ BrowserThread() {}
+ DISALLOW_COPY_AND_ASSIGN(BrowserThread);
};
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698