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

Unified Diff: content/browser/browser_main_runner.cc

Issue 9190018: Support sharing of ContentMain and BrowserMain code with embedded use cases. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 8 years, 11 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
Index: content/browser/browser_main_runner.cc
===================================================================
--- content/browser/browser_main_runner.cc (revision 117304)
+++ content/browser/browser_main_runner.cc (working copy)
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "content/browser/browser_main.h"
+#include "content/public/browser/browser_main_runner.h"
#include "base/allocator/allocator_shim.h"
#include "base/base_switches.h"
@@ -24,19 +24,46 @@
bool g_exited_main_message_loop = false;
-} // namespace
+class BrowserMainRunnerImpl : public content::BrowserMainRunner {
jam 2012/01/31 21:11:29 ditto for inliing these methods
+ public:
+ BrowserMainRunnerImpl();
+ ~BrowserMainRunnerImpl();
-namespace content {
+ virtual int Initialize(const content::MainFunctionParams& parameters)
+ OVERRIDE;
+ virtual int Run() OVERRIDE;
+ virtual void Shutdown() OVERRIDE;
-bool ExitedMainMessageLoop() {
- return g_exited_main_message_loop;
+ protected:
+ // True if the runner has been initialized.
+ bool is_initialized_;
+
+ // True if the runner has been shut down.
+ bool is_shutdown_;
+
+ scoped_ptr<NotificationServiceImpl> notification_service_;
+ scoped_ptr<content::BrowserMainLoop> main_loop_;
+#if defined(OS_WIN)
+ scoped_ptr<base::win::ScopedCOMInitializer> com_initializer_;
+#endif
+ scoped_ptr<base::StatisticsRecorder> statistics_;
+
+ DISALLOW_COPY_AND_ASSIGN(BrowserMainRunnerImpl);
+};
+
+BrowserMainRunnerImpl::BrowserMainRunnerImpl()
+ : is_initialized_(false),
+ is_shutdown_(false) {
}
-} // namespace content
+BrowserMainRunnerImpl::~BrowserMainRunnerImpl() {
+ if (is_initialized_ && !is_shutdown_)
+ Shutdown();
+}
-// Main routine for running as the Browser process.
-int BrowserMain(const content::MainFunctionParams& parameters) {
- TRACE_EVENT_BEGIN_ETW("BrowserMain", 0, "");
+int BrowserMainRunnerImpl::Initialize(
+ const content::MainFunctionParams& parameters) {
+ is_initialized_ = true;
// ChildProcess:: is a misnomer unless you consider context. Use
// of --wait-for-debugger only makes sense when Chrome itself is a
@@ -44,19 +71,18 @@
if (parameters.command_line.HasSwitch(switches::kWaitForDebugger))
ChildProcess::WaitForDebugger("Browser");
- NotificationServiceImpl main_notification_service;
+ notification_service_.reset(new NotificationServiceImpl);
- scoped_ptr<content::BrowserMainLoop> main_loop(
- new content::BrowserMainLoop(parameters));
+ main_loop_.reset(new content::BrowserMainLoop(parameters));
- main_loop->Init();
+ main_loop_->Init();
- main_loop->EarlyInitialization();
+ main_loop_->EarlyInitialization();
// Must happen before we try to use a message loop or display any UI.
- main_loop->InitializeToolkit();
+ main_loop_->InitializeToolkit();
- main_loop->MainMessageLoopStart();
+ main_loop_->MainMessageLoopStart();
// WARNING: If we get a WM_ENDSESSION, objects created on the stack here
// are NOT deleted. If you need something to run during WM_ENDSESSION add it
@@ -92,14 +118,54 @@
base::allocator::SetupSubprocessAllocator();
#endif
- base::win::ScopedCOMInitializer com_initializer;
+ com_initializer_.reset(new base::win::ScopedCOMInitializer);
#endif // OS_WIN
- base::StatisticsRecorder statistics;
+ statistics_.reset(new base::StatisticsRecorder);
- main_loop->RunMainMessageLoopParts(&g_exited_main_message_loop);
+ main_loop_->CreateThreads();
- TRACE_EVENT_END_ETW("BrowserMain", 0, 0);
+ // Return -1 to indicate no early termination.
+ return -1;
+}
- return main_loop->GetResultCode();
+int BrowserMainRunnerImpl::Run() {
+ DCHECK(is_initialized_);
+ DCHECK(!is_shutdown_);
+ main_loop_->RunMainMessageLoopParts();
+ return main_loop_->GetResultCode();
}
+
+void BrowserMainRunnerImpl::Shutdown() {
+ DCHECK(is_initialized_);
+ DCHECK(!is_shutdown_);
+ g_exited_main_message_loop = true;
+ main_loop_->ShutdownThreadsAndCleanUp();
+
+ statistics_.reset(NULL);
+
+#if defined(OS_WIN)
+ com_initializer_.reset(NULL);
+#endif
+
+ main_loop_.reset(NULL);
+
+ notification_service_.reset(NULL);
+
+ is_shutdown_ = true;
+}
+
+} // namespace
+
+namespace content {
+
+// static
+BrowserMainRunner* BrowserMainRunner::Create() {
+ return new BrowserMainRunnerImpl();
+}
+
+bool ExitedMainMessageLoop() {
+ return g_exited_main_message_loop;
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698