summaryrefslogtreecommitdiffstats
path: root/content/public
diff options
context:
space:
mode:
Diffstat (limited to 'content/public')
-rw-r--r--content/public/browser/browser_main_parts.h33
-rw-r--r--content/public/browser/browser_shutdown.h32
-rw-r--r--content/public/browser/browser_thread.h81
-rw-r--r--content/public/browser/browser_thread_delegate.h32
4 files changed, 141 insertions, 37 deletions
diff --git a/content/public/browser/browser_main_parts.h b/content/public/browser/browser_main_parts.h
index 860541c..4bce3cf 100644
--- a/content/public/browser/browser_main_parts.h
+++ b/content/public/browser/browser_main_parts.h
@@ -8,6 +8,7 @@
#include "base/basictypes.h"
#include "content/common/content_export.h"
+#include "content/public/browser/browser_thread.h"
namespace content {
@@ -64,6 +65,24 @@ class CONTENT_EXPORT BrowserMainParts {
// Allows an embedder to do any extra toolkit initialization.
virtual void ToolkitInitialized() = 0;
+ // Called just before any child threads owned by the content
+ // framework are created.
+ //
+ // The main message loop has been started at this point (but has not
+ // been run), and the toolkit has been initialized.
+ virtual void PreCreateThreads() = 0;
+
+ // Called once for each thread owned by the content framework just
+ // before and just after the thread object is created and started.
+ // This happens in the order of the threads' appearence in the
+ // BrowserThread::ID enumeration. Note that there will be no such
+ // call for BrowserThread::UI, since it is the main thread of the
+ // application.
+ virtual void PreStartThread(BrowserThread::ID identifier) = 0;
+ virtual void PostStartThread(BrowserThread::ID identifier) = 0;
+
+ // This is called just before the main message loop is run. The
+ // various browser threads have all been created at this point
virtual void PreMainMessageLoopRun() = 0;
// Returns true if the message loop was run, false otherwise.
@@ -71,8 +90,22 @@ class CONTENT_EXPORT BrowserMainParts {
// May set |result_code|, which will be returned by |BrowserMain()|.
virtual bool MainMessageLoopRun(int* result_code) = 0;
+ // This happens after the main message loop has stopped, but before
+ // threads are stopped.
virtual void PostMainMessageLoopRun() = 0;
+ // Called once for each thread owned by the content framework just
+ // before and just after it is torn down. This is in reverse order
+ // of the threads' appearance in the BrowserThread::ID enumeration.
+ // Note that you will not receive such a call for BrowserThread::UI,
+ // since it is the main thread of the application.
+ virtual void PreStopThread(BrowserThread::ID identifier) = 0;
+ virtual void PostStopThread(BrowserThread::ID identifier) = 0;
+
+ // Called as the very last part of shutdown, after threads have been
+ // stopped and destroyed.
+ virtual void PostDestroyThreads() = 0;
+
private:
DISALLOW_COPY_AND_ASSIGN(BrowserMainParts);
};
diff --git a/content/public/browser/browser_shutdown.h b/content/public/browser/browser_shutdown.h
new file mode 100644
index 0000000..72a4ce0
--- /dev/null
+++ b/content/public/browser/browser_shutdown.h
@@ -0,0 +1,32 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_PUBLIC_BROWSER_BROWSER_SHUTDOWN_H_
+#define CONTENT_PUBLIC_BROWSER_BROWSER_SHUTDOWN_H_
+#pragma once
+
+#include "content/common/content_export.h"
+
+namespace content {
+
+// This can be used for as-fast-as-possible shutdown, in cases where
+// time for shutdown is limited and we just need to write out as much
+// data as possible before our time runs out.
+//
+// This causes the shutdown sequence embodied by
+// BrowserMainParts::PostMainMessageLoopRun through
+// BrowserMainParts::PostDestroyThreads to occur, i.e. we pretend the
+// message loop finished, all threads are stopped in sequence and
+// PreStopThread/PostStopThread gets called, and at least,
+// PostDestroyThreads is called.
+//
+// As this violates the normal order of shutdown, likely leaving the
+// process in a bad state, the last thing this function does is
+// terminate the process (right after calling
+// BrowserMainParts::PostDestroyThreads).
+CONTENT_EXPORT void ImmediateShutdownAndExitProcess();
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_BROWSER_BROWSER_SHUTDOWN_H_
diff --git a/content/public/browser/browser_thread.h b/content/public/browser/browser_thread.h
index 66dc009..4478558 100644
--- a/content/public/browser/browser_thread.h
+++ b/content/public/browser/browser_thread.h
@@ -6,11 +6,21 @@
#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"
+#include "content/public/browser/browser_thread_delegate.h"
+
+// TODO(joi): Remove these in a follow-up change and IWYU in files
+// that were getting them directly or indirectly from here.
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/message_loop.h"
+#include "base/message_loop_proxy.h"
+#include "base/synchronization/lock.h"
+#include "base/threading/thread.h"
#if defined(UNIT_TEST)
#include "base/logging.h"
@@ -18,12 +28,12 @@
namespace base {
class MessageLoopProxy;
+class Thread;
}
namespace content {
class BrowserThreadImpl;
-class DeprecatedBrowserThread;
///////////////////////////////////////////////////////////////////////////////
// BrowserThread
@@ -47,7 +57,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 +180,33 @@ 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);
+
+ // Sets the delegate for the specified BrowserThread.
+ //
+ // Only one delegate may be registered at a time. Delegates may be
+ // unregistered by providing a NULL pointer.
+ //
+ // If the caller unregisters a delegate before CleanUp has been
+ // called, it must perform its own locking to ensure the delegate is
+ // not deleted while unregistering.
+ static void SetDelegate(ID identifier, BrowserThreadDelegate* delegate);
+
// 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 +250,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();
-
- // Common initialization code for the constructors.
- void Initialize();
-
- // Constructors are only available through this subclass.
- friend class content::BrowserThreadImpl;
+ friend class 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
diff --git a/content/public/browser/browser_thread_delegate.h b/content/public/browser/browser_thread_delegate.h
new file mode 100644
index 0000000..ae9fc7b
--- /dev/null
+++ b/content/public/browser/browser_thread_delegate.h
@@ -0,0 +1,32 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_DELEGATE_H_
+#define CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_DELEGATE_H_
+#pragma once
+
+namespace content {
+
+// A class with this type may be registered via
+// BrowserThread::SetDelegate.
+//
+// If registered as such, it will receive an Init() call right before
+// the BrowserThread in question starts its message loop (and right
+// after the BrowserThread has done its own initialization), and a
+// CleanUp call right after the message loop ends (and before the
+// BrowserThread has done its own clean-up).
+class BrowserThreadDelegate {
+ public:
+ virtual ~BrowserThreadDelegate() {}
+
+ // Called just prior to starting the message loop.
+ virtual void Init() = 0;
+
+ // Called just after the message loop ends.
+ virtual void CleanUp() = 0;
+};
+
+} // namespace content
+
+#endif // CONTENT_PUBLIC_BROWSER_BROWSER_THREAD_DELEGATE_H_