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

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

Issue 6292017: Extended: Add "system" URLRequestContext (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 9 years, 10 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 <map> 7 #include <map>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 16 matching lines...) Expand all
27 #include "chrome/browser/download/download_file_manager.h" 27 #include "chrome/browser/download/download_file_manager.h"
28 #include "chrome/browser/download/save_file_manager.h" 28 #include "chrome/browser/download/save_file_manager.h"
29 #include "chrome/browser/first_run/first_run.h" 29 #include "chrome/browser/first_run/first_run.h"
30 #include "chrome/browser/google/google_url_tracker.h" 30 #include "chrome/browser/google/google_url_tracker.h"
31 #include "chrome/browser/icon_manager.h" 31 #include "chrome/browser/icon_manager.h"
32 #include "chrome/browser/intranet_redirect_detector.h" 32 #include "chrome/browser/intranet_redirect_detector.h"
33 #include "chrome/browser/io_thread.h" 33 #include "chrome/browser/io_thread.h"
34 #include "chrome/browser/metrics/metrics_service.h" 34 #include "chrome/browser/metrics/metrics_service.h"
35 #include "chrome/browser/net/chrome_net_log.h" 35 #include "chrome/browser/net/chrome_net_log.h"
36 #include "chrome/browser/net/predictor_api.h" 36 #include "chrome/browser/net/predictor_api.h"
37 #include "chrome/browser/net/pref_proxy_config_service.h"
37 #include "chrome/browser/net/sdch_dictionary_fetcher.h" 38 #include "chrome/browser/net/sdch_dictionary_fetcher.h"
38 #include "chrome/browser/notifications/notification_ui_manager.h" 39 #include "chrome/browser/notifications/notification_ui_manager.h"
39 #include "chrome/browser/plugin_data_remover.h" 40 #include "chrome/browser/plugin_data_remover.h"
40 #include "chrome/browser/plugin_service.h" 41 #include "chrome/browser/plugin_service.h"
41 #include "chrome/browser/plugin_updater.h" 42 #include "chrome/browser/plugin_updater.h"
42 #include "chrome/browser/policy/configuration_policy_provider_keeper.h" 43 #include "chrome/browser/policy/configuration_policy_provider_keeper.h"
43 #include "chrome/browser/prefs/pref_service.h" 44 #include "chrome/browser/prefs/pref_service.h"
44 #include "chrome/browser/printing/print_job_manager.h" 45 #include "chrome/browser/printing/print_job_manager.h"
45 #include "chrome/browser/printing/print_preview_tab_controller.h" 46 #include "chrome/browser/printing/print_preview_tab_controller.h"
46 #include "chrome/browser/profiles/profile_manager.h" 47 #include "chrome/browser/profiles/profile_manager.h"
47 #include "chrome/browser/renderer_host/render_process_host.h" 48 #include "chrome/browser/renderer_host/render_process_host.h"
48 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" 49 #include "chrome/browser/renderer_host/resource_dispatcher_host.h"
49 #include "chrome/browser/safe_browsing/client_side_detection_service.h" 50 #include "chrome/browser/safe_browsing/client_side_detection_service.h"
50 #include "chrome/browser/safe_browsing/safe_browsing_service.h" 51 #include "chrome/browser/safe_browsing/safe_browsing_service.h"
51 #include "chrome/browser/shell_integration.h" 52 #include "chrome/browser/shell_integration.h"
52 #include "chrome/browser/sidebar/sidebar_manager.h" 53 #include "chrome/browser/sidebar/sidebar_manager.h"
53 #include "chrome/browser/tab_closeable_state_watcher.h" 54 #include "chrome/browser/tab_closeable_state_watcher.h"
54 #include "chrome/common/chrome_constants.h" 55 #include "chrome/common/chrome_constants.h"
55 #include "chrome/common/chrome_paths.h" 56 #include "chrome/common/chrome_paths.h"
56 #include "chrome/common/chrome_switches.h" 57 #include "chrome/common/chrome_switches.h"
57 #include "chrome/common/extensions/extension_resource.h" 58 #include "chrome/common/extensions/extension_resource.h"
58 #include "chrome/common/extensions/extension_l10n_util.h" 59 #include "chrome/common/extensions/extension_l10n_util.h"
59 #include "chrome/common/json_pref_store.h" 60 #include "chrome/common/json_pref_store.h"
61 #include "chrome/common/net/url_request_context_getter.h"
60 #include "chrome/common/notification_service.h" 62 #include "chrome/common/notification_service.h"
61 #include "chrome/common/pref_names.h" 63 #include "chrome/common/pref_names.h"
62 #include "chrome/common/url_constants.h" 64 #include "chrome/common/url_constants.h"
63 #include "chrome/common/switch_utils.h" 65 #include "chrome/common/switch_utils.h"
64 #include "chrome/installer/util/google_update_constants.h" 66 #include "chrome/installer/util/google_update_constants.h"
65 #include "ipc/ipc_logging.h" 67 #include "ipc/ipc_logging.h"
66 #include "ui/base/clipboard/clipboard.h" 68 #include "ui/base/clipboard/clipboard.h"
67 #include "ui/base/l10n/l10n_util.h" 69 #include "ui/base/l10n/l10n_util.h"
68 #include "webkit/database/database_tracker.h" 70 #include "webkit/database/database_tracker.h"
69 71
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 configuration_policy_provider_keeper_.reset(); 194 configuration_policy_provider_keeper_.reset();
193 195
194 #if defined(USE_X11) 196 #if defined(USE_X11)
195 // The IO thread must outlive the BACKGROUND_X11 thread. 197 // The IO thread must outlive the BACKGROUND_X11 thread.
196 background_x11_thread_.reset(); 198 background_x11_thread_.reset();
197 #endif 199 #endif
198 200
199 // Wait for removing plugin data to finish before shutting down the IO thread. 201 // Wait for removing plugin data to finish before shutting down the IO thread.
200 WaitForPluginDataRemoverToFinish(); 202 WaitForPluginDataRemoverToFinish();
201 203
204 // Give up reference before io_thread_ checks that there is no one left
205 // holding a reference.
206 system_request_context_ = NULL;
207
202 // Need to stop io_thread_ before resource_dispatcher_host_, since 208 // Need to stop io_thread_ before resource_dispatcher_host_, since
203 // io_thread_ may still deref ResourceDispatcherHost and handle resource 209 // io_thread_ may still deref ResourceDispatcherHost and handle resource
204 // request before going away. 210 // request before going away.
205 io_thread_.reset(); 211 io_thread_.reset();
206 212
207 // The IO thread was the only user of this thread. 213 // The IO thread was the only user of this thread.
208 cache_thread_.reset(); 214 cache_thread_.reset();
209 215
210 // Stop the process launcher thread after the IO thread, in case the IO thread 216 // Stop the process launcher thread after the IO thread, in case the IO thread
211 // posted a task to terminate a process on the process launcher thread. 217 // posted a task to terminate a process on the process launcher thread.
(...skipping 26 matching lines...) Expand all
238 // former registers for notifications. 244 // former registers for notifications.
239 tab_closeable_state_watcher_.reset(); 245 tab_closeable_state_watcher_.reset();
240 246
241 // Now OK to destroy NotificationService. 247 // Now OK to destroy NotificationService.
242 main_notification_service_.reset(); 248 main_notification_service_.reset();
243 249
244 // Prior to clearing local state, we want to complete tasks pending 250 // Prior to clearing local state, we want to complete tasks pending
245 // on the db thread too. 251 // on the db thread too.
246 db_thread_.reset(); 252 db_thread_.reset();
247 253
254 // Need to destroy PrefProxyConfigTracker before local state, since it
255 // caches a pointer to it.
256 pref_proxy_config_tracker_->DetachFromPrefService();
257 pref_proxy_config_tracker_ = NULL;
258
248 // At this point, no render process exist and the file, io, db, and 259 // At this point, no render process exist and the file, io, db, and
249 // webkit threads in this process have all terminated, so it's safe 260 // webkit threads in this process have all terminated, so it's safe
250 // to access local state data such as cookies, database, or local storage. 261 // to access local state data such as cookies, database, or local storage.
251 if (clear_local_state_on_exit) 262 if (clear_local_state_on_exit)
252 ClearLocalState(profile_path); 263 ClearLocalState(profile_path);
253 264
254 g_browser_process = NULL; 265 g_browser_process = NULL;
255 } 266 }
256 267
257 #if defined(OS_WIN) 268 #if defined(OS_WIN)
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 if (!created_sidebar_manager_) 427 if (!created_sidebar_manager_)
417 CreateSidebarManager(); 428 CreateSidebarManager();
418 return sidebar_manager_.get(); 429 return sidebar_manager_.get();
419 } 430 }
420 431
421 ui::Clipboard* BrowserProcessImpl::clipboard() { 432 ui::Clipboard* BrowserProcessImpl::clipboard() {
422 DCHECK(CalledOnValidThread()); 433 DCHECK(CalledOnValidThread());
423 return clipboard_.get(); 434 return clipboard_.get();
424 } 435 }
425 436
437 PrefProxyConfigTracker* BrowserProcessImpl::pref_proxy_config_tracker() {
438 DCHECK(CalledOnValidThread());
439 if (!created_pref_proxy_config_tracker_)
440 CreatePrefProxyConfigTracker();
441 return pref_proxy_config_tracker_.get();
442 }
443
444 scoped_refptr<URLRequestContextGetter>
445 BrowserProcessImpl::system_request_context() {
446 DCHECK(CalledOnValidThread());
447 if (!created_system_request_context_)
448 CreateSystemRequestContextGetter();
449 return system_request_context_.get();
450 }
451
426 NotificationUIManager* BrowserProcessImpl::notification_ui_manager() { 452 NotificationUIManager* BrowserProcessImpl::notification_ui_manager() {
427 DCHECK(CalledOnValidThread()); 453 DCHECK(CalledOnValidThread());
428 if (!created_notification_ui_manager_) 454 if (!created_notification_ui_manager_)
429 CreateNotificationUIManager(); 455 CreateNotificationUIManager();
430 return notification_ui_manager_.get(); 456 return notification_ui_manager_.get();
431 } 457 }
432 458
433 policy::ConfigurationPolicyProviderKeeper* 459 policy::ConfigurationPolicyProviderKeeper*
434 BrowserProcessImpl::configuration_policy_provider_keeper() { 460 BrowserProcessImpl::configuration_policy_provider_keeper() {
435 DCHECK(CalledOnValidThread()); 461 DCHECK(CalledOnValidThread());
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 if (IsSafeBrowsingDetectionServiceEnabled() && 852 if (IsSafeBrowsingDetectionServiceEnabled() &&
827 PathService::Get(chrome::DIR_USER_DATA, &model_file_path) && 853 PathService::Get(chrome::DIR_USER_DATA, &model_file_path) &&
828 profile && profile->GetRequestContext()) { 854 profile && profile->GetRequestContext()) {
829 safe_browsing_detection_service_.reset( 855 safe_browsing_detection_service_.reset(
830 safe_browsing::ClientSideDetectionService::Create( 856 safe_browsing::ClientSideDetectionService::Create(
831 model_file_path.Append(chrome::kSafeBrowsingPhishingModelFilename), 857 model_file_path.Append(chrome::kSafeBrowsingPhishingModelFilename),
832 profile->GetRequestContext())); 858 profile->GetRequestContext()));
833 } 859 }
834 } 860 }
835 861
862 void BrowserProcessImpl::CreatePrefProxyConfigTracker() {
863 DCHECK(pref_proxy_config_tracker_.get() == NULL);
864 created_pref_proxy_config_tracker_ = true;
865 pref_proxy_config_tracker_ = new PrefProxyConfigTracker(local_state());
866 }
867
868 void BrowserProcessImpl::CreateSystemRequestContextGetter() {
869 DCHECK(system_request_context_.get() == NULL);
870 created_system_request_context_ = true;
871 system_request_context_ = io_thread()->system_url_request_context_getter();
872 }
873
836 bool BrowserProcessImpl::IsSafeBrowsingDetectionServiceEnabled() { 874 bool BrowserProcessImpl::IsSafeBrowsingDetectionServiceEnabled() {
837 // The safe browsing client-side detection is enabled only if the switch is 875 // The safe browsing client-side detection is enabled only if the switch is
838 // enabled and when safe browsing related stats is allowed to be collected. 876 // enabled and when safe browsing related stats is allowed to be collected.
839 return CommandLine::ForCurrentProcess()->HasSwitch( 877 return CommandLine::ForCurrentProcess()->HasSwitch(
840 switches::kEnableClientSidePhishingDetection) && 878 switches::kEnableClientSidePhishingDetection) &&
841 resource_dispatcher_host()->safe_browsing_service() && 879 resource_dispatcher_host()->safe_browsing_service() &&
842 resource_dispatcher_host()->safe_browsing_service()->CanReportStats(); 880 resource_dispatcher_host()->safe_browsing_service()->CanReportStats();
843 } 881 }
844 882
845 // The BrowserProcess object must outlive the file thread so we use traits 883 // The BrowserProcess object must outlive the file thread so we use traits
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 } 985 }
948 986
949 void BrowserProcessImpl::OnAutoupdateTimer() { 987 void BrowserProcessImpl::OnAutoupdateTimer() {
950 if (CanAutorestartForUpdate()) { 988 if (CanAutorestartForUpdate()) {
951 DLOG(WARNING) << "Detected update. Restarting browser."; 989 DLOG(WARNING) << "Detected update. Restarting browser.";
952 RestartPersistentInstance(); 990 RestartPersistentInstance();
953 } 991 }
954 } 992 }
955 993
956 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) 994 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS)
995
996 void BrowserProcessImpl::InitSystemRequestContext() {
997 // The linux gconf-based proxy settings getter relies on being initialized
998 // from the UI thread.
999 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
1000
1001 // Create a baseline service that provides proxy configuration in case nothing
1002 // is configured through prefs (Note: prefs include command line and
1003 // configuration policy).
1004 net::ProxyConfigService* base_service = NULL;
1005
1006 // TODO(port): the IO and FILE message loops are only used by Linux. Can
1007 // that code be moved to chrome/browser instead of being in net, so that it
1008 // can use BrowserThread instead of raw MessageLoop pointers? See bug 25354.
1009 #if defined(OS_CHROMEOS)
1010 base_service = new chromeos::ProxyConfigService(
1011 new chromeos::ProxyConfigServiceImpl());
1012 #else
1013 base_service = net::ProxyService::CreateSystemProxyConfigService(
1014 io_thread()->message_loop(), file_thread()->message_loop());
1015 #endif // defined(OS_CHROMEOS)
1016
1017 net::ProxyConfigService* config_service =
1018 new PrefProxyConfigService(pref_proxy_config_tracker(),
1019 base_service);
1020
1021 // Takes ownership of config_service.
1022 io_thread()->InitSystemRequestContext(config_service);
1023 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698