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