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