Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(253)

Side by Side Diff: chrome/browser/browser_process_impl.cc

Issue 301973009: Add browser-global GCMDriver (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
22 #include "base/threading/sequenced_worker_pool.h"
21 #include "base/threading/thread.h" 23 #include "base/threading/thread.h"
22 #include "base/threading/thread_restrictions.h" 24 #include "base/threading/thread_restrictions.h"
23 #include "base/time/default_tick_clock.h" 25 #include "base/time/default_tick_clock.h"
24 #include "chrome/browser/apps/chrome_apps_client.h" 26 #include "chrome/browser/apps/chrome_apps_client.h"
25 #include "chrome/browser/background/background_mode_manager.h" 27 #include "chrome/browser/background/background_mode_manager.h"
26 #include "chrome/browser/chrome_browser_main.h" 28 #include "chrome/browser/chrome_browser_main.h"
27 #include "chrome/browser/chrome_content_browser_client.h" 29 #include "chrome/browser/chrome_content_browser_client.h"
28 #include "chrome/browser/chrome_notification_types.h" 30 #include "chrome/browser/chrome_notification_types.h"
29 #include "chrome/browser/component_updater/component_updater_configurator.h" 31 #include "chrome/browser/component_updater/component_updater_configurator.h"
30 #include "chrome/browser/component_updater/component_updater_service.h" 32 #include "chrome/browser/component_updater/component_updater_service.h"
(...skipping 25 matching lines...) Expand all
56 #include "chrome/browser/plugins/plugin_finder.h" 58 #include "chrome/browser/plugins/plugin_finder.h"
57 #include "chrome/browser/prefs/browser_prefs.h" 59 #include "chrome/browser/prefs/browser_prefs.h"
58 #include "chrome/browser/prefs/chrome_pref_service_factory.h" 60 #include "chrome/browser/prefs/chrome_pref_service_factory.h"
59 #include "chrome/browser/prerender/prerender_tracker.h" 61 #include "chrome/browser/prerender/prerender_tracker.h"
60 #include "chrome/browser/printing/background_printing_manager.h" 62 #include "chrome/browser/printing/background_printing_manager.h"
61 #include "chrome/browser/printing/print_job_manager.h" 63 #include "chrome/browser/printing/print_job_manager.h"
62 #include "chrome/browser/printing/print_preview_dialog_controller.h" 64 #include "chrome/browser/printing/print_preview_dialog_controller.h"
63 #include "chrome/browser/profiles/profile_manager.h" 65 #include "chrome/browser/profiles/profile_manager.h"
64 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate. h" 66 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate. h"
65 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 67 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
68 #include "chrome/browser/services/gcm/gcm_utils.h"
66 #include "chrome/browser/shell_integration.h" 69 #include "chrome/browser/shell_integration.h"
67 #include "chrome/browser/status_icons/status_tray.h" 70 #include "chrome/browser/status_icons/status_tray.h"
68 #include "chrome/browser/ui/browser_dialogs.h" 71 #include "chrome/browser/ui/browser_dialogs.h"
69 #include "chrome/browser/ui/browser_finder.h" 72 #include "chrome/browser/ui/browser_finder.h"
70 #include "chrome/browser/web_resource/promo_resource_service.h" 73 #include "chrome/browser/web_resource/promo_resource_service.h"
71 #include "chrome/common/chrome_constants.h" 74 #include "chrome/common/chrome_constants.h"
72 #include "chrome/common/chrome_paths.h" 75 #include "chrome/common/chrome_paths.h"
73 #include "chrome/common/chrome_switches.h" 76 #include "chrome/common/chrome_switches.h"
74 #include "chrome/common/extensions/chrome_extensions_client.h" 77 #include "chrome/common/extensions/chrome_extensions_client.h"
75 #include "chrome/common/pref_names.h" 78 #include "chrome/common/pref_names.h"
76 #include "chrome/common/switch_utils.h" 79 #include "chrome/common/switch_utils.h"
77 #include "chrome/common/url_constants.h" 80 #include "chrome/common/url_constants.h"
78 #include "chrome/installer/util/google_update_constants.h" 81 #include "chrome/installer/util/google_update_constants.h"
79 #include "chrome/installer/util/google_update_settings.h" 82 #include "chrome/installer/util/google_update_settings.h"
83 #include "components/gcm_driver/gcm_client_factory.h"
84 #include "components/gcm_driver/gcm_driver.h"
80 #include "components/policy/core/common/policy_service.h" 85 #include "components/policy/core/common/policy_service.h"
81 #include "components/signin/core/common/profile_management_switches.h" 86 #include "components/signin/core/common/profile_management_switches.h"
82 #include "components/translate/core/browser/translate_download_manager.h" 87 #include "components/translate/core/browser/translate_download_manager.h"
83 #include "content/public/browser/browser_thread.h" 88 #include "content/public/browser/browser_thread.h"
84 #include "content/public/browser/child_process_security_policy.h" 89 #include "content/public/browser/child_process_security_policy.h"
85 #include "content/public/browser/notification_details.h" 90 #include "content/public/browser/notification_details.h"
86 #include "content/public/browser/plugin_service.h" 91 #include "content/public/browser/plugin_service.h"
87 #include "content/public/browser/render_process_host.h" 92 #include "content/public/browser/render_process_host.h"
88 #include "content/public/browser/resource_dispatcher_host.h" 93 #include "content/public/browser/resource_dispatcher_host.h"
89 #include "content/public/browser/service_worker_context.h" 94 #include "content/public/browser/service_worker_context.h"
90 #include "content/public/browser/storage_partition.h" 95 #include "content/public/browser/storage_partition.h"
91 #include "extensions/common/constants.h" 96 #include "extensions/common/constants.h"
92 #include "extensions/common/extension_l10n_util.h" 97 #include "extensions/common/extension_l10n_util.h"
98 #include "google_apis/gaia/identity_provider.h"
93 #include "net/socket/client_socket_pool_manager.h" 99 #include "net/socket/client_socket_pool_manager.h"
94 #include "net/url_request/url_request_context_getter.h" 100 #include "net/url_request/url_request_context_getter.h"
95 #include "ui/base/l10n/l10n_util.h" 101 #include "ui/base/l10n/l10n_util.h"
96 #include "ui/message_center/message_center.h" 102 #include "ui/message_center/message_center.h"
97 103
98 #if defined(ENABLE_CONFIGURATION_POLICY) 104 #if defined(ENABLE_CONFIGURATION_POLICY)
99 #include "components/policy/core/browser/browser_policy_connector.h" 105 #include "components/policy/core/browser/browser_policy_connector.h"
100 #else 106 #else
101 #include "components/policy/core/common/policy_service_stub.h" 107 #include "components/policy/core/common/policy_service_stub.h"
102 #endif // defined(ENABLE_CONFIGURATION_POLICY) 108 #endif // defined(ENABLE_CONFIGURATION_POLICY)
(...skipping 15 matching lines...) Expand all
118 #endif 124 #endif
119 125
120 #if defined(ENABLE_PLUGIN_INSTALLATION) 126 #if defined(ENABLE_PLUGIN_INSTALLATION)
121 #include "chrome/browser/plugins/plugins_resource_service.h" 127 #include "chrome/browser/plugins/plugins_resource_service.h"
122 #endif 128 #endif
123 129
124 #if defined(ENABLE_WEBRTC) 130 #if defined(ENABLE_WEBRTC)
125 #include "chrome/browser/media/webrtc_log_uploader.h" 131 #include "chrome/browser/media/webrtc_log_uploader.h"
126 #endif 132 #endif
127 133
134 #if defined(OS_CHROMEOS)
135 #include "chrome/browser/chromeos/settings/device_identity_provider.h"
136 #include "chrome/browser/chromeos/settings/device_oauth2_token_service_factory.h "
137 #else
138 #include "google_apis/gaia/dummy_identity_provider.h"
139 #endif
140
128 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) 141 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
129 // How often to check if the persistent instance of Chrome needs to restart 142 // How often to check if the persistent instance of Chrome needs to restart
130 // to install an update. 143 // to install an update.
131 static const int kUpdateCheckIntervalHours = 6; 144 static const int kUpdateCheckIntervalHours = 6;
132 #endif 145 #endif
133 146
134 #if defined(USE_X11) || defined(OS_WIN) 147 #if defined(USE_X11) || defined(OS_WIN)
135 // How long to wait for the File thread to complete during EndSession, on Linux 148 // 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 149 // 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 150 // 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
255 268
256 message_center::MessageCenter::Shutdown(); 269 message_center::MessageCenter::Shutdown();
257 270
258 #if defined(ENABLE_CONFIGURATION_POLICY) 271 #if defined(ENABLE_CONFIGURATION_POLICY)
259 // The policy providers managed by |browser_policy_connector_| need to shut 272 // The policy providers managed by |browser_policy_connector_| need to shut
260 // down while the IO and FILE threads are still alive. 273 // down while the IO and FILE threads are still alive.
261 if (browser_policy_connector_) 274 if (browser_policy_connector_)
262 browser_policy_connector_->Shutdown(); 275 browser_policy_connector_->Shutdown();
263 #endif 276 #endif
264 277
278 // The |gcm_driver_| must shut down while the IO thread is still alive.
279 if (gcm_driver_)
280 gcm_driver_->Shutdown();
281
265 // Stop the watchdog thread before stopping other threads. 282 // Stop the watchdog thread before stopping other threads.
266 watchdog_thread_.reset(); 283 watchdog_thread_.reset();
267 284
268 #if defined(USE_AURA) 285 #if defined(USE_AURA)
269 // Delete aura after the metrics service has been deleted as it accesses 286 // Delete aura after the metrics service has been deleted as it accesses
270 // monitor information. 287 // monitor information.
271 aura::Env::DeleteInstance(); 288 aura::Env::DeleteInstance();
272 #endif 289 #endif
273 290
274 platform_part()->StartTearDown(); 291 platform_part()->StartTearDown();
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 652
636 NetworkTimeTracker* BrowserProcessImpl::network_time_tracker() { 653 NetworkTimeTracker* BrowserProcessImpl::network_time_tracker() {
637 if (!network_time_tracker_) { 654 if (!network_time_tracker_) {
638 network_time_tracker_.reset(new NetworkTimeTracker( 655 network_time_tracker_.reset(new NetworkTimeTracker(
639 scoped_ptr<base::TickClock>(new base::DefaultTickClock()), 656 scoped_ptr<base::TickClock>(new base::DefaultTickClock()),
640 local_state())); 657 local_state()));
641 } 658 }
642 return network_time_tracker_.get(); 659 return network_time_tracker_.get();
643 } 660 }
644 661
662 gcm::GCMDriver* BrowserProcessImpl::gcm_driver() {
663 DCHECK(CalledOnValidThread());
664 if (!gcm_driver_)
665 CreateGCMDriver();
666 return gcm_driver_.get();
667 }
668
645 // static 669 // static
646 void BrowserProcessImpl::RegisterPrefs(PrefRegistrySimple* registry) { 670 void BrowserProcessImpl::RegisterPrefs(PrefRegistrySimple* registry) {
647 registry->RegisterBooleanPref(prefs::kDefaultBrowserSettingEnabled, 671 registry->RegisterBooleanPref(prefs::kDefaultBrowserSettingEnabled,
648 false); 672 false);
649 // This policy needs to be defined before the net subsystem is initialized, 673 // This policy needs to be defined before the net subsystem is initialized,
650 // so we do it here. 674 // so we do it here.
651 registry->RegisterIntegerPref(prefs::kMaxConnectionsPerProxy, 675 registry->RegisterIntegerPref(prefs::kMaxConnectionsPerProxy,
652 net::kDefaultMaxSocketsPerProxyServer); 676 net::kDefaultMaxSocketsPerProxyServer);
653 677
654 registry->RegisterBooleanPref(prefs::kAllowCrossOriginAuthPrompt, false); 678 registry->RegisterBooleanPref(prefs::kAllowCrossOriginAuthPrompt, false);
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
979 DCHECK(safe_browsing_service_.get() == NULL); 1003 DCHECK(safe_browsing_service_.get() == NULL);
980 // Set this flag to true so that we don't retry indefinitely to 1004 // Set this flag to true so that we don't retry indefinitely to
981 // create the service class if there was an error. 1005 // create the service class if there was an error.
982 created_safe_browsing_service_ = true; 1006 created_safe_browsing_service_ = true;
983 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING) 1007 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING)
984 safe_browsing_service_ = SafeBrowsingService::CreateSafeBrowsingService(); 1008 safe_browsing_service_ = SafeBrowsingService::CreateSafeBrowsingService();
985 safe_browsing_service_->Initialize(); 1009 safe_browsing_service_->Initialize();
986 #endif 1010 #endif
987 } 1011 }
988 1012
1013 void BrowserProcessImpl::CreateGCMDriver() {
1014 DCHECK(!gcm_driver_);
1015
1016 base::FilePath store_path;
1017 CHECK(PathService::Get(chrome::DIR_GLOBAL_GCM_STORE, &store_path));
1018
1019 scoped_refptr<base::SequencedWorkerPool> worker_pool(
1020 content::BrowserThread::GetBlockingPool());
1021 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner(
1022 worker_pool->GetSequencedTaskRunnerWithShutdownBehavior(
1023 worker_pool->GetSequenceToken(),
1024 base::SequencedWorkerPool::SKIP_ON_SHUTDOWN));
1025
1026 gcm_driver_.reset(new gcm::GCMDriver(
jianli 2014/06/02 22:34:40 You need to sync to pick up johnme's change. I don
bartfab (slow) 2014/06/03 13:36:49 Done. For consistency, I made the code also create
1027 make_scoped_ptr(new gcm::GCMClientFactory),
1028 #if defined(OS_CHROMEOS)
1029 scoped_ptr<IdentityProvider>(new chromeos::DeviceIdentityProvider(
1030 chromeos::DeviceOAuth2TokenServiceFactory::Get())),
1031 #else
1032 scoped_ptr<IdentityProvider>(new DummyIdentityProvider),
1033 #endif
1034 gcm::GetChromeBuildInfo(),
1035 store_path,
1036 system_request_context(),
1037 content::BrowserThread::GetMessageLoopProxyForThread(
1038 content::BrowserThread::UI),
1039 content::BrowserThread::GetMessageLoopProxyForThread(
1040 content::BrowserThread::IO),
1041 blocking_task_runner));
1042 }
1043
989 MetricsServicesManager* BrowserProcessImpl::GetMetricsServicesManager() { 1044 MetricsServicesManager* BrowserProcessImpl::GetMetricsServicesManager() {
990 DCHECK(CalledOnValidThread()); 1045 DCHECK(CalledOnValidThread());
991 if (!metrics_services_manager_) 1046 if (!metrics_services_manager_)
992 metrics_services_manager_.reset(new MetricsServicesManager(local_state())); 1047 metrics_services_manager_.reset(new MetricsServicesManager(local_state()));
993 return metrics_services_manager_.get(); 1048 return metrics_services_manager_.get();
994 } 1049 }
995 1050
996 void BrowserProcessImpl::ApplyDefaultBrowserPolicy() { 1051 void BrowserProcessImpl::ApplyDefaultBrowserPolicy() {
997 if (local_state()->GetBoolean(prefs::kDefaultBrowserSettingEnabled)) { 1052 if (local_state()->GetBoolean(prefs::kDefaultBrowserSettingEnabled)) {
998 scoped_refptr<ShellIntegration::DefaultWebClientWorker> 1053 scoped_refptr<ShellIntegration::DefaultWebClientWorker>
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 } 1121 }
1067 1122
1068 void BrowserProcessImpl::OnAutoupdateTimer() { 1123 void BrowserProcessImpl::OnAutoupdateTimer() {
1069 if (CanAutorestartForUpdate()) { 1124 if (CanAutorestartForUpdate()) {
1070 DLOG(WARNING) << "Detected update. Restarting browser."; 1125 DLOG(WARNING) << "Detected update. Restarting browser.";
1071 RestartBackgroundInstance(); 1126 RestartBackgroundInstance();
1072 } 1127 }
1073 } 1128 }
1074 1129
1075 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) 1130 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698