| 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 <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "app/clipboard/clipboard.h" | 9 #include "app/clipboard/clipboard.h" |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 14 #include "base/task.h" |
| 14 #include "base/thread.h" | 15 #include "base/thread.h" |
| 15 #include "base/waitable_event.h" | 16 #include "base/waitable_event.h" |
| 16 #include "chrome/browser/appcache/chrome_appcache_service.h" | 17 #include "chrome/browser/appcache/chrome_appcache_service.h" |
| 17 #include "chrome/browser/automation/automation_provider_list.h" | 18 #include "chrome/browser/automation/automation_provider_list.h" |
| 18 #include "chrome/browser/browser_child_process_host.h" | 19 #include "chrome/browser/browser_child_process_host.h" |
| 19 #include "chrome/browser/browser_list.h" | 20 #include "chrome/browser/browser_list.h" |
| 20 #include "chrome/browser/browser_main.h" | 21 #include "chrome/browser/browser_main.h" |
| 21 #include "chrome/browser/browser_process_sub_thread.h" | 22 #include "chrome/browser/browser_process_sub_thread.h" |
| 22 #include "chrome/browser/browser_trial.h" | 23 #include "chrome/browser/browser_trial.h" |
| 23 #include "chrome/browser/chrome_thread.h" | 24 #include "chrome/browser/chrome_thread.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 #include "chrome/common/plugin_messages.h" | 68 #include "chrome/common/plugin_messages.h" |
| 68 #include "chrome/common/render_messages.h" | 69 #include "chrome/common/render_messages.h" |
| 69 #endif | 70 #endif |
| 70 | 71 |
| 71 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) | 72 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
| 72 // How often to check if the persistent instance of Chrome needs to restart | 73 // How often to check if the persistent instance of Chrome needs to restart |
| 73 // to install an update. | 74 // to install an update. |
| 74 static const int kUpdateCheckIntervalHours = 6; | 75 static const int kUpdateCheckIntervalHours = 6; |
| 75 #endif | 76 #endif |
| 76 | 77 |
| 78 #if defined(USE_X11) |
| 79 // How long to wait for the File thread to complete during EndSession, on |
| 80 // Linux. We have a timeout here because we're unable to run the UI messageloop |
| 81 // and there's some deadlock risk. Our only option is to exit anyway. |
| 82 static const int kEndSessionTimeoutSeconds = 10; |
| 83 #endif |
| 84 |
| 77 BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line) | 85 BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line) |
| 78 : created_resource_dispatcher_host_(false), | 86 : created_resource_dispatcher_host_(false), |
| 79 created_metrics_service_(false), | 87 created_metrics_service_(false), |
| 80 created_io_thread_(false), | 88 created_io_thread_(false), |
| 81 created_file_thread_(false), | 89 created_file_thread_(false), |
| 82 created_db_thread_(false), | 90 created_db_thread_(false), |
| 83 created_process_launcher_thread_(false), | 91 created_process_launcher_thread_(false), |
| 84 created_cache_thread_(false), | 92 created_cache_thread_(false), |
| 85 created_profile_manager_(false), | 93 created_profile_manager_(false), |
| 86 created_local_state_(false), | 94 created_local_state_(false), |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 208 | 216 |
| 209 // At this point, no render process exist and the file, io, db, and | 217 // At this point, no render process exist and the file, io, db, and |
| 210 // webkit threads in this process have all terminated, so it's safe | 218 // webkit threads in this process have all terminated, so it's safe |
| 211 // to access local state data such as cookies, database, or local storage. | 219 // to access local state data such as cookies, database, or local storage. |
| 212 if (clear_local_state_on_exit) | 220 if (clear_local_state_on_exit) |
| 213 ClearLocalState(profile_path); | 221 ClearLocalState(profile_path); |
| 214 | 222 |
| 215 g_browser_process = NULL; | 223 g_browser_process = NULL; |
| 216 } | 224 } |
| 217 | 225 |
| 226 #if defined(OS_WIN) |
| 218 // Send a QuitTask to the given MessageLoop. | 227 // Send a QuitTask to the given MessageLoop. |
| 219 static void PostQuit(MessageLoop* message_loop) { | 228 static void PostQuit(MessageLoop* message_loop) { |
| 220 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); | 229 message_loop->PostTask(FROM_HERE, new MessageLoop::QuitTask()); |
| 221 } | 230 } |
| 231 #elif defined(USE_X11) |
| 232 static void Signal(base::WaitableEvent* event) { |
| 233 event->Signal(); |
| 234 } |
| 235 #endif |
| 222 | 236 |
| 223 unsigned int BrowserProcessImpl::AddRefModule() { | 237 unsigned int BrowserProcessImpl::AddRefModule() { |
| 224 DCHECK(CalledOnValidThread()); | 238 DCHECK(CalledOnValidThread()); |
| 225 did_start_ = true; | 239 did_start_ = true; |
| 226 module_ref_count_++; | 240 module_ref_count_++; |
| 227 return module_ref_count_; | 241 return module_ref_count_; |
| 228 } | 242 } |
| 229 | 243 |
| 230 unsigned int BrowserProcessImpl::ReleaseModule() { | 244 unsigned int BrowserProcessImpl::ReleaseModule() { |
| 231 DCHECK(CalledOnValidThread()); | 245 DCHECK(CalledOnValidThread()); |
| 232 DCHECK_NE(0u, module_ref_count_); | 246 DCHECK_NE(0u, module_ref_count_); |
| 233 module_ref_count_--; | 247 module_ref_count_--; |
| 234 if (0 == module_ref_count_) { | 248 if (0 == module_ref_count_) { |
| 235 MessageLoop::current()->PostTask( | 249 MessageLoop::current()->PostTask( |
| 236 FROM_HERE, NewRunnableFunction(DidEndMainMessageLoop)); | 250 FROM_HERE, NewRunnableFunction(DidEndMainMessageLoop)); |
| 237 MessageLoop::current()->Quit(); | 251 MessageLoop::current()->Quit(); |
| 238 } | 252 } |
| 239 return module_ref_count_; | 253 return module_ref_count_; |
| 240 } | 254 } |
| 241 | 255 |
| 242 void BrowserProcessImpl::EndSession() { | 256 void BrowserProcessImpl::EndSession() { |
| 243 #if defined(OS_WIN) | 257 #if defined(OS_WIN) || defined(USE_X11) |
| 244 // Notify we are going away. | 258 // Notify we are going away. |
| 245 ::SetEvent(shutdown_event_->handle()); | 259 shutdown_event_->Signal(); |
| 246 #endif | 260 #endif |
| 247 | 261 |
| 248 // Mark all the profiles as clean. | 262 // Mark all the profiles as clean. |
| 249 ProfileManager* pm = profile_manager(); | 263 ProfileManager* pm = profile_manager(); |
| 250 for (ProfileManager::const_iterator i = pm->begin(); i != pm->end(); ++i) | 264 for (ProfileManager::const_iterator i = pm->begin(); i != pm->end(); ++i) |
| 251 (*i)->MarkAsCleanShutdown(); | 265 (*i)->MarkAsCleanShutdown(); |
| 252 | 266 |
| 253 // Tell the metrics service it was cleanly shutdown. | 267 // Tell the metrics service it was cleanly shutdown. |
| 254 MetricsService* metrics = g_browser_process->metrics_service(); | 268 MetricsService* metrics = g_browser_process->metrics_service(); |
| 255 if (metrics && local_state()) { | 269 if (metrics && local_state()) { |
| 256 metrics->RecordCleanShutdown(); | 270 metrics->RecordCleanShutdown(); |
| 257 | 271 |
| 258 metrics->RecordStartOfSessionEnd(); | 272 metrics->RecordStartOfSessionEnd(); |
| 259 | 273 |
| 260 // MetricsService lazily writes to prefs, force it to write now. | 274 // MetricsService lazily writes to prefs, force it to write now. |
| 261 local_state()->SavePersistentPrefs(); | 275 local_state()->SavePersistentPrefs(); |
| 262 } | 276 } |
| 263 | 277 |
| 264 // We must write that the profile and metrics service shutdown cleanly, | 278 // We must write that the profile and metrics service shutdown cleanly, |
| 265 // otherwise on startup we'll think we crashed. So we block until done and | 279 // otherwise on startup we'll think we crashed. So we block until done and |
| 266 // then proceed with normal shutdown. | 280 // then proceed with normal shutdown. |
| 267 g_browser_process->file_thread()->message_loop()->PostTask(FROM_HERE, | 281 #if defined(USE_X11) |
| 282 // Can't run a local loop on linux. Instead create a waitable event. |
| 283 base::WaitableEvent done_writing(false, false); |
| 284 ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, |
| 285 NewRunnableFunction(Signal, &done_writing)); |
| 286 done_writing.TimedWait( |
| 287 base::TimeDelta::FromSeconds(kEndSessionTimeoutSeconds)); |
| 288 #elif defined(OS_WIN) |
| 289 ChromeThread::PostTask(ChromeThread::FILE, FROM_HERE, |
| 268 NewRunnableFunction(PostQuit, MessageLoop::current())); | 290 NewRunnableFunction(PostQuit, MessageLoop::current())); |
| 269 MessageLoop::current()->Run(); | 291 MessageLoop::current()->Run(); |
| 292 #else |
| 293 NOTIMPLEMENTED(); |
| 294 #endif |
| 270 } | 295 } |
| 271 | 296 |
| 272 ResourceDispatcherHost* BrowserProcessImpl::resource_dispatcher_host() { | 297 ResourceDispatcherHost* BrowserProcessImpl::resource_dispatcher_host() { |
| 273 DCHECK(CalledOnValidThread()); | 298 DCHECK(CalledOnValidThread()); |
| 274 if (!created_resource_dispatcher_host_) | 299 if (!created_resource_dispatcher_host_) |
| 275 CreateResourceDispatcherHost(); | 300 CreateResourceDispatcherHost(); |
| 276 return resource_dispatcher_host_.get(); | 301 return resource_dispatcher_host_.get(); |
| 277 } | 302 } |
| 278 | 303 |
| 279 MetricsService* BrowserProcessImpl::metrics_service() { | 304 MetricsService* BrowserProcessImpl::metrics_service() { |
| (...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 783 } | 808 } |
| 784 | 809 |
| 785 void BrowserProcessImpl::OnAutoupdateTimer() { | 810 void BrowserProcessImpl::OnAutoupdateTimer() { |
| 786 if (CanAutorestartForUpdate()) { | 811 if (CanAutorestartForUpdate()) { |
| 787 DLOG(WARNING) << "Detected update. Restarting browser."; | 812 DLOG(WARNING) << "Detected update. Restarting browser."; |
| 788 RestartPersistentInstance(); | 813 RestartPersistentInstance(); |
| 789 } | 814 } |
| 790 } | 815 } |
| 791 | 816 |
| 792 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) | 817 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
| OLD | NEW |