OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/browser_process_impl.h" | 5 #include "chrome/browser/browser_process_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/debug/alias.h" | 14 #include "base/debug/alias.h" |
15 #include "base/debug/leak_annotations.h" | 15 #include "base/debug/leak_annotations.h" |
| 16 #include "base/files/file_path.h" |
16 #include "base/path_service.h" | 17 #include "base/path_service.h" |
17 #include "base/prefs/json_pref_store.h" | 18 #include "base/prefs/json_pref_store.h" |
18 #include "base/prefs/pref_registry_simple.h" | 19 #include "base/prefs/pref_registry_simple.h" |
19 #include "base/prefs/pref_service.h" | 20 #include "base/prefs/pref_service.h" |
20 #include "base/synchronization/waitable_event.h" | 21 #include "base/synchronization/waitable_event.h" |
21 #include "base/threading/thread.h" | 22 #include "base/threading/thread.h" |
22 #include "base/threading/thread_restrictions.h" | 23 #include "base/threading/thread_restrictions.h" |
23 #include "base/time/default_tick_clock.h" | 24 #include "base/time/default_tick_clock.h" |
24 #include "chrome/browser/apps/chrome_apps_client.h" | 25 #include "chrome/browser/apps/chrome_apps_client.h" |
25 #include "chrome/browser/background/background_mode_manager.h" | 26 #include "chrome/browser/background/background_mode_manager.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 #include "chrome/browser/web_resource/promo_resource_service.h" | 70 #include "chrome/browser/web_resource/promo_resource_service.h" |
70 #include "chrome/common/chrome_constants.h" | 71 #include "chrome/common/chrome_constants.h" |
71 #include "chrome/common/chrome_paths.h" | 72 #include "chrome/common/chrome_paths.h" |
72 #include "chrome/common/chrome_switches.h" | 73 #include "chrome/common/chrome_switches.h" |
73 #include "chrome/common/extensions/chrome_extensions_client.h" | 74 #include "chrome/common/extensions/chrome_extensions_client.h" |
74 #include "chrome/common/pref_names.h" | 75 #include "chrome/common/pref_names.h" |
75 #include "chrome/common/switch_utils.h" | 76 #include "chrome/common/switch_utils.h" |
76 #include "chrome/common/url_constants.h" | 77 #include "chrome/common/url_constants.h" |
77 #include "chrome/installer/util/google_update_constants.h" | 78 #include "chrome/installer/util/google_update_constants.h" |
78 #include "chrome/installer/util/google_update_settings.h" | 79 #include "chrome/installer/util/google_update_settings.h" |
| 80 #include "components/gcm_driver/gcm_driver.h" |
79 #include "components/network_time/network_time_tracker.h" | 81 #include "components/network_time/network_time_tracker.h" |
80 #include "components/policy/core/common/policy_service.h" | 82 #include "components/policy/core/common/policy_service.h" |
81 #include "components/signin/core/common/profile_management_switches.h" | 83 #include "components/signin/core/common/profile_management_switches.h" |
82 #include "components/translate/core/browser/translate_download_manager.h" | 84 #include "components/translate/core/browser/translate_download_manager.h" |
83 #include "content/public/browser/browser_thread.h" | 85 #include "content/public/browser/browser_thread.h" |
84 #include "content/public/browser/child_process_security_policy.h" | 86 #include "content/public/browser/child_process_security_policy.h" |
85 #include "content/public/browser/notification_details.h" | 87 #include "content/public/browser/notification_details.h" |
86 #include "content/public/browser/plugin_service.h" | 88 #include "content/public/browser/plugin_service.h" |
87 #include "content/public/browser/render_process_host.h" | 89 #include "content/public/browser/render_process_host.h" |
88 #include "content/public/browser/resource_dispatcher_host.h" | 90 #include "content/public/browser/resource_dispatcher_host.h" |
89 #include "content/public/browser/service_worker_context.h" | 91 #include "content/public/browser/service_worker_context.h" |
90 #include "content/public/browser/storage_partition.h" | 92 #include "content/public/browser/storage_partition.h" |
91 #include "extensions/common/constants.h" | 93 #include "extensions/common/constants.h" |
92 #include "extensions/common/extension_l10n_util.h" | 94 #include "extensions/common/extension_l10n_util.h" |
| 95 #include "google_apis/gaia/identity_provider.h" |
93 #include "net/socket/client_socket_pool_manager.h" | 96 #include "net/socket/client_socket_pool_manager.h" |
94 #include "net/url_request/url_request_context_getter.h" | 97 #include "net/url_request/url_request_context_getter.h" |
95 #include "ui/base/l10n/l10n_util.h" | 98 #include "ui/base/l10n/l10n_util.h" |
96 #include "ui/message_center/message_center.h" | 99 #include "ui/message_center/message_center.h" |
97 | 100 |
98 #if defined(ENABLE_CONFIGURATION_POLICY) | 101 #if defined(ENABLE_CONFIGURATION_POLICY) |
99 #include "components/policy/core/browser/browser_policy_connector.h" | 102 #include "components/policy/core/browser/browser_policy_connector.h" |
100 #else | 103 #else |
101 #include "components/policy/core/common/policy_service_stub.h" | 104 #include "components/policy/core/common/policy_service_stub.h" |
102 #endif // defined(ENABLE_CONFIGURATION_POLICY) | 105 #endif // defined(ENABLE_CONFIGURATION_POLICY) |
(...skipping 15 matching lines...) Expand all Loading... |
118 #endif | 121 #endif |
119 | 122 |
120 #if defined(ENABLE_PLUGIN_INSTALLATION) | 123 #if defined(ENABLE_PLUGIN_INSTALLATION) |
121 #include "chrome/browser/plugins/plugins_resource_service.h" | 124 #include "chrome/browser/plugins/plugins_resource_service.h" |
122 #endif | 125 #endif |
123 | 126 |
124 #if defined(ENABLE_WEBRTC) | 127 #if defined(ENABLE_WEBRTC) |
125 #include "chrome/browser/media/webrtc_log_uploader.h" | 128 #include "chrome/browser/media/webrtc_log_uploader.h" |
126 #endif | 129 #endif |
127 | 130 |
| 131 #if defined(OS_CHROMEOS) |
| 132 #include "chrome/browser/chromeos/settings/device_identity_provider.h" |
| 133 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h
" |
| 134 #elif !defined(OS_ANDROID) |
| 135 #include "google_apis/gaia/dummy_identity_provider.h" |
| 136 #endif |
| 137 |
| 138 #if defined(OS_ANDROID) |
| 139 #include "components/gcm_driver/gcm_driver_android.h" |
| 140 #else |
| 141 #include "chrome/browser/services/gcm/gcm_desktop_utils.h" |
| 142 #include "components/gcm_driver/gcm_client_factory.h" |
| 143 #endif |
| 144 |
128 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) | 145 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
129 // How often to check if the persistent instance of Chrome needs to restart | 146 // How often to check if the persistent instance of Chrome needs to restart |
130 // to install an update. | 147 // to install an update. |
131 static const int kUpdateCheckIntervalHours = 6; | 148 static const int kUpdateCheckIntervalHours = 6; |
132 #endif | 149 #endif |
133 | 150 |
134 #if defined(USE_X11) || defined(OS_WIN) | 151 #if defined(USE_X11) || defined(OS_WIN) |
135 // How long to wait for the File thread to complete during EndSession, on Linux | 152 // How long to wait for the File thread to complete during EndSession, on Linux |
136 // and Windows. We have a timeout here because we're unable to run the UI | 153 // and Windows. We have a timeout here because we're unable to run the UI |
137 // messageloop and there's some deadlock risk. Our only option is to exit | 154 // messageloop and there's some deadlock risk. Our only option is to exit |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 | 272 |
256 message_center::MessageCenter::Shutdown(); | 273 message_center::MessageCenter::Shutdown(); |
257 | 274 |
258 #if defined(ENABLE_CONFIGURATION_POLICY) | 275 #if defined(ENABLE_CONFIGURATION_POLICY) |
259 // The policy providers managed by |browser_policy_connector_| need to shut | 276 // The policy providers managed by |browser_policy_connector_| need to shut |
260 // down while the IO and FILE threads are still alive. | 277 // down while the IO and FILE threads are still alive. |
261 if (browser_policy_connector_) | 278 if (browser_policy_connector_) |
262 browser_policy_connector_->Shutdown(); | 279 browser_policy_connector_->Shutdown(); |
263 #endif | 280 #endif |
264 | 281 |
| 282 // The |gcm_driver_| must shut down while the IO thread is still alive. |
| 283 if (gcm_driver_) |
| 284 gcm_driver_->Shutdown(); |
| 285 |
265 // Stop the watchdog thread before stopping other threads. | 286 // Stop the watchdog thread before stopping other threads. |
266 watchdog_thread_.reset(); | 287 watchdog_thread_.reset(); |
267 | 288 |
268 #if defined(USE_AURA) | 289 #if defined(USE_AURA) |
269 // Delete aura after the metrics service has been deleted as it accesses | 290 // Delete aura after the metrics service has been deleted as it accesses |
270 // monitor information. | 291 // monitor information. |
271 aura::Env::DeleteInstance(); | 292 aura::Env::DeleteInstance(); |
272 #endif | 293 #endif |
273 | 294 |
274 platform_part()->StartTearDown(); | 295 platform_part()->StartTearDown(); |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 | 656 |
636 network_time::NetworkTimeTracker* BrowserProcessImpl::network_time_tracker() { | 657 network_time::NetworkTimeTracker* BrowserProcessImpl::network_time_tracker() { |
637 if (!network_time_tracker_) { | 658 if (!network_time_tracker_) { |
638 network_time_tracker_.reset(new network_time::NetworkTimeTracker( | 659 network_time_tracker_.reset(new network_time::NetworkTimeTracker( |
639 scoped_ptr<base::TickClock>(new base::DefaultTickClock()), | 660 scoped_ptr<base::TickClock>(new base::DefaultTickClock()), |
640 local_state())); | 661 local_state())); |
641 } | 662 } |
642 return network_time_tracker_.get(); | 663 return network_time_tracker_.get(); |
643 } | 664 } |
644 | 665 |
| 666 gcm::GCMDriver* BrowserProcessImpl::gcm_driver() { |
| 667 DCHECK(CalledOnValidThread()); |
| 668 if (!gcm_driver_) |
| 669 CreateGCMDriver(); |
| 670 return gcm_driver_.get(); |
| 671 } |
| 672 |
645 // static | 673 // static |
646 void BrowserProcessImpl::RegisterPrefs(PrefRegistrySimple* registry) { | 674 void BrowserProcessImpl::RegisterPrefs(PrefRegistrySimple* registry) { |
647 registry->RegisterBooleanPref(prefs::kDefaultBrowserSettingEnabled, | 675 registry->RegisterBooleanPref(prefs::kDefaultBrowserSettingEnabled, |
648 false); | 676 false); |
649 // This policy needs to be defined before the net subsystem is initialized, | 677 // This policy needs to be defined before the net subsystem is initialized, |
650 // so we do it here. | 678 // so we do it here. |
651 registry->RegisterIntegerPref(prefs::kMaxConnectionsPerProxy, | 679 registry->RegisterIntegerPref(prefs::kMaxConnectionsPerProxy, |
652 net::kDefaultMaxSocketsPerProxyServer); | 680 net::kDefaultMaxSocketsPerProxyServer); |
653 | 681 |
654 registry->RegisterBooleanPref(prefs::kAllowCrossOriginAuthPrompt, false); | 682 registry->RegisterBooleanPref(prefs::kAllowCrossOriginAuthPrompt, false); |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 DCHECK(safe_browsing_service_.get() == NULL); | 1007 DCHECK(safe_browsing_service_.get() == NULL); |
980 // Set this flag to true so that we don't retry indefinitely to | 1008 // Set this flag to true so that we don't retry indefinitely to |
981 // create the service class if there was an error. | 1009 // create the service class if there was an error. |
982 created_safe_browsing_service_ = true; | 1010 created_safe_browsing_service_ = true; |
983 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING) | 1011 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING) |
984 safe_browsing_service_ = SafeBrowsingService::CreateSafeBrowsingService(); | 1012 safe_browsing_service_ = SafeBrowsingService::CreateSafeBrowsingService(); |
985 safe_browsing_service_->Initialize(); | 1013 safe_browsing_service_->Initialize(); |
986 #endif | 1014 #endif |
987 } | 1015 } |
988 | 1016 |
| 1017 void BrowserProcessImpl::CreateGCMDriver() { |
| 1018 DCHECK(!gcm_driver_); |
| 1019 |
| 1020 #if defined(OS_ANDROID) |
| 1021 gcm_driver_.reset(new gcm::GCMDriverAndroid); |
| 1022 #else |
| 1023 base::FilePath store_path; |
| 1024 CHECK(PathService::Get(chrome::DIR_GLOBAL_GCM_STORE, &store_path)); |
| 1025 gcm_driver_ = gcm::CreateGCMDriverDesktop( |
| 1026 make_scoped_ptr(new gcm::GCMClientFactory), |
| 1027 #if defined(OS_CHROMEOS) |
| 1028 scoped_ptr<IdentityProvider>(new chromeos::DeviceIdentityProvider( |
| 1029 chromeos::DeviceOAuth2TokenServiceFactory::Get())), |
| 1030 #else |
| 1031 scoped_ptr<IdentityProvider>(new DummyIdentityProvider), |
| 1032 #endif // defined(OS_CHROMEOS) |
| 1033 store_path, |
| 1034 system_request_context()); |
| 1035 #endif // defined(OS_ANDROID) |
| 1036 } |
| 1037 |
989 MetricsServicesManager* BrowserProcessImpl::GetMetricsServicesManager() { | 1038 MetricsServicesManager* BrowserProcessImpl::GetMetricsServicesManager() { |
990 DCHECK(CalledOnValidThread()); | 1039 DCHECK(CalledOnValidThread()); |
991 if (!metrics_services_manager_) | 1040 if (!metrics_services_manager_) |
992 metrics_services_manager_.reset(new MetricsServicesManager(local_state())); | 1041 metrics_services_manager_.reset(new MetricsServicesManager(local_state())); |
993 return metrics_services_manager_.get(); | 1042 return metrics_services_manager_.get(); |
994 } | 1043 } |
995 | 1044 |
996 void BrowserProcessImpl::ApplyDefaultBrowserPolicy() { | 1045 void BrowserProcessImpl::ApplyDefaultBrowserPolicy() { |
997 if (local_state()->GetBoolean(prefs::kDefaultBrowserSettingEnabled)) { | 1046 if (local_state()->GetBoolean(prefs::kDefaultBrowserSettingEnabled)) { |
998 scoped_refptr<ShellIntegration::DefaultWebClientWorker> | 1047 scoped_refptr<ShellIntegration::DefaultWebClientWorker> |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1066 } | 1115 } |
1067 | 1116 |
1068 void BrowserProcessImpl::OnAutoupdateTimer() { | 1117 void BrowserProcessImpl::OnAutoupdateTimer() { |
1069 if (CanAutorestartForUpdate()) { | 1118 if (CanAutorestartForUpdate()) { |
1070 DLOG(WARNING) << "Detected update. Restarting browser."; | 1119 DLOG(WARNING) << "Detected update. Restarting browser."; |
1071 RestartBackgroundInstance(); | 1120 RestartBackgroundInstance(); |
1072 } | 1121 } |
1073 } | 1122 } |
1074 | 1123 |
1075 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) | 1124 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
OLD | NEW |