gunsch | 611228e | 2014-08-30 01:47:04 | [diff] [blame] | 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. |
| 4 | |
gunsch | f44ffcb | 2014-10-13 23:01:45 | [diff] [blame] | 5 | #include "chromecast/browser/cast_browser_process.h" |
gunsch | 611228e | 2014-08-30 01:47:04 | [diff] [blame] | 6 | |
| 7 | #include "base/logging.h" |
byungchul | ba825256 | 2014-12-05 21:01:27 | [diff] [blame] | 8 | #include "base/prefs/pref_service.h" |
avi | 82d54ced | 2015-12-22 22:01:49 | [diff] [blame^] | 9 | #include "build/build_config.h" |
gunsch | 7d57bdc3 | 2014-10-20 22:44:43 | [diff] [blame] | 10 | #include "chromecast/base/metrics/cast_metrics_helper.h" |
gunsch | f44ffcb | 2014-10-13 23:01:45 | [diff] [blame] | 11 | #include "chromecast/browser/cast_browser_context.h" |
derekjchow | 30d4c22 | 2015-02-20 20:30:26 | [diff] [blame] | 12 | #include "chromecast/browser/cast_resource_dispatcher_host_delegate.h" |
gunsch | f44ffcb | 2014-10-13 23:01:45 | [diff] [blame] | 13 | #include "chromecast/browser/devtools/remote_debugging_server.h" |
| 14 | #include "chromecast/browser/metrics/cast_metrics_service_client.h" |
derekjchow | 30d4c22 | 2015-02-20 20:30:26 | [diff] [blame] | 15 | #include "chromecast/net/connectivity_checker.h" |
gunsch | 68c183a | 2015-09-08 18:12:31 | [diff] [blame] | 16 | #include "chromecast/service/cast_service.h" |
gunsch | 611228e | 2014-08-30 01:47:04 | [diff] [blame] | 17 | |
gunsch | 168c44ce | 2014-10-09 04:37:06 | [diff] [blame] | 18 | #if defined(OS_ANDROID) |
sdefresne | 8ba0b88c | 2015-09-18 10:33:13 | [diff] [blame] | 19 | #include "components/crash/content/browser/crash_dump_manager_android.h" |
gunsch | 168c44ce | 2014-10-09 04:37:06 | [diff] [blame] | 20 | #endif // defined(OS_ANDROID) |
| 21 | |
esum | 03d2f82 | 2015-07-08 23:43:59 | [diff] [blame] | 22 | #if defined(USE_AURA) |
| 23 | #include "chromecast/graphics/cast_screen.h" |
| 24 | #endif // defined(USE_AURA) |
| 25 | |
gunsch | 611228e | 2014-08-30 01:47:04 | [diff] [blame] | 26 | namespace chromecast { |
| 27 | namespace shell { |
| 28 | |
| 29 | namespace { |
| 30 | CastBrowserProcess* g_instance = NULL; |
| 31 | } // namespace |
| 32 | |
| 33 | // static |
| 34 | CastBrowserProcess* CastBrowserProcess::GetInstance() { |
| 35 | DCHECK(g_instance); |
| 36 | return g_instance; |
| 37 | } |
| 38 | |
derekjchow | 4a2ab5d | 2015-07-09 18:39:53 | [diff] [blame] | 39 | CastBrowserProcess::CastBrowserProcess() |
gunsch | 24edba48 | 2015-08-20 00:09:06 | [diff] [blame] | 40 | : cast_content_browser_client_(nullptr), |
| 41 | net_log_(nullptr) { |
gunsch | 611228e | 2014-08-30 01:47:04 | [diff] [blame] | 42 | DCHECK(!g_instance); |
| 43 | g_instance = this; |
| 44 | } |
| 45 | |
| 46 | CastBrowserProcess::~CastBrowserProcess() { |
| 47 | DCHECK_EQ(g_instance, this); |
byungchul | ba825256 | 2014-12-05 21:01:27 | [diff] [blame] | 48 | if (pref_service_) |
| 49 | pref_service_->CommitPendingWrite(); |
gunsch | 611228e | 2014-08-30 01:47:04 | [diff] [blame] | 50 | g_instance = NULL; |
| 51 | } |
| 52 | |
| 53 | void CastBrowserProcess::SetBrowserContext( |
byungchul | ba825256 | 2014-12-05 21:01:27 | [diff] [blame] | 54 | scoped_ptr<CastBrowserContext> browser_context) { |
gunsch | 611228e | 2014-08-30 01:47:04 | [diff] [blame] | 55 | DCHECK(!browser_context_); |
byungchul | ba825256 | 2014-12-05 21:01:27 | [diff] [blame] | 56 | browser_context_.swap(browser_context); |
gunsch | 611228e | 2014-08-30 01:47:04 | [diff] [blame] | 57 | } |
| 58 | |
gunsch | 24edba48 | 2015-08-20 00:09:06 | [diff] [blame] | 59 | void CastBrowserProcess::SetCastContentBrowserClient( |
| 60 | CastContentBrowserClient* cast_content_browser_client) { |
| 61 | DCHECK(!cast_content_browser_client_); |
| 62 | cast_content_browser_client_ = cast_content_browser_client; |
| 63 | } |
| 64 | |
byungchul | ba825256 | 2014-12-05 21:01:27 | [diff] [blame] | 65 | void CastBrowserProcess::SetCastService(scoped_ptr<CastService> cast_service) { |
gunsch | 611228e | 2014-08-30 01:47:04 | [diff] [blame] | 66 | DCHECK(!cast_service_); |
byungchul | ba825256 | 2014-12-05 21:01:27 | [diff] [blame] | 67 | cast_service_.swap(cast_service); |
gunsch | 611228e | 2014-08-30 01:47:04 | [diff] [blame] | 68 | } |
| 69 | |
esum | 03d2f82 | 2015-07-08 23:43:59 | [diff] [blame] | 70 | #if defined(USE_AURA) |
| 71 | void CastBrowserProcess::SetCastScreen(scoped_ptr<CastScreen> cast_screen) { |
| 72 | DCHECK(!cast_screen_); |
| 73 | cast_screen_ = cast_screen.Pass(); |
| 74 | } |
| 75 | #endif // defined(USE_AURA) |
| 76 | |
gunsch | 7d57bdc3 | 2014-10-20 22:44:43 | [diff] [blame] | 77 | void CastBrowserProcess::SetMetricsHelper( |
byungchul | ba825256 | 2014-12-05 21:01:27 | [diff] [blame] | 78 | scoped_ptr<metrics::CastMetricsHelper> metrics_helper) { |
gunsch | 7d57bdc3 | 2014-10-20 22:44:43 | [diff] [blame] | 79 | DCHECK(!metrics_helper_); |
byungchul | ba825256 | 2014-12-05 21:01:27 | [diff] [blame] | 80 | metrics_helper_.swap(metrics_helper); |
gunsch | 7d57bdc3 | 2014-10-20 22:44:43 | [diff] [blame] | 81 | } |
| 82 | |
gunsch | 611228e | 2014-08-30 01:47:04 | [diff] [blame] | 83 | void CastBrowserProcess::SetMetricsServiceClient( |
byungchul | ba825256 | 2014-12-05 21:01:27 | [diff] [blame] | 84 | scoped_ptr<metrics::CastMetricsServiceClient> metrics_service_client) { |
gunsch | 611228e | 2014-08-30 01:47:04 | [diff] [blame] | 85 | DCHECK(!metrics_service_client_); |
byungchul | ba825256 | 2014-12-05 21:01:27 | [diff] [blame] | 86 | metrics_service_client_.swap(metrics_service_client); |
| 87 | } |
| 88 | |
| 89 | void CastBrowserProcess::SetPrefService(scoped_ptr<PrefService> pref_service) { |
| 90 | DCHECK(!pref_service_); |
| 91 | pref_service_.swap(pref_service); |
| 92 | } |
| 93 | |
| 94 | void CastBrowserProcess::SetRemoteDebuggingServer( |
| 95 | scoped_ptr<RemoteDebuggingServer> remote_debugging_server) { |
| 96 | DCHECK(!remote_debugging_server_); |
| 97 | remote_debugging_server_.swap(remote_debugging_server); |
gunsch | 611228e | 2014-08-30 01:47:04 | [diff] [blame] | 98 | } |
| 99 | |
derekjchow | 30d4c22 | 2015-02-20 20:30:26 | [diff] [blame] | 100 | void CastBrowserProcess::SetResourceDispatcherHostDelegate( |
| 101 | scoped_ptr<CastResourceDispatcherHostDelegate> delegate) { |
| 102 | DCHECK(!resource_dispatcher_host_delegate_); |
| 103 | resource_dispatcher_host_delegate_.swap(delegate); |
| 104 | } |
| 105 | |
gunsch | 168c44ce | 2014-10-09 04:37:06 | [diff] [blame] | 106 | #if defined(OS_ANDROID) |
| 107 | void CastBrowserProcess::SetCrashDumpManager( |
byungchul | ba825256 | 2014-12-05 21:01:27 | [diff] [blame] | 108 | scoped_ptr<breakpad::CrashDumpManager> crash_dump_manager) { |
gunsch | 168c44ce | 2014-10-09 04:37:06 | [diff] [blame] | 109 | DCHECK(!crash_dump_manager_); |
byungchul | ba825256 | 2014-12-05 21:01:27 | [diff] [blame] | 110 | crash_dump_manager_.swap(crash_dump_manager); |
gunsch | 168c44ce | 2014-10-09 04:37:06 | [diff] [blame] | 111 | } |
| 112 | #endif // defined(OS_ANDROID) |
| 113 | |
derekjchow | 30d4c22 | 2015-02-20 20:30:26 | [diff] [blame] | 114 | void CastBrowserProcess::SetConnectivityChecker( |
| 115 | scoped_refptr<ConnectivityChecker> connectivity_checker) { |
| 116 | DCHECK(!connectivity_checker_); |
| 117 | connectivity_checker_.swap(connectivity_checker); |
| 118 | } |
| 119 | |
derekjchow | 4a2ab5d | 2015-07-09 18:39:53 | [diff] [blame] | 120 | void CastBrowserProcess::SetNetLog(net::NetLog* net_log) { |
| 121 | DCHECK(!net_log_); |
| 122 | net_log_ = net_log; |
| 123 | } |
| 124 | |
gunsch | 611228e | 2014-08-30 01:47:04 | [diff] [blame] | 125 | } // namespace shell |
| 126 | } // namespace chromecast |