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 <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 #include "chrome/browser/printing/print_job_manager.h" | 56 #include "chrome/browser/printing/print_job_manager.h" |
57 #include "chrome/browser/printing/print_preview_dialog_controller.h" | 57 #include "chrome/browser/printing/print_preview_dialog_controller.h" |
58 #include "chrome/browser/profiles/profile_manager.h" | 58 #include "chrome/browser/profiles/profile_manager.h" |
59 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" | 59 #include "chrome/browser/renderer_host/chrome_resource_dispatcher_host_delegate.
h" |
60 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 60 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
61 #include "chrome/browser/shell_integration.h" | 61 #include "chrome/browser/shell_integration.h" |
62 #include "chrome/browser/status_icons/status_tray.h" | 62 #include "chrome/browser/status_icons/status_tray.h" |
63 #include "chrome/browser/thumbnails/render_widget_snapshot_taker.h" | 63 #include "chrome/browser/thumbnails/render_widget_snapshot_taker.h" |
64 #include "chrome/browser/ui/bookmarks/bookmark_prompt_controller.h" | 64 #include "chrome/browser/ui/bookmarks/bookmark_prompt_controller.h" |
65 #include "chrome/browser/ui/browser_list.h" | 65 #include "chrome/browser/ui/browser_list.h" |
| 66 #include "chrome/browser/web_resource/promo_resource_service.h" |
66 #include "chrome/common/chrome_constants.h" | 67 #include "chrome/common/chrome_constants.h" |
67 #include "chrome/common/chrome_notification_types.h" | 68 #include "chrome/common/chrome_notification_types.h" |
68 #include "chrome/common/chrome_paths.h" | 69 #include "chrome/common/chrome_paths.h" |
69 #include "chrome/common/chrome_switches.h" | 70 #include "chrome/common/chrome_switches.h" |
70 #include "chrome/common/extensions/extension_l10n_util.h" | 71 #include "chrome/common/extensions/extension_l10n_util.h" |
71 #include "chrome/common/extensions/extension_resource.h" | 72 #include "chrome/common/extensions/extension_resource.h" |
72 #include "chrome/common/pref_names.h" | 73 #include "chrome/common/pref_names.h" |
73 #include "chrome/common/switch_utils.h" | 74 #include "chrome/common/switch_utils.h" |
74 #include "chrome/common/url_constants.h" | 75 #include "chrome/common/url_constants.h" |
75 #include "chrome/installer/util/google_update_constants.h" | 76 #include "chrome/installer/util/google_update_constants.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 #endif | 195 #endif |
195 | 196 |
196 // We need to shutdown the SdchDictionaryFetcher as it regularly holds | 197 // We need to shutdown the SdchDictionaryFetcher as it regularly holds |
197 // a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do | 198 // a pointer to a URLFetcher, and that URLFetcher (upon destruction) will do |
198 // a PostDelayedTask onto the IO thread. This shutdown call will both discard | 199 // a PostDelayedTask onto the IO thread. This shutdown call will both discard |
199 // any pending URLFetchers, and avoid creating any more. | 200 // any pending URLFetchers, and avoid creating any more. |
200 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 201 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
201 base::Bind(&SdchDictionaryFetcher::Shutdown)); | 202 base::Bind(&SdchDictionaryFetcher::Shutdown)); |
202 | 203 |
203 // We need to destroy the MetricsService, VariationsService, | 204 // We need to destroy the MetricsService, VariationsService, |
204 // IntranetRedirectDetector, and SafeBrowsing ClientSideDetectionService | 205 // IntranetRedirectDetector, PromoResourceService, and SafeBrowsing |
205 // (owned by the SafeBrowsingService) before the io_thread_ gets destroyed, | 206 // ClientSideDetectionService (owned by the SafeBrowsingService) before the |
206 // since their destructors can call the URLFetcher destructor, which does a | 207 // io_thread_ gets destroyed, since their destructors can call the URLFetcher |
207 // PostDelayedTask operation on the IO thread. (The IO thread will handle that | 208 // destructor, which does a PostDelayedTask operation on the IO thread. (The |
208 // URLFetcher operation before going away.) | 209 // IO thread will handle that URLFetcher operation before going away.) |
209 metrics_service_.reset(); | 210 metrics_service_.reset(); |
210 variations_service_.reset(); | 211 variations_service_.reset(); |
211 intranet_redirect_detector_.reset(); | 212 intranet_redirect_detector_.reset(); |
212 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING) | 213 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING) |
213 if (safe_browsing_service_.get()) { | 214 if (safe_browsing_service_.get()) |
214 safe_browsing_service()->ShutDown(); | 215 safe_browsing_service()->ShutDown(); |
215 } | |
216 #endif | 216 #endif |
217 | 217 |
218 // Need to clear the desktop notification balloons before the io_thread_ and | 218 // Need to clear the desktop notification balloons before the io_thread_ and |
219 // before the profiles, since if there are any still showing we will access | 219 // before the profiles, since if there are any still showing we will access |
220 // those things during teardown. | 220 // those things during teardown. |
221 notification_ui_manager_.reset(); | 221 notification_ui_manager_.reset(); |
222 | 222 |
223 // Need to clear profiles (download managers) before the io_thread_. | 223 // Need to clear profiles (download managers) before the io_thread_. |
224 profile_manager_.reset(); | 224 profile_manager_.reset(); |
225 | 225 |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 // then proceed with normal shutdown. | 344 // then proceed with normal shutdown. |
345 #if defined(USE_X11) | 345 #if defined(USE_X11) |
346 // Can't run a local loop on linux. Instead create a waitable event. | 346 // Can't run a local loop on linux. Instead create a waitable event. |
347 scoped_ptr<base::WaitableEvent> done_writing( | 347 scoped_ptr<base::WaitableEvent> done_writing( |
348 new base::WaitableEvent(false, false)); | 348 new base::WaitableEvent(false, false)); |
349 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 349 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
350 base::Bind(Signal, done_writing.get())); | 350 base::Bind(Signal, done_writing.get())); |
351 // If all file writes haven't cleared in the timeout, leak the WaitableEvent | 351 // If all file writes haven't cleared in the timeout, leak the WaitableEvent |
352 // so that there's no race to reference it in Signal(). | 352 // so that there's no race to reference it in Signal(). |
353 if (!done_writing->TimedWait( | 353 if (!done_writing->TimedWait( |
354 base::TimeDelta::FromSeconds(kEndSessionTimeoutSeconds))) | 354 base::TimeDelta::FromSeconds(kEndSessionTimeoutSeconds))) { |
355 ignore_result(done_writing.release()); | 355 ignore_result(done_writing.release()); |
| 356 } |
356 | 357 |
357 #elif defined(OS_WIN) | 358 #elif defined(OS_WIN) |
358 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, | 359 BrowserThread::PostTask(BrowserThread::FILE, FROM_HERE, |
359 base::Bind(PostQuit, MessageLoop::current())); | 360 base::Bind(PostQuit, MessageLoop::current())); |
360 int quits_received = 0; | 361 int quits_received = 0; |
361 do { | 362 do { |
362 MessageLoop::current()->Run(); | 363 MessageLoop::current()->Run(); |
363 ++quits_received; | 364 ++quits_received; |
364 } while (!g_end_session_file_thread_has_completed); | 365 } while (!g_end_session_file_thread_has_completed); |
365 // If we did get extra quits, then we should re-post them to the message loop. | 366 // If we did get extra quits, then we should re-post them to the message loop. |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 return component_updater_.get(); | 677 return component_updater_.get(); |
677 #endif | 678 #endif |
678 } | 679 } |
679 | 680 |
680 CRLSetFetcher* BrowserProcessImpl::crl_set_fetcher() { | 681 CRLSetFetcher* BrowserProcessImpl::crl_set_fetcher() { |
681 #if defined(OS_CHROMEOS) | 682 #if defined(OS_CHROMEOS) |
682 // There's no component updater on ChromeOS so there can't be a CRLSetFetcher | 683 // There's no component updater on ChromeOS so there can't be a CRLSetFetcher |
683 // either. | 684 // either. |
684 return NULL; | 685 return NULL; |
685 #else | 686 #else |
686 if (!crl_set_fetcher_.get()) { | 687 if (!crl_set_fetcher_.get()) |
687 crl_set_fetcher_ = new CRLSetFetcher(); | 688 crl_set_fetcher_ = new CRLSetFetcher(); |
688 } | |
689 return crl_set_fetcher_.get(); | 689 return crl_set_fetcher_.get(); |
690 #endif | 690 #endif |
691 } | 691 } |
692 | 692 |
693 void BrowserProcessImpl::ResourceDispatcherHostCreated() { | 693 void BrowserProcessImpl::ResourceDispatcherHostCreated() { |
694 resource_dispatcher_host_delegate_.reset( | 694 resource_dispatcher_host_delegate_.reset( |
695 new ChromeResourceDispatcherHostDelegate(prerender_tracker())); | 695 new ChromeResourceDispatcherHostDelegate(prerender_tracker())); |
696 ResourceDispatcherHost::Get()->SetDelegate( | 696 ResourceDispatcherHost::Get()->SetDelegate( |
697 resource_dispatcher_host_delegate_.get()); | 697 resource_dispatcher_host_delegate_.get()); |
698 | 698 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 | 793 |
794 #if defined(ENABLE_PLUGINS) | 794 #if defined(ENABLE_PLUGINS) |
795 PluginService* plugin_service = PluginService::GetInstance(); | 795 PluginService* plugin_service = PluginService::GetInstance(); |
796 plugin_service->SetFilter(ChromePluginServiceFilter::GetInstance()); | 796 plugin_service->SetFilter(ChromePluginServiceFilter::GetInstance()); |
797 plugin_service->StartWatchingPlugins(); | 797 plugin_service->StartWatchingPlugins(); |
798 | 798 |
799 #if defined(OS_POSIX) | 799 #if defined(OS_POSIX) |
800 // Also find plugins in a user-specific plugins dir, | 800 // Also find plugins in a user-specific plugins dir, |
801 // e.g. ~/.config/chromium/Plugins. | 801 // e.g. ~/.config/chromium/Plugins. |
802 FilePath user_data_dir; | 802 FilePath user_data_dir; |
803 if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) { | 803 if (PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)) |
804 plugin_service->AddExtraPluginDir(user_data_dir.Append("Plugins")); | 804 plugin_service->AddExtraPluginDir(user_data_dir.Append("Plugins")); |
805 } | |
806 #endif | 805 #endif |
807 | 806 |
| 807 #endif // defined(ENABLE_PLUGINS) |
| 808 |
| 809 if (local_state()->IsManagedPreference(prefs::kDefaultBrowserSettingEnabled)) |
| 810 ApplyDefaultBrowserPolicy(); |
| 811 |
808 // Triggers initialization of the singleton instance on UI thread. | 812 // Triggers initialization of the singleton instance on UI thread. |
809 PluginFinder::GetInstance()->Init(); | 813 PluginFinder::GetInstance()->Init(); |
810 | 814 |
811 #if defined(ENABLE_PLUGIN_INSTALLATION) | 815 #if defined(ENABLE_PLUGIN_INSTALLATION) |
812 if (!plugins_resource_service_) { | 816 DCHECK(!plugins_resource_service_.get()); |
813 plugins_resource_service_ = new PluginsResourceService(local_state()); | 817 plugins_resource_service_ = new PluginsResourceService(local_state()); |
814 plugins_resource_service_->StartAfterDelay(); | 818 plugins_resource_service_->StartAfterDelay(); |
| 819 #endif |
| 820 |
| 821 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 822 if (!command_line.HasSwitch(switches::kDisableWebResources)) { |
| 823 DCHECK(!promo_resource_service_.get()); |
| 824 promo_resource_service_ = new PromoResourceService; |
| 825 promo_resource_service_->StartAfterDelay(); |
815 } | 826 } |
816 #endif | |
817 #endif // defined(ENABLE_PLUGINS) | |
818 | 827 |
819 #if !defined(OS_ANDROID) | 828 #if !defined(OS_ANDROID) |
820 if (browser_defaults::bookmarks_enabled && | 829 if (browser_defaults::bookmarks_enabled && |
821 BookmarkPromptController::IsEnabled()) | 830 BookmarkPromptController::IsEnabled()) { |
822 bookmark_prompt_controller_.reset(new BookmarkPromptController()); | 831 bookmark_prompt_controller_.reset(new BookmarkPromptController()); |
| 832 } |
823 #endif | 833 #endif |
824 } | 834 } |
825 | 835 |
826 void BrowserProcessImpl::CreateIconManager() { | 836 void BrowserProcessImpl::CreateIconManager() { |
827 DCHECK(!created_icon_manager_ && icon_manager_.get() == NULL); | 837 DCHECK(!created_icon_manager_ && icon_manager_.get() == NULL); |
828 created_icon_manager_ = true; | 838 created_icon_manager_ = true; |
829 icon_manager_.reset(new IconManager); | 839 icon_manager_.reset(new IconManager); |
830 } | 840 } |
831 | 841 |
832 void BrowserProcessImpl::CreateIntranetRedirectDetector() { | 842 void BrowserProcessImpl::CreateIntranetRedirectDetector() { |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 // create the service class if there was an error. | 891 // create the service class if there was an error. |
882 created_safe_browsing_service_ = true; | 892 created_safe_browsing_service_ = true; |
883 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING) | 893 #if defined(FULL_SAFE_BROWSING) || defined(MOBILE_SAFE_BROWSING) |
884 safe_browsing_service_ = SafeBrowsingService::CreateSafeBrowsingService(); | 894 safe_browsing_service_ = SafeBrowsingService::CreateSafeBrowsingService(); |
885 safe_browsing_service_->Initialize(); | 895 safe_browsing_service_->Initialize(); |
886 #endif | 896 #endif |
887 } | 897 } |
888 | 898 |
889 void BrowserProcessImpl::ApplyDisabledSchemesPolicy() { | 899 void BrowserProcessImpl::ApplyDisabledSchemesPolicy() { |
890 std::set<std::string> schemes; | 900 std::set<std::string> schemes; |
891 const ListValue* scheme_list = local_state_->GetList(prefs::kDisabledSchemes); | 901 const ListValue* scheme_list = |
| 902 local_state()->GetList(prefs::kDisabledSchemes); |
892 for (ListValue::const_iterator iter = scheme_list->begin(); | 903 for (ListValue::const_iterator iter = scheme_list->begin(); |
893 iter != scheme_list->end(); ++iter) { | 904 iter != scheme_list->end(); ++iter) { |
894 std::string scheme; | 905 std::string scheme; |
895 if ((*iter)->GetAsString(&scheme)) | 906 if ((*iter)->GetAsString(&scheme)) |
896 schemes.insert(scheme); | 907 schemes.insert(scheme); |
897 } | 908 } |
898 ChildProcessSecurityPolicy::GetInstance()->RegisterDisabledSchemes(schemes); | 909 ChildProcessSecurityPolicy::GetInstance()->RegisterDisabledSchemes(schemes); |
899 } | 910 } |
900 | 911 |
901 void BrowserProcessImpl::ApplyDefaultBrowserPolicy() { | 912 void BrowserProcessImpl::ApplyDefaultBrowserPolicy() { |
902 if (local_state_->GetBoolean(prefs::kDefaultBrowserSettingEnabled)) { | 913 if (local_state()->GetBoolean(prefs::kDefaultBrowserSettingEnabled)) { |
903 scoped_refptr<ShellIntegration::DefaultWebClientWorker> | 914 scoped_refptr<ShellIntegration::DefaultWebClientWorker> |
904 set_browser_worker = new ShellIntegration::DefaultBrowserWorker(NULL); | 915 set_browser_worker = new ShellIntegration::DefaultBrowserWorker(NULL); |
905 set_browser_worker->StartSetAsDefault(); | 916 set_browser_worker->StartSetAsDefault(); |
906 } | 917 } |
907 } | 918 } |
908 | 919 |
909 void BrowserProcessImpl::ApplyAllowCrossOriginAuthPromptPolicy() { | 920 void BrowserProcessImpl::ApplyAllowCrossOriginAuthPromptPolicy() { |
910 bool value = local_state()->GetBoolean(prefs::kAllowCrossOriginAuthPrompt); | 921 bool value = local_state()->GetBoolean(prefs::kAllowCrossOriginAuthPrompt); |
911 ResourceDispatcherHost::Get()->SetAllowCrossOriginAuthPrompt(value); | 922 ResourceDispatcherHost::Get()->SetAllowCrossOriginAuthPrompt(value); |
912 } | 923 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
961 } | 972 } |
962 | 973 |
963 void BrowserProcessImpl::OnAutoupdateTimer() { | 974 void BrowserProcessImpl::OnAutoupdateTimer() { |
964 if (CanAutorestartForUpdate()) { | 975 if (CanAutorestartForUpdate()) { |
965 DLOG(WARNING) << "Detected update. Restarting browser."; | 976 DLOG(WARNING) << "Detected update. Restarting browser."; |
966 RestartBackgroundInstance(); | 977 RestartBackgroundInstance(); |
967 } | 978 } |
968 } | 979 } |
969 | 980 |
970 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) | 981 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
OLD | NEW |