| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "app/clipboard/clipboard.h" | 7 #include "app/clipboard/clipboard.h" |
| 8 #include "app/l10n_util.h" | 8 #include "app/l10n_util.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/thread.h" | 12 #include "base/thread.h" |
| 13 #include "base/waitable_event.h" | 13 #include "base/waitable_event.h" |
| 14 #include "chrome/browser/browser_main.h" | 14 #include "chrome/browser/browser_main.h" |
| 15 #include "chrome/browser/browser_process_sub_thread.h" | 15 #include "chrome/browser/browser_process_sub_thread.h" |
| 16 #include "chrome/browser/browser_trial.h" | 16 #include "chrome/browser/browser_trial.h" |
| 17 #include "chrome/browser/chrome_thread.h" | 17 #include "chrome/browser/chrome_thread.h" |
| 18 #include "chrome/browser/debugger/debugger_wrapper.h" | 18 #include "chrome/browser/debugger/debugger_wrapper.h" |
| 19 #include "chrome/browser/debugger/devtools_manager.h" | 19 #include "chrome/browser/debugger/devtools_manager.h" |
| 20 #include "chrome/browser/download/download_file.h" | 20 #include "chrome/browser/download/download_file.h" |
| 21 #include "chrome/browser/download/save_file_manager.h" | 21 #include "chrome/browser/download/save_file_manager.h" |
| 22 #include "chrome/browser/google_url_tracker.h" | 22 #include "chrome/browser/google_url_tracker.h" |
| 23 #include "chrome/browser/icon_manager.h" | 23 #include "chrome/browser/icon_manager.h" |
| 24 #include "chrome/browser/in_process_webkit/dom_storage_context.h" |
| 24 #include "chrome/browser/intranet_redirect_detector.h" | 25 #include "chrome/browser/intranet_redirect_detector.h" |
| 25 #include "chrome/browser/io_thread.h" | 26 #include "chrome/browser/io_thread.h" |
| 26 #include "chrome/browser/metrics/metrics_service.h" | 27 #include "chrome/browser/metrics/metrics_service.h" |
| 27 #include "chrome/browser/net/dns_global.h" | 28 #include "chrome/browser/net/dns_global.h" |
| 28 #include "chrome/browser/net/sdch_dictionary_fetcher.h" | 29 #include "chrome/browser/net/sdch_dictionary_fetcher.h" |
| 30 #include "chrome/browser/net/sqlite_persistent_cookie_store.h" |
| 29 #include "chrome/browser/notifications/notification_ui_manager.h" | 31 #include "chrome/browser/notifications/notification_ui_manager.h" |
| 30 #include "chrome/browser/plugin_service.h" | 32 #include "chrome/browser/plugin_service.h" |
| 31 #include "chrome/browser/profile_manager.h" | 33 #include "chrome/browser/profile_manager.h" |
| 32 #include "chrome/browser/renderer_host/render_process_host.h" | 34 #include "chrome/browser/renderer_host/render_process_host.h" |
| 33 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 35 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" |
| 34 #include "chrome/browser/safe_browsing/safe_browsing_service.h" | 36 #include "chrome/browser/safe_browsing/safe_browsing_service.h" |
| 35 #include "chrome/common/child_process_host.h" | 37 #include "chrome/common/child_process_host.h" |
| 38 #include "chrome/common/chrome_constants.h" |
| 36 #include "chrome/common/chrome_paths.h" | 39 #include "chrome/common/chrome_paths.h" |
| 37 #include "chrome/common/chrome_switches.h" | 40 #include "chrome/common/chrome_switches.h" |
| 38 #include "chrome/common/notification_service.h" | 41 #include "chrome/common/notification_service.h" |
| 39 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
| 40 #include "chrome/common/pref_service.h" | 43 #include "chrome/common/pref_service.h" |
| 44 #include "chrome/common/url_constants.h" |
| 41 #include "ipc/ipc_logging.h" | 45 #include "ipc/ipc_logging.h" |
| 46 #include "webkit/database/database_tracker.h" |
| 42 | 47 |
| 43 #if defined(OS_WIN) | 48 #if defined(OS_WIN) |
| 44 #include "views/focus/view_storage.h" | 49 #include "views/focus/view_storage.h" |
| 45 #endif | 50 #endif |
| 46 | 51 |
| 47 #if defined(OS_LINUX) | 52 #if defined(OS_LINUX) |
| 48 // TODO(port): get rid of this. | 53 // TODO(port): get rid of this. |
| 49 #include "chrome/common/temp_scaffolding_stubs.h" | 54 #include "chrome/common/temp_scaffolding_stubs.h" |
| 50 #else | 55 #else |
| 51 #include "chrome/browser/printing/print_job_manager.h" | 56 #include "chrome/browser/printing/print_job_manager.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 81 clipboard_.reset(new Clipboard); | 86 clipboard_.reset(new Clipboard); |
| 82 main_notification_service_.reset(new NotificationService); | 87 main_notification_service_.reset(new NotificationService); |
| 83 | 88 |
| 84 // Must be created after the NotificationService. | 89 // Must be created after the NotificationService. |
| 85 print_job_manager_.reset(new printing::PrintJobManager); | 90 print_job_manager_.reset(new printing::PrintJobManager); |
| 86 | 91 |
| 87 shutdown_event_.reset(new base::WaitableEvent(true, false)); | 92 shutdown_event_.reset(new base::WaitableEvent(true, false)); |
| 88 } | 93 } |
| 89 | 94 |
| 90 BrowserProcessImpl::~BrowserProcessImpl() { | 95 BrowserProcessImpl::~BrowserProcessImpl() { |
| 96 FilePath profile_path; |
| 97 bool clear_local_state_on_exit; |
| 98 |
| 99 // Store the profile path for clearing local state data on exit. |
| 100 clear_local_state_on_exit = ShouldClearLocalState(&profile_path); |
| 101 |
| 91 // Delete the AutomationProviderList before NotificationService, | 102 // Delete the AutomationProviderList before NotificationService, |
| 92 // since it may try to unregister notifications | 103 // since it may try to unregister notifications |
| 93 // Both NotificationService and AutomationProvider are singleton instances in | 104 // Both NotificationService and AutomationProvider are singleton instances in |
| 94 // the BrowserProcess. Since AutomationProvider may have some active | 105 // the BrowserProcess. Since AutomationProvider may have some active |
| 95 // notification observers, it is essential that it gets destroyed before the | 106 // notification observers, it is essential that it gets destroyed before the |
| 96 // NotificationService. NotificationService won't be destroyed until after | 107 // NotificationService. NotificationService won't be destroyed until after |
| 97 // this destructor is run. | 108 // this destructor is run. |
| 98 automation_provider_list_.reset(); | 109 automation_provider_list_.reset(); |
| 99 | 110 |
| 100 // We need to shutdown the SdchDictionaryFetcher as it regularly holds | 111 // We need to shutdown the SdchDictionaryFetcher as it regularly holds |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 if (resource_dispatcher_host_.get()) { | 157 if (resource_dispatcher_host_.get()) { |
| 147 resource_dispatcher_host()->download_file_manager()->Shutdown(); | 158 resource_dispatcher_host()->download_file_manager()->Shutdown(); |
| 148 resource_dispatcher_host()->save_file_manager()->Shutdown(); | 159 resource_dispatcher_host()->save_file_manager()->Shutdown(); |
| 149 } | 160 } |
| 150 | 161 |
| 151 // Need to stop the file_thread_ here to force it to process messages in its | 162 // Need to stop the file_thread_ here to force it to process messages in its |
| 152 // message loop from the previous call to shutdown the DownloadFileManager, | 163 // message loop from the previous call to shutdown the DownloadFileManager, |
| 153 // SaveFileManager and SessionService. | 164 // SaveFileManager and SessionService. |
| 154 file_thread_.reset(); | 165 file_thread_.reset(); |
| 155 | 166 |
| 167 // At this point, no render process exist, so it's safe to access local |
| 168 // state data such as cookies, database, or local storage. |
| 169 if (clear_local_state_on_exit) |
| 170 ClearLocalState(profile_path); |
| 171 |
| 156 // With the file_thread_ flushed, we can release any icon resources. | 172 // With the file_thread_ flushed, we can release any icon resources. |
| 157 icon_manager_.reset(); | 173 icon_manager_.reset(); |
| 158 | 174 |
| 159 // Need to destroy ResourceDispatcherHost before PluginService and | 175 // Need to destroy ResourceDispatcherHost before PluginService and |
| 160 // SafeBrowsingService, since it caches a pointer to it. | 176 // SafeBrowsingService, since it caches a pointer to it. |
| 161 resource_dispatcher_host_.reset(); | 177 resource_dispatcher_host_.reset(); |
| 162 | 178 |
| 163 // Wait for the pending print jobs to finish. | 179 // Wait for the pending print jobs to finish. |
| 164 print_job_manager_->OnQuit(); | 180 print_job_manager_->OnQuit(); |
| 165 print_job_manager_.reset(); | 181 print_job_manager_.reset(); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 | 241 |
| 226 printing::PrintJobManager* BrowserProcessImpl::print_job_manager() { | 242 printing::PrintJobManager* BrowserProcessImpl::print_job_manager() { |
| 227 // TODO(abarth): DCHECK(CalledOnValidThread()); | 243 // TODO(abarth): DCHECK(CalledOnValidThread()); |
| 228 // See <http://b/1287209>. | 244 // See <http://b/1287209>. |
| 229 // print_job_manager_ is initialized in the constructor and destroyed in the | 245 // print_job_manager_ is initialized in the constructor and destroyed in the |
| 230 // destructor, so it should always be valid. | 246 // destructor, so it should always be valid. |
| 231 DCHECK(print_job_manager_.get()); | 247 DCHECK(print_job_manager_.get()); |
| 232 return print_job_manager_.get(); | 248 return print_job_manager_.get(); |
| 233 } | 249 } |
| 234 | 250 |
| 251 void BrowserProcessImpl::ClearLocalState(const FilePath& profile_path) { |
| 252 SQLitePersistentCookieStore::ClearLocalState(profile_path.Append( |
| 253 chrome::kCookieFilename)); |
| 254 DOMStorageContext::ClearLocalState(profile_path, chrome::kExtensionScheme); |
| 255 webkit_database::DatabaseTracker::ClearLocalState(profile_path, |
| 256 chrome::kExtensionScheme); |
| 257 // TODO(jochen): clear app cache local state. |
| 258 } |
| 259 |
| 260 bool BrowserProcessImpl::ShouldClearLocalState(FilePath* profile_path) { |
| 261 FilePath user_data_dir; |
| 262 Profile* profile; |
| 263 |
| 264 PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); |
| 265 profile = profile_manager_->GetDefaultProfile(user_data_dir); |
| 266 *profile_path = profile->GetPath(); |
| 267 return profile->GetPrefs()->GetBoolean(prefs::kClearSiteDataOnExit); |
| 268 } |
| 269 |
| 235 void BrowserProcessImpl::CreateResourceDispatcherHost() { | 270 void BrowserProcessImpl::CreateResourceDispatcherHost() { |
| 236 DCHECK(!created_resource_dispatcher_host_ && | 271 DCHECK(!created_resource_dispatcher_host_ && |
| 237 resource_dispatcher_host_.get() == NULL); | 272 resource_dispatcher_host_.get() == NULL); |
| 238 created_resource_dispatcher_host_ = true; | 273 created_resource_dispatcher_host_ = true; |
| 239 | 274 |
| 240 resource_dispatcher_host_.reset(new ResourceDispatcherHost()); | 275 resource_dispatcher_host_.reset(new ResourceDispatcherHost()); |
| 241 resource_dispatcher_host_->Initialize(); | 276 resource_dispatcher_host_->Initialize(); |
| 242 } | 277 } |
| 243 | 278 |
| 244 void BrowserProcessImpl::CreateMetricsService() { | 279 void BrowserProcessImpl::CreateMetricsService() { |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 DCHECK(file_thread_->message_loop() == MessageLoop::current()); | 473 DCHECK(file_thread_->message_loop() == MessageLoop::current()); |
| 439 bool result = false; | 474 bool result = false; |
| 440 | 475 |
| 441 FilePath inspector_dir; | 476 FilePath inspector_dir; |
| 442 if (PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) { | 477 if (PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) { |
| 443 result = file_util::PathExists(inspector_dir); | 478 result = file_util::PathExists(inspector_dir); |
| 444 } | 479 } |
| 445 | 480 |
| 446 have_inspector_files_ = result; | 481 have_inspector_files_ = result; |
| 447 } | 482 } |
| OLD | NEW |