summaryrefslogtreecommitdiffstats
path: root/content
diff options
context:
space:
mode:
Diffstat (limited to 'content')
-rw-r--r--content/browser/browser_main_loop.cc50
-rw-r--r--content/browser/browser_main_loop.h14
-rw-r--r--content/browser/mock_content_browser_client.cc6
-rw-r--r--content/browser/mock_content_browser_client.h5
-rw-r--r--content/public/browser/browser_main_parts.h15
-rw-r--r--content/public/browser/content_browser_client.h5
-rw-r--r--content/shell/shell_content_browser_client.cc7
-rw-r--r--content/shell/shell_content_browser_client.h5
8 files changed, 43 insertions, 64 deletions
diff --git a/content/browser/browser_main_loop.cc b/content/browser/browser_main_loop.cc
index 2059d2a..dd93e58 100644
--- a/content/browser/browser_main_loop.cc
+++ b/content/browser/browser_main_loop.cc
@@ -158,26 +158,21 @@ BrowserMainLoop::BrowserMainLoop(const content::MainFunctionParams& parameters)
}
BrowserMainLoop::~BrowserMainLoop() {
- // Destroy added parts in reverse order.
- for (int i = static_cast<int>(parts_list_.size())-1; i >= 0; --i)
- delete parts_list_[i];
- parts_list_.clear();
-
#if defined(OS_WIN)
OleUninitialize();
#endif
}
void BrowserMainLoop::Init() {
- GetContentClient()->browser()->CreateBrowserMainParts(
- parameters_, &parts_list_);
+ parts_.reset(
+ GetContentClient()->browser()->CreateBrowserMainParts(parameters_));
}
// BrowserMainLoop stages ==================================================
void BrowserMainLoop::EarlyInitialization() {
- for (size_t i = 0; i < parts_list_.size(); ++i)
- parts_list_[i]->PreEarlyInitialization();
+ if (parts_.get())
+ parts_->PreEarlyInitialization();
#if defined(OS_WIN)
net::EnsureWinsockInit();
@@ -223,13 +218,13 @@ void BrowserMainLoop::EarlyInitialization() {
if (parsed_command_line_.HasSwitch(switches::kEnableTcpFastOpen))
net::set_tcp_fastopen_enabled(true);
- for (size_t i = 0; i < parts_list_.size(); ++i)
- parts_list_[i]->PostEarlyInitialization();
+ if (parts_.get())
+ parts_->PostEarlyInitialization();
}
void BrowserMainLoop::MainMessageLoopStart() {
- for (size_t i = 0; i < parts_list_.size(); ++i)
- parts_list_[i]->PreMainMessageLoopStart();
+ if (parts_.get())
+ parts_->PreMainMessageLoopStart();
#if defined(OS_WIN)
// If we're running tests (ui_task is non-null), then the ResourceBundle
@@ -260,31 +255,24 @@ void BrowserMainLoop::MainMessageLoopStart() {
system_message_window_.reset(new SystemMessageWindowWin);
#endif
- for (size_t i = 0; i < parts_list_.size(); ++i)
- parts_list_[i]->PostMainMessageLoopStart();
+ if (parts_.get())
+ parts_->PostMainMessageLoopStart();
}
void BrowserMainLoop::RunMainMessageLoopParts(
bool* completed_main_message_loop) {
- for (size_t i = 0; i < parts_list_.size(); ++i)
- parts_list_[i]->PreMainMessageLoopRun();
+ if (parts_.get())
+ parts_->PreMainMessageLoopRun();
TRACE_EVENT_BEGIN_ETW("BrowserMain:MESSAGE_LOOP", 0, "");
// If the UI thread blocks, the whole UI is unresponsive.
// Do not allow disk IO from the UI thread.
base::ThreadRestrictions::SetIOAllowed(false);
- // Iterate through each of the parts. If any of them ran the main
- // message loop then they should return |true|. Otherwise
- // BrowserMainLoop::MainMessageLoopRun loop will be run.
bool ran_main_loop = false;
- for (size_t i = 0; i < parts_list_.size(); ++i) {
- int result_code = result_code_;
- if (parts_list_[i]->MainMessageLoopRun(&result_code)) {
- ran_main_loop = true;
- result_code_ = result_code;
- }
- }
+ if (parts_.get())
+ ran_main_loop = parts_->MainMessageLoopRun(&result_code_);
+
if (!ran_main_loop)
MainMessageLoopRun();
@@ -293,8 +281,8 @@ void BrowserMainLoop::RunMainMessageLoopParts(
if (completed_main_message_loop)
*completed_main_message_loop = true;
- for (size_t i = 0; i < parts_list_.size(); ++i)
- parts_list_[i]->PostMainMessageLoopRun();
+ if (parts_.get())
+ parts_->PostMainMessageLoopRun();
}
void BrowserMainLoop::InitializeMainThread() {
@@ -343,8 +331,8 @@ void BrowserMainLoop::InitializeToolkit() {
LOG_GETLASTERROR(FATAL);
#endif
- for (size_t i = 0; i < parts_list_.size(); ++i)
- parts_list_[i]->ToolkitInitialized();
+ if (parts_.get())
+ parts_->ToolkitInitialized();
}
void BrowserMainLoop::MainMessageLoopRun() {
diff --git a/content/browser/browser_main_loop.h b/content/browser/browser_main_loop.h
index 0abe7e1..d02d578 100644
--- a/content/browser/browser_main_loop.h
+++ b/content/browser/browser_main_loop.h
@@ -6,8 +6,6 @@
#define CONTENT_BROWSER_BROWSER_MAIN_LOOP_H_
#pragma once
-#include <vector>
-
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
@@ -55,11 +53,6 @@ class BrowserMainLoop {
const CommandLine& parsed_command_line_;
int result_code_;
- // Vector of BrowserMainParts set by CreateBrowserMainParts ------------------
- // The BrowserParts fucntions for each part are called in the order added.
- // They are released (destroyed) in the reverse order.
- std::vector<BrowserMainParts*> parts_list_;
-
// Members initialized in |MainMessageLoopStart()| ---------------------------
scoped_ptr<MessageLoop> main_message_loop_;
scoped_ptr<base::SystemMonitor> system_monitor_;
@@ -68,6 +61,13 @@ class BrowserMainLoop {
#if defined(OS_WIN)
scoped_ptr<SystemMessageWindowWin> system_message_window_;
#endif
+
+ // Destroy parts_ before main_message_loop_ (required) and before other
+ // classes constructed in content (but after main_thread_).
+ scoped_ptr<BrowserMainParts> parts_;
+
+ // Members initialized in |InitializeMainThread()| ---------------------------
+ // This must get destroyed before other threads that are created in parts_.
scoped_ptr<BrowserThreadImpl> main_thread_;
DISALLOW_COPY_AND_ASSIGN(BrowserMainLoop);
diff --git a/content/browser/mock_content_browser_client.cc b/content/browser/mock_content_browser_client.cc
index b2c2dd6..5b1c08b 100644
--- a/content/browser/mock_content_browser_client.cc
+++ b/content/browser/mock_content_browser_client.cc
@@ -23,9 +23,9 @@ MockContentBrowserClient::MockContentBrowserClient() {
MockContentBrowserClient::~MockContentBrowserClient() {
}
-void MockContentBrowserClient::CreateBrowserMainParts(
- const content::MainFunctionParams& parameters,
- std::vector<BrowserMainParts*>* parts_list) {
+BrowserMainParts* MockContentBrowserClient::CreateBrowserMainParts(
+ const content::MainFunctionParams& parameters) {
+ return NULL;
}
RenderWidgetHostView* MockContentBrowserClient::CreateViewForWidget(
diff --git a/content/browser/mock_content_browser_client.h b/content/browser/mock_content_browser_client.h
index 56a7be2..2b61f71 100644
--- a/content/browser/mock_content_browser_client.h
+++ b/content/browser/mock_content_browser_client.h
@@ -21,9 +21,8 @@ class MockContentBrowserClient : public ContentBrowserClient {
MockContentBrowserClient();
virtual ~MockContentBrowserClient();
- virtual void CreateBrowserMainParts(
- const content::MainFunctionParams& parameters,
- std::vector<BrowserMainParts*>* parts_list) OVERRIDE;
+ virtual BrowserMainParts* CreateBrowserMainParts(
+ const content::MainFunctionParams& parameters) OVERRIDE;
virtual RenderWidgetHostView* CreateViewForWidget(
RenderWidgetHost* widget) OVERRIDE;
virtual TabContentsView* CreateTabContentsView(
diff --git a/content/public/browser/browser_main_parts.h b/content/public/browser/browser_main_parts.h
index 0bbaa83..860541c 100644
--- a/content/public/browser/browser_main_parts.h
+++ b/content/public/browser/browser_main_parts.h
@@ -15,9 +15,8 @@ namespace content {
// Each stage is represented by a single BrowserMainParts method, called from
// the corresponding method in |BrowserMainLoop| (e.g., EarlyInitialization())
// which does the following:
-// - calls a method (e.g., "PreEarlyInitialization()") for each member of
-// |parts_|. Parts will implement platform or tookit specific code for that
-// stage.
+// - calls a method (e.g., "PreEarlyInitialization()") which implements
+// platform / tookit specific code for that stage.
// - calls various methods for things common to all platforms (for that stage).
// - calls a method (e.g., "PostEarlyInitialization()") for platform-specific
// code to be called after the common code.
@@ -49,9 +48,6 @@ namespace content {
// existing chunk which makes it longer than one or two lines, please move
// the code out into a separate method.)
//
-// There can be any number of "Parts". These should be constructed in
-// ContentBrowserClient::CreateBrowserMainParts. Each stage will be called
-// for each part in the order it was added. Destruction is in the inverse order.
class CONTENT_EXPORT BrowserMainParts {
public:
BrowserMainParts() {}
@@ -63,17 +59,16 @@ class CONTENT_EXPORT BrowserMainParts {
virtual void PreMainMessageLoopStart() = 0;
+ virtual void PostMainMessageLoopStart() = 0;
+
// Allows an embedder to do any extra toolkit initialization.
virtual void ToolkitInitialized() = 0;
- virtual void PostMainMessageLoopStart() = 0;
-
virtual void PreMainMessageLoopRun() = 0;
// Returns true if the message loop was run, false otherwise.
+ // If this returns false, the default implementation will be run.
// May set |result_code|, which will be returned by |BrowserMain()|.
- // If no BrowserMainParts implementations return true, the default
- // implementation will be run.
virtual bool MainMessageLoopRun(int* result_code) = 0;
virtual void PostMainMessageLoopRun() = 0;
diff --git a/content/public/browser/content_browser_client.h b/content/public/browser/content_browser_client.h
index 2a2a9f7..7d5438e 100644
--- a/content/public/browser/content_browser_client.h
+++ b/content/public/browser/content_browser_client.h
@@ -85,9 +85,8 @@ class ContentBrowserClient {
// Allows the embedder to set any number of custom BrowserMainParts
// implementations for the browser startup code. See comments in
// browser_main_parts.h.
- virtual void CreateBrowserMainParts(
- const content::MainFunctionParams& parameters,
- std::vector<BrowserMainParts*>* parts_list) = 0;
+ virtual BrowserMainParts* CreateBrowserMainParts(
+ const content::MainFunctionParams& parameters) = 0;
// Platform-specific creator. Use this to construct new RenderWidgetHostViews
// rather than using RenderWidgetHostViewWin & friends.
diff --git a/content/shell/shell_content_browser_client.cc b/content/shell/shell_content_browser_client.cc
index ec25de5..394af26 100644
--- a/content/shell/shell_content_browser_client.cc
+++ b/content/shell/shell_content_browser_client.cc
@@ -28,10 +28,9 @@ ShellContentBrowserClient::ShellContentBrowserClient()
ShellContentBrowserClient::~ShellContentBrowserClient() {
}
-void ShellContentBrowserClient::CreateBrowserMainParts(
- const content::MainFunctionParams& parameters,
- std::vector<BrowserMainParts*>* parts_list) {
- parts_list->push_back(new ShellBrowserMainParts(parameters));
+BrowserMainParts* ShellContentBrowserClient::CreateBrowserMainParts(
+ const content::MainFunctionParams& parameters) {
+ return new ShellBrowserMainParts(parameters);
}
RenderWidgetHostView* ShellContentBrowserClient::CreateViewForWidget(
diff --git a/content/shell/shell_content_browser_client.h b/content/shell/shell_content_browser_client.h
index 1231ae0..4d0ac37 100644
--- a/content/shell/shell_content_browser_client.h
+++ b/content/shell/shell_content_browser_client.h
@@ -33,9 +33,8 @@ class ShellContentBrowserClient : public ContentBrowserClient
shell_browser_main_parts_ = parts;
}
- virtual void CreateBrowserMainParts(
- const content::MainFunctionParams& parameters,
- std::vector<BrowserMainParts*>* parts_list) OVERRIDE;
+ virtual BrowserMainParts* CreateBrowserMainParts(
+ const content::MainFunctionParams& parameters) OVERRIDE;
virtual RenderWidgetHostView* CreateViewForWidget(
RenderWidgetHost* widget) OVERRIDE;
virtual TabContentsView* CreateTabContentsView(