Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chromecast / browser / cast_browser_process.cc
blob077ee1df3f846c361614385fa8e23724abf67898
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromecast/browser/cast_browser_process.h"
7 #include "base/logging.h"
8 #include "base/prefs/pref_service.h"
9 #include "chromecast/base/metrics/cast_metrics_helper.h"
10 #include "chromecast/browser/cast_browser_context.h"
11 #include "chromecast/browser/cast_resource_dispatcher_host_delegate.h"
12 #include "chromecast/browser/devtools/remote_debugging_server.h"
13 #include "chromecast/browser/metrics/cast_metrics_service_client.h"
14 #include "chromecast/net/connectivity_checker.h"
15 #include "chromecast/service/cast_service.h"
17 #if defined(OS_ANDROID)
18 #include "components/crash/content/browser/crash_dump_manager_android.h"
19 #endif // defined(OS_ANDROID)
21 #if defined(USE_AURA)
22 #include "chromecast/graphics/cast_screen.h"
23 #endif // defined(USE_AURA)
25 namespace chromecast {
26 namespace shell {
28 namespace {
29 CastBrowserProcess* g_instance = NULL;
30 } // namespace
32 // static
33 CastBrowserProcess* CastBrowserProcess::GetInstance() {
34 DCHECK(g_instance);
35 return g_instance;
38 CastBrowserProcess::CastBrowserProcess()
39 : cast_content_browser_client_(nullptr),
40 net_log_(nullptr) {
41 DCHECK(!g_instance);
42 g_instance = this;
45 CastBrowserProcess::~CastBrowserProcess() {
46 DCHECK_EQ(g_instance, this);
47 if (pref_service_)
48 pref_service_->CommitPendingWrite();
49 g_instance = NULL;
52 void CastBrowserProcess::SetBrowserContext(
53 scoped_ptr<CastBrowserContext> browser_context) {
54 DCHECK(!browser_context_);
55 browser_context_.swap(browser_context);
58 void CastBrowserProcess::SetCastContentBrowserClient(
59 CastContentBrowserClient* cast_content_browser_client) {
60 DCHECK(!cast_content_browser_client_);
61 cast_content_browser_client_ = cast_content_browser_client;
64 void CastBrowserProcess::SetCastService(scoped_ptr<CastService> cast_service) {
65 DCHECK(!cast_service_);
66 cast_service_.swap(cast_service);
69 #if defined(USE_AURA)
70 void CastBrowserProcess::SetCastScreen(scoped_ptr<CastScreen> cast_screen) {
71 DCHECK(!cast_screen_);
72 cast_screen_ = cast_screen.Pass();
74 #endif // defined(USE_AURA)
76 void CastBrowserProcess::SetMetricsHelper(
77 scoped_ptr<metrics::CastMetricsHelper> metrics_helper) {
78 DCHECK(!metrics_helper_);
79 metrics_helper_.swap(metrics_helper);
82 void CastBrowserProcess::SetMetricsServiceClient(
83 scoped_ptr<metrics::CastMetricsServiceClient> metrics_service_client) {
84 DCHECK(!metrics_service_client_);
85 metrics_service_client_.swap(metrics_service_client);
88 void CastBrowserProcess::SetPrefService(scoped_ptr<PrefService> pref_service) {
89 DCHECK(!pref_service_);
90 pref_service_.swap(pref_service);
93 void CastBrowserProcess::SetRemoteDebuggingServer(
94 scoped_ptr<RemoteDebuggingServer> remote_debugging_server) {
95 DCHECK(!remote_debugging_server_);
96 remote_debugging_server_.swap(remote_debugging_server);
99 void CastBrowserProcess::SetResourceDispatcherHostDelegate(
100 scoped_ptr<CastResourceDispatcherHostDelegate> delegate) {
101 DCHECK(!resource_dispatcher_host_delegate_);
102 resource_dispatcher_host_delegate_.swap(delegate);
105 #if defined(OS_ANDROID)
106 void CastBrowserProcess::SetCrashDumpManager(
107 scoped_ptr<breakpad::CrashDumpManager> crash_dump_manager) {
108 DCHECK(!crash_dump_manager_);
109 crash_dump_manager_.swap(crash_dump_manager);
111 #endif // defined(OS_ANDROID)
113 void CastBrowserProcess::SetConnectivityChecker(
114 scoped_refptr<ConnectivityChecker> connectivity_checker) {
115 DCHECK(!connectivity_checker_);
116 connectivity_checker_.swap(connectivity_checker);
119 void CastBrowserProcess::SetNetLog(net::NetLog* net_log) {
120 DCHECK(!net_log_);
121 net_log_ = net_log;
124 } // namespace shell
125 } // namespace chromecast