Commit 611228ee authored by gunsch's avatar gunsch Committed by Commit bot

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}
parent 439a05cd
......@@ -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',
......
......@@ -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
......
......@@ -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);
......
// 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
// 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_
......@@ -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(
......
......@@ -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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment