summaryrefslogtreecommitdiffstats
path: root/chromecast
diff options
context:
space:
mode:
authorgunsch <gunsch@chromium.org>2014-08-29 18:47:04 -0700
committerCommit bot <commit-bot@chromium.org>2014-08-30 01:51:09 +0000
commit611228ee885eb89f54703e24fd547b4832d189d8 (patch)
tree962fdfa8f71411f1364dd3315d9e6454e17a80b9 /chromecast
parent439a05cd87fe1f880b896bd7b154454299355899 (diff)
downloadchromium_src-611228ee885eb89f54703e24fd547b4832d189d8.zip
chromium_src-611228ee885eb89f54703e24fd547b4832d189d8.tar.gz
chromium_src-611228ee885eb89f54703e24fd547b4832d189d8.tar.bz2
Chromecast: adds CastBrowserProcess to manage browser process entities.
These are not appropriate for CastBrowserMainParts to manage. R=lcwu@chromium.org,byungchul@chromium.org BUG=336640 Review URL: https://codereview.chromium.org/521753002 Cr-Commit-Position: refs/heads/master@{#292752}
Diffstat (limited to 'chromecast')
-rw-r--r--chromecast/chromecast.gyp2
-rw-r--r--chromecast/shell/browser/cast_browser_main_parts.cc27
-rw-r--r--chromecast/shell/browser/cast_browser_main_parts.h21
-rw-r--r--chromecast/shell/browser/cast_browser_process.cc60
-rw-r--r--chromecast/shell/browser/cast_browser_process.h63
-rw-r--r--chromecast/shell/browser/cast_content_browser_client.cc9
-rw-r--r--chromecast/shell/browser/cast_content_browser_client.h3
7 files changed, 147 insertions, 38 deletions
diff --git a/chromecast/chromecast.gyp b/chromecast/chromecast.gyp
index 6824379..3c744d6 100644
--- a/chromecast/chromecast.gyp
+++ b/chromecast/chromecast.gyp
@@ -195,6 +195,8 @@
'shell/browser/cast_browser_context.h',
'shell/browser/cast_browser_main_parts.cc',
'shell/browser/cast_browser_main_parts.h',
+ 'shell/browser/cast_browser_process.cc',
+ 'shell/browser/cast_browser_process.h',
'shell/browser/cast_content_browser_client.cc',
'shell/browser/cast_content_browser_client.h',
'shell/browser/cast_http_user_agent_settings.cc',
diff --git a/chromecast/shell/browser/cast_browser_main_parts.cc b/chromecast/shell/browser/cast_browser_main_parts.cc
index 8b98918d..3f7b358 100644
--- a/chromecast/shell/browser/cast_browser_main_parts.cc
+++ b/chromecast/shell/browser/cast_browser_main_parts.cc
@@ -12,6 +12,7 @@
#include "chromecast/net/network_change_notifier_factory_cast.h"
#include "chromecast/service/cast_service.h"
#include "chromecast/shell/browser/cast_browser_context.h"
+#include "chromecast/shell/browser/cast_browser_process.h"
#include "chromecast/shell/browser/devtools/remote_debugging_server.h"
#include "chromecast/shell/browser/url_request_context_factory.h"
#include "chromecast/shell/browser/webui/webui_cast.h"
@@ -49,6 +50,7 @@ CastBrowserMainParts::CastBrowserMainParts(
const content::MainFunctionParams& parameters,
URLRequestContextFactory* url_request_context_factory)
: BrowserMainParts(),
+ cast_browser_process_(new CastBrowserProcess()),
url_request_context_factory_(url_request_context_factory) {
CommandLine* command_line = CommandLine::ForCurrentProcess();
AddDefaultCommandLineSwitches(command_line);
@@ -74,16 +76,19 @@ int CastBrowserMainParts::PreCreateThreads() {
void CastBrowserMainParts::PreMainMessageLoopRun() {
url_request_context_factory_->InitializeOnUIThread();
- browser_context_.reset(new CastBrowserContext(url_request_context_factory_));
- metrics_service_client_.reset(metrics::CastMetricsServiceClient::Create(
- ChromecastConfig::GetInstance()->pref_service(),
- browser_context_->GetRequestContext()));
- dev_tools_.reset(new RemoteDebuggingServer());
+ cast_browser_process_->SetBrowserContext(
+ new CastBrowserContext(url_request_context_factory_));
+ cast_browser_process_->SetMetricsServiceClient(
+ metrics::CastMetricsServiceClient::Create(
+ ChromecastConfig::GetInstance()->pref_service(),
+ cast_browser_process_->browser_context()->GetRequestContext()));
+ cast_browser_process_->SetRemoteDebuggingServer(new RemoteDebuggingServer());
InitializeWebUI();
- cast_service_.reset(CastService::Create(browser_context_.get()));
- cast_service_->Start();
+ cast_browser_process_->SetCastService(
+ CastService::Create(cast_browser_process_->browser_context()));
+ cast_browser_process_->cast_service()->Start();
}
bool CastBrowserMainParts::MainMessageLoopRun(int* result_code) {
@@ -92,12 +97,8 @@ bool CastBrowserMainParts::MainMessageLoopRun(int* result_code) {
}
void CastBrowserMainParts::PostMainMessageLoopRun() {
- cast_service_->Stop();
-
- cast_service_.reset();
- dev_tools_.reset();
- metrics_service_client_.reset();
- browser_context_.reset();
+ cast_browser_process_->cast_service()->Stop();
+ cast_browser_process_.reset();
}
} // namespace shell
diff --git a/chromecast/shell/browser/cast_browser_main_parts.h b/chromecast/shell/browser/cast_browser_main_parts.h
index 6be05ad..e620eb2 100644
--- a/chromecast/shell/browser/cast_browser_main_parts.h
+++ b/chromecast/shell/browser/cast_browser_main_parts.h
@@ -15,17 +15,8 @@ struct MainFunctionParams;
}
namespace chromecast {
-
-class CastService;
-
-namespace metrics {
-class CastMetricsServiceClient;
-} // namespace metrics
-
namespace shell {
-
-class CastBrowserContext;
-class RemoteDebuggingServer;
+class CastBrowserProcess;
class URLRequestContextFactory;
class CastBrowserMainParts : public content::BrowserMainParts {
@@ -43,15 +34,9 @@ class CastBrowserMainParts : public content::BrowserMainParts {
virtual bool MainMessageLoopRun(int* result_code) OVERRIDE;
virtual void PostMainMessageLoopRun() OVERRIDE;
- CastBrowserContext* browser_context() {
- return browser_context_.get();
- }
-
private:
- scoped_ptr<CastBrowserContext> browser_context_;
- scoped_ptr<CastService> cast_service_;
- scoped_ptr<metrics::CastMetricsServiceClient> metrics_service_client_;
- scoped_ptr<RemoteDebuggingServer> dev_tools_;
+ scoped_ptr<CastBrowserProcess> cast_browser_process_;
+
URLRequestContextFactory* const url_request_context_factory_;
DISALLOW_COPY_AND_ASSIGN(CastBrowserMainParts);
diff --git a/chromecast/shell/browser/cast_browser_process.cc b/chromecast/shell/browser/cast_browser_process.cc
new file mode 100644
index 0000000..70802aa
--- /dev/null
+++ b/chromecast/shell/browser/cast_browser_process.cc
@@ -0,0 +1,60 @@
+// Copyright 2014 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.
+
+#include "chromecast/shell/browser/cast_browser_process.h"
+
+#include "base/logging.h"
+#include "chromecast/metrics/cast_metrics_service_client.h"
+#include "chromecast/service/cast_service.h"
+#include "chromecast/shell/browser/cast_browser_context.h"
+#include "chromecast/shell/browser/devtools/remote_debugging_server.h"
+
+namespace chromecast {
+namespace shell {
+
+namespace {
+CastBrowserProcess* g_instance = NULL;
+} // namespace
+
+// static
+CastBrowserProcess* CastBrowserProcess::GetInstance() {
+ DCHECK(g_instance);
+ return g_instance;
+}
+
+CastBrowserProcess::CastBrowserProcess() {
+ DCHECK(!g_instance);
+ g_instance = this;
+}
+
+CastBrowserProcess::~CastBrowserProcess() {
+ DCHECK_EQ(g_instance, this);
+ g_instance = NULL;
+}
+
+void CastBrowserProcess::SetBrowserContext(
+ CastBrowserContext* browser_context) {
+ DCHECK(!browser_context_);
+ browser_context_.reset(browser_context);
+}
+
+void CastBrowserProcess::SetCastService(CastService* cast_service) {
+ DCHECK(!cast_service_);
+ cast_service_.reset(cast_service);
+}
+
+void CastBrowserProcess::SetRemoteDebuggingServer(
+ RemoteDebuggingServer* remote_debugging_server) {
+ DCHECK(!remote_debugging_server_);
+ remote_debugging_server_.reset(remote_debugging_server);
+}
+
+void CastBrowserProcess::SetMetricsServiceClient(
+ metrics::CastMetricsServiceClient* metrics_service_client) {
+ DCHECK(!metrics_service_client_);
+ metrics_service_client_.reset(metrics_service_client);
+}
+
+} // namespace shell
+} // namespace chromecast
diff --git a/chromecast/shell/browser/cast_browser_process.h b/chromecast/shell/browser/cast_browser_process.h
new file mode 100644
index 0000000..65830c2a
--- /dev/null
+++ b/chromecast/shell/browser/cast_browser_process.h
@@ -0,0 +1,63 @@
+// Copyright 2014 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 CHROMECAST_SHELL_BROWSER_CAST_BROWSER_PROCESS_H_
+#define CHROMECAST_SHELL_BROWSER_CAST_BROWSER_PROCESS_H_
+
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+
+namespace breakpad {
+class CrashDumpManager;
+} // namespace breakpad
+
+namespace chromecast {
+class CastService;
+class WebCryptoServer;
+
+namespace metrics {
+class CastMetricsHelper;
+class CastMetricsServiceClient;
+} // namespace metrics
+
+namespace shell {
+class CastBrowserContext;
+class RemoteDebuggingServer;
+
+class CastBrowserProcess {
+ public:
+ // Gets the global instance of CastBrowserProcess. Does not create lazily and
+ // assumes the instance already exists.
+ static CastBrowserProcess* GetInstance();
+
+ CastBrowserProcess();
+ virtual ~CastBrowserProcess();
+
+ void SetBrowserContext(CastBrowserContext* browser_context);
+ void SetCastService(CastService* cast_service);
+ void SetRemoteDebuggingServer(RemoteDebuggingServer* remote_debugging_server);
+ void SetMetricsServiceClient(
+ metrics::CastMetricsServiceClient* metrics_service_client);
+
+ CastBrowserContext* browser_context() const { return browser_context_.get(); }
+ CastService* cast_service() const { return cast_service_.get(); }
+ metrics::CastMetricsServiceClient* metrics_service_client() const {
+ return metrics_service_client_.get();
+ }
+
+ private:
+ scoped_ptr<CastBrowserContext> browser_context_;
+ scoped_ptr<metrics::CastMetricsServiceClient> metrics_service_client_;
+ scoped_ptr<RemoteDebuggingServer> remote_debugging_server_;
+
+ // Note: CastService must be destroyed before others.
+ scoped_ptr<CastService> cast_service_;
+
+ DISALLOW_COPY_AND_ASSIGN(CastBrowserProcess);
+};
+
+} // namespace shell
+} // namespace chromecast
+
+#endif // CHROMECAST_SHELL_BROWSER_CAST_BROWSER_PROCESS_H_
diff --git a/chromecast/shell/browser/cast_content_browser_client.cc b/chromecast/shell/browser/cast_content_browser_client.cc
index 12600e1..1c70429 100644
--- a/chromecast/shell/browser/cast_content_browser_client.cc
+++ b/chromecast/shell/browser/cast_content_browser_client.cc
@@ -7,6 +7,7 @@
#include "base/command_line.h"
#include "chromecast/shell/browser/cast_browser_context.h"
#include "chromecast/shell/browser/cast_browser_main_parts.h"
+#include "chromecast/shell/browser/cast_browser_process.h"
#include "chromecast/shell/browser/geolocation/cast_access_token_store.h"
#include "chromecast/shell/browser/url_request_context_factory.h"
#include "content/public/browser/certificate_request_result_type.h"
@@ -28,9 +29,8 @@ CastContentBrowserClient::~CastContentBrowserClient() {
content::BrowserMainParts* CastContentBrowserClient::CreateBrowserMainParts(
const content::MainFunctionParams& parameters) {
- shell_browser_main_parts_ =
- new CastBrowserMainParts(parameters, url_request_context_factory_.get());
- return shell_browser_main_parts_;
+ return new CastBrowserMainParts(parameters,
+ url_request_context_factory_.get());
}
void CastContentBrowserClient::RenderProcessWillLaunch(
@@ -81,7 +81,8 @@ void CastContentBrowserClient::AppendExtraCommandLineSwitches(
}
content::AccessTokenStore* CastContentBrowserClient::CreateAccessTokenStore() {
- return new CastAccessTokenStore(shell_browser_main_parts_->browser_context());
+ return new CastAccessTokenStore(
+ CastBrowserProcess::GetInstance()->browser_context());
}
void CastContentBrowserClient::OverrideWebkitPrefs(
diff --git a/chromecast/shell/browser/cast_content_browser_client.h b/chromecast/shell/browser/cast_content_browser_client.h
index 98504e3..2356eef 100644
--- a/chromecast/shell/browser/cast_content_browser_client.h
+++ b/chromecast/shell/browser/cast_content_browser_client.h
@@ -71,9 +71,6 @@ class CastContentBrowserClient: public content::ContentBrowserClient {
std::vector<content::FileDescriptorInfo>* mappings) OVERRIDE;
private:
- // Note: BrowserMainLoop holds ownership of CastBrowserMainParts after it is
- // created.
- CastBrowserMainParts* shell_browser_main_parts_;
scoped_ptr<URLRequestContextFactory> url_request_context_factory_;
DISALLOW_COPY_AND_ASSIGN(CastContentBrowserClient);