| 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> |
| 8 |
| 7 #include "app/clipboard/clipboard.h" | 9 #include "app/clipboard/clipboard.h" |
| 8 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| 9 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 11 #include "base/path_service.h" | 13 #include "base/path_service.h" |
| 12 #include "base/thread.h" | 14 #include "base/thread.h" |
| 13 #include "base/waitable_event.h" | 15 #include "base/waitable_event.h" |
| 14 #include "chrome/browser/appcache/chrome_appcache_service.h" | 16 #include "chrome/browser/appcache/chrome_appcache_service.h" |
| 15 #include "chrome/browser/browser_list.h" | 17 #include "chrome/browser/browser_list.h" |
| 16 #include "chrome/browser/browser_main.h" | 18 #include "chrome/browser/browser_main.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 | 58 |
| 57 #if defined(OS_WIN) | 59 #if defined(OS_WIN) |
| 58 #include "views/focus/view_storage.h" | 60 #include "views/focus/view_storage.h" |
| 59 #endif | 61 #endif |
| 60 | 62 |
| 61 #if defined(IPC_MESSAGE_LOG_ENABLED) | 63 #if defined(IPC_MESSAGE_LOG_ENABLED) |
| 62 #include "chrome/common/plugin_messages.h" | 64 #include "chrome/common/plugin_messages.h" |
| 63 #include "chrome/common/render_messages.h" | 65 #include "chrome/common/render_messages.h" |
| 64 #endif | 66 #endif |
| 65 | 67 |
| 68 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
| 69 // How often to check if the persistent instance of Chrome needs to restart |
| 70 // to install an update. |
| 71 static const int kUpdateCheckIntervalHours = 6; |
| 72 #endif |
| 73 |
| 66 BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line) | 74 BrowserProcessImpl::BrowserProcessImpl(const CommandLine& command_line) |
| 67 : created_resource_dispatcher_host_(false), | 75 : created_resource_dispatcher_host_(false), |
| 68 created_metrics_service_(false), | 76 created_metrics_service_(false), |
| 69 created_io_thread_(false), | 77 created_io_thread_(false), |
| 70 created_file_thread_(false), | 78 created_file_thread_(false), |
| 71 created_db_thread_(false), | 79 created_db_thread_(false), |
| 72 created_process_launcher_thread_(false), | 80 created_process_launcher_thread_(false), |
| 73 created_profile_manager_(false), | 81 created_profile_manager_(false), |
| 74 created_local_state_(false), | 82 created_local_state_(false), |
| 75 created_icon_manager_(false), | 83 created_icon_manager_(false), |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 void RetainCallee(BrowserProcessImpl* process) {} | 449 void RetainCallee(BrowserProcessImpl* process) {} |
| 442 void ReleaseCallee(BrowserProcessImpl* process) {} | 450 void ReleaseCallee(BrowserProcessImpl* process) {} |
| 443 }; | 451 }; |
| 444 | 452 |
| 445 void BrowserProcessImpl::CheckForInspectorFiles() { | 453 void BrowserProcessImpl::CheckForInspectorFiles() { |
| 446 file_thread()->message_loop()->PostTask | 454 file_thread()->message_loop()->PostTask |
| 447 (FROM_HERE, | 455 (FROM_HERE, |
| 448 NewRunnableMethod(this, &BrowserProcessImpl::DoInspectorFilesCheck)); | 456 NewRunnableMethod(this, &BrowserProcessImpl::DoInspectorFilesCheck)); |
| 449 } | 457 } |
| 450 | 458 |
| 451 #if defined(OS_WIN) | 459 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
| 452 void BrowserProcessImpl::StartAutoupdateTimer() { | 460 void BrowserProcessImpl::StartAutoupdateTimer() { |
| 453 autoupdate_timer_.Start( | 461 autoupdate_timer_.Start( |
| 454 TimeDelta::FromHours(google_update::kUpdateCheckInvervalHours), | 462 TimeDelta::FromHours(kUpdateCheckIntervalHours), |
| 455 this, | 463 this, |
| 456 &BrowserProcessImpl::OnAutoupdateTimer); | 464 &BrowserProcessImpl::OnAutoupdateTimer); |
| 457 } | 465 } |
| 458 #endif // OS_WIN | 466 #endif |
| 459 | 467 |
| 460 #if defined(IPC_MESSAGE_LOG_ENABLED) | 468 #if defined(IPC_MESSAGE_LOG_ENABLED) |
| 461 | 469 |
| 462 void BrowserProcessImpl::SetIPCLoggingEnabled(bool enable) { | 470 void BrowserProcessImpl::SetIPCLoggingEnabled(bool enable) { |
| 463 // First enable myself. | 471 // First enable myself. |
| 464 if (enable) | 472 if (enable) |
| 465 IPC::Logging::current()->Enable(); | 473 IPC::Logging::current()->Enable(); |
| 466 else | 474 else |
| 467 IPC::Logging::current()->Disable(); | 475 IPC::Logging::current()->Disable(); |
| 468 | 476 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 501 bool result = false; | 509 bool result = false; |
| 502 | 510 |
| 503 FilePath inspector_dir; | 511 FilePath inspector_dir; |
| 504 if (PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) { | 512 if (PathService::Get(chrome::DIR_INSPECTOR, &inspector_dir)) { |
| 505 result = file_util::PathExists(inspector_dir); | 513 result = file_util::PathExists(inspector_dir); |
| 506 } | 514 } |
| 507 | 515 |
| 508 have_inspector_files_ = result; | 516 have_inspector_files_ = result; |
| 509 } | 517 } |
| 510 | 518 |
| 511 #if defined(OS_WIN) // Linux doesn't do rename on restart, and Mac is currently | 519 // Mac is currently not supported. |
| 512 // not supported. | 520 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
| 513 | 521 |
| 514 bool BrowserProcessImpl::CanAutorestartForUpdate() const { | 522 bool BrowserProcessImpl::CanAutorestartForUpdate() const { |
| 515 // Check if browser is in the background and if it needs to be restarted to | 523 // Check if browser is in the background and if it needs to be restarted to |
| 516 // apply a pending update. | 524 // apply a pending update. |
| 517 return BrowserList::IsInPersistentMode() && Upgrade::IsUpdatePendingRestart(); | 525 return BrowserList::IsInPersistentMode() && Upgrade::IsUpdatePendingRestart(); |
| 518 } | 526 } |
| 519 | 527 |
| 520 // Switches enumerated here will be removed when a background instance of | 528 // Switches enumerated here will be removed when a background instance of |
| 521 // Chrome restarts itself. If your key is designed to only be used once, | 529 // Chrome restarts itself. If your key is designed to only be used once, |
| 522 // or if it does not make sense when restarting a background instance to | 530 // or if it does not make sense when restarting a background instance to |
| 523 // pick up an automatic update, be sure to add it to this list. | 531 // pick up an automatic update, be sure to add it to this list. |
| 524 const char* const kSwitchesToRemoveOnAutorestart[] = { | 532 const char* const kSwitchesToRemoveOnAutorestart[] = { |
| 525 switches::kApp, | 533 switches::kApp, |
| 526 switches::kFirstRun, | 534 switches::kFirstRun, |
| 527 switches::kImport, | 535 switches::kImport, |
| 528 switches::kImportFromFile, | 536 switches::kImportFromFile, |
| 529 switches::kMakeDefaultBrowser | 537 switches::kMakeDefaultBrowser |
| 530 }; | 538 }; |
| 531 | 539 |
| 532 void BrowserProcessImpl::RestartPersistentInstance() { | 540 void BrowserProcessImpl::RestartPersistentInstance() { |
| 533 CommandLine* old_cl = CommandLine::ForCurrentProcess(); | 541 CommandLine* old_cl = CommandLine::ForCurrentProcess(); |
| 534 CommandLine new_cl(old_cl->GetProgram()); | 542 scoped_ptr<CommandLine> new_cl(new CommandLine(old_cl->GetProgram())); |
| 535 | 543 |
| 536 std::map<std::string, CommandLine::StringType> switches = | 544 std::map<std::string, CommandLine::StringType> switches = |
| 537 old_cl->GetSwitches(); | 545 old_cl->GetSwitches(); |
| 538 | 546 |
| 539 // Remove the keys that we shouldn't pass through during restart. | 547 // Remove the keys that we shouldn't pass through during restart. |
| 540 for (int i = 0; i < arraysize(kSwitchesToRemoveOnAutorestart); i++) { | 548 for (size_t i = 0; i < arraysize(kSwitchesToRemoveOnAutorestart); i++) { |
| 541 switches.erase(kSwitchesToRemoveOnAutorestart[i]); | 549 switches.erase(kSwitchesToRemoveOnAutorestart[i]); |
| 542 } | 550 } |
| 543 | 551 |
| 544 // Append the rest of the switches (along with their values, if any) | 552 // Append the rest of the switches (along with their values, if any) |
| 545 // to the new command line | 553 // to the new command line |
| 546 for (std::map<std::string, CommandLine::StringType>::const_iterator i = | 554 for (std::map<std::string, CommandLine::StringType>::const_iterator i = |
| 547 switches.begin(); i != switches.end(); ++i) { | 555 switches.begin(); i != switches.end(); ++i) { |
| 548 CommandLine::StringType switch_value = i->second; | 556 CommandLine::StringType switch_value = i->second; |
| 549 if (switch_value.length() > 0) { | 557 if (switch_value.length() > 0) { |
| 550 new_cl.AppendSwitchWithValue(i->first, i->second); | 558 new_cl->AppendSwitchWithValue(i->first, i->second); |
| 551 } else { | 559 } else { |
| 552 new_cl.AppendSwitch(i->first); | 560 new_cl->AppendSwitch(i->first); |
| 553 } | 561 } |
| 554 } | 562 } |
| 555 | 563 |
| 556 // TODO(atwilson): Uncomment the following two lines to add the "persistence" | 564 // TODO(atwilson): Uncomment the following two lines to add the "persistence" |
| 557 // switch when the corresponding CL is committed. | 565 // switch when the corresponding CL is committed. |
| 558 // if (!new_cl.HasSwitch(switches::kLongLivedExtensions)) | 566 // if (!new_cl->HasSwitch(switches::kLongLivedExtensions)) |
| 559 // new_cl.AppendSwitch(switches::kLongLivedExtensions); | 567 // new_cl->AppendSwitch(switches::kLongLivedExtensions); |
| 560 | 568 |
| 561 if (Upgrade::RelaunchChromeBrowser(new_cl)) { | 569 DLOG(WARNING) << "Shutting down current instance of the browser."; |
| 562 BrowserList::CloseAllBrowsersAndExit(); | 570 BrowserList::CloseAllBrowsersAndExit(); |
| 563 } else { | 571 |
| 564 DLOG(ERROR) << "Could not restart browser for autoupdate."; | 572 // Transfer ownership to Upgrade. |
| 565 } | 573 Upgrade::SetNewCommandLine(new_cl.release()); |
| 566 } | 574 } |
| 567 | 575 |
| 568 void BrowserProcessImpl::OnAutoupdateTimer() { | 576 void BrowserProcessImpl::OnAutoupdateTimer() { |
| 569 if (CanAutorestartForUpdate()) { | 577 if (CanAutorestartForUpdate()) { |
| 578 DLOG(WARNING) << "Detected update. Restarting browser."; |
| 570 RestartPersistentInstance(); | 579 RestartPersistentInstance(); |
| 571 } | 580 } |
| 572 } | 581 } |
| 573 | 582 |
| 574 #endif | 583 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
| OLD | NEW |