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" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 #include "chrome/browser/tab_closeable_state_watcher.h" | 49 #include "chrome/browser/tab_closeable_state_watcher.h" |
50 #include "chrome/common/chrome_constants.h" | 50 #include "chrome/common/chrome_constants.h" |
51 #include "chrome/common/chrome_paths.h" | 51 #include "chrome/common/chrome_paths.h" |
52 #include "chrome/common/chrome_switches.h" | 52 #include "chrome/common/chrome_switches.h" |
53 #include "chrome/common/extensions/extension_resource.h" | 53 #include "chrome/common/extensions/extension_resource.h" |
54 #include "chrome/common/extensions/extension_l10n_util.h" | 54 #include "chrome/common/extensions/extension_l10n_util.h" |
55 #include "chrome/common/json_pref_store.h" | 55 #include "chrome/common/json_pref_store.h" |
56 #include "chrome/common/notification_service.h" | 56 #include "chrome/common/notification_service.h" |
57 #include "chrome/common/pref_names.h" | 57 #include "chrome/common/pref_names.h" |
58 #include "chrome/common/url_constants.h" | 58 #include "chrome/common/url_constants.h" |
| 59 #include "chrome/common/switch_utils.h" |
59 #include "chrome/installer/util/google_update_constants.h" | 60 #include "chrome/installer/util/google_update_constants.h" |
60 #include "ipc/ipc_logging.h" | 61 #include "ipc/ipc_logging.h" |
61 #include "webkit/database/database_tracker.h" | 62 #include "webkit/database/database_tracker.h" |
62 | 63 |
63 #if defined(OS_WIN) | 64 #if defined(OS_WIN) |
64 #include "views/focus/view_storage.h" | 65 #include "views/focus/view_storage.h" |
65 #endif | 66 #endif |
66 | 67 |
67 #if defined(IPC_MESSAGE_LOG_ENABLED) | 68 #if defined(IPC_MESSAGE_LOG_ENABLED) |
68 #include "chrome/common/plugin_messages.h" | 69 #include "chrome/common/plugin_messages.h" |
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
747 // Mac is currently not supported. | 748 // Mac is currently not supported. |
748 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) | 749 #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
749 | 750 |
750 bool BrowserProcessImpl::CanAutorestartForUpdate() const { | 751 bool BrowserProcessImpl::CanAutorestartForUpdate() const { |
751 // Check if browser is in the background and if it needs to be restarted to | 752 // Check if browser is in the background and if it needs to be restarted to |
752 // apply a pending update. | 753 // apply a pending update. |
753 return BrowserList::size() == 0 && BrowserList::WillKeepAlive() && | 754 return BrowserList::size() == 0 && BrowserList::WillKeepAlive() && |
754 Upgrade::IsUpdatePendingRestart(); | 755 Upgrade::IsUpdatePendingRestart(); |
755 } | 756 } |
756 | 757 |
757 // Switches enumerated here will be removed when a background instance of | 758 // Switches to add when auto-restarting Chrome. |
758 // Chrome restarts itself. If your key is designed to only be used once, | |
759 // or if it does not make sense when restarting a background instance to | |
760 // pick up an automatic update, be sure to add it to this list. | |
761 const char* const kSwitchesToRemoveOnAutorestart[] = { | |
762 switches::kApp, | |
763 switches::kFirstRun, | |
764 switches::kImport, | |
765 switches::kImportFromFile, | |
766 switches::kMakeDefaultBrowser | |
767 }; | |
768 | |
769 const char* const kSwitchesToAddOnAutorestart[] = { | 759 const char* const kSwitchesToAddOnAutorestart[] = { |
770 switches::kNoStartupWindow | 760 switches::kNoStartupWindow |
771 }; | 761 }; |
772 | 762 |
773 void BrowserProcessImpl::RestartPersistentInstance() { | 763 void BrowserProcessImpl::RestartPersistentInstance() { |
774 CommandLine* old_cl = CommandLine::ForCurrentProcess(); | 764 CommandLine* old_cl = CommandLine::ForCurrentProcess(); |
775 scoped_ptr<CommandLine> new_cl(new CommandLine(old_cl->GetProgram())); | 765 scoped_ptr<CommandLine> new_cl(new CommandLine(old_cl->GetProgram())); |
776 | 766 |
777 std::map<std::string, CommandLine::StringType> switches = | 767 std::map<std::string, CommandLine::StringType> switches = |
778 old_cl->GetSwitches(); | 768 old_cl->GetSwitches(); |
779 | 769 |
780 // Remove the keys that we shouldn't pass through during restart. | 770 switches::RemoveSwitchesForAutostart(&switches); |
781 for (size_t i = 0; i < arraysize(kSwitchesToRemoveOnAutorestart); i++) { | |
782 switches.erase(kSwitchesToRemoveOnAutorestart[i]); | |
783 } | |
784 | 771 |
785 // Append the rest of the switches (along with their values, if any) | 772 // Append the rest of the switches (along with their values, if any) |
786 // to the new command line | 773 // to the new command line |
787 for (std::map<std::string, CommandLine::StringType>::const_iterator i = | 774 for (std::map<std::string, CommandLine::StringType>::const_iterator i = |
788 switches.begin(); i != switches.end(); ++i) { | 775 switches.begin(); i != switches.end(); ++i) { |
789 CommandLine::StringType switch_value = i->second; | 776 CommandLine::StringType switch_value = i->second; |
790 if (switch_value.length() > 0) { | 777 if (switch_value.length() > 0) { |
791 new_cl->AppendSwitchNative(i->first, i->second); | 778 new_cl->AppendSwitchNative(i->first, i->second); |
792 } else { | 779 } else { |
793 new_cl->AppendSwitch(i->first); | 780 new_cl->AppendSwitch(i->first); |
794 } | 781 } |
795 } | 782 } |
796 | 783 |
797 // Ensure that our desired switches are set on the new process. | 784 // Ensure that our desired switches are set on the new process. |
798 for (size_t i = 0; i < arraysize(kSwitchesToAddOnAutorestart); i++) { | 785 for (size_t i = 0; i < arraysize(kSwitchesToAddOnAutorestart); ++i) { |
799 if (!new_cl->HasSwitch(kSwitchesToAddOnAutorestart[i])) | 786 if (!new_cl->HasSwitch(kSwitchesToAddOnAutorestart[i])) |
800 new_cl->AppendSwitch(kSwitchesToAddOnAutorestart[i]); | 787 new_cl->AppendSwitch(kSwitchesToAddOnAutorestart[i]); |
801 } | 788 } |
802 | 789 |
803 DLOG(WARNING) << "Shutting down current instance of the browser."; | 790 DLOG(WARNING) << "Shutting down current instance of the browser."; |
804 BrowserList::CloseAllBrowsersAndExit(); | 791 BrowserList::CloseAllBrowsersAndExit(); |
805 | 792 |
806 // Transfer ownership to Upgrade. | 793 // Transfer ownership to Upgrade. |
807 Upgrade::SetNewCommandLine(new_cl.release()); | 794 Upgrade::SetNewCommandLine(new_cl.release()); |
808 } | 795 } |
809 | 796 |
810 void BrowserProcessImpl::OnAutoupdateTimer() { | 797 void BrowserProcessImpl::OnAutoupdateTimer() { |
811 if (CanAutorestartForUpdate()) { | 798 if (CanAutorestartForUpdate()) { |
812 DLOG(WARNING) << "Detected update. Restarting browser."; | 799 DLOG(WARNING) << "Detected update. Restarting browser."; |
813 RestartPersistentInstance(); | 800 RestartPersistentInstance(); |
814 } | 801 } |
815 } | 802 } |
816 | 803 |
817 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) | 804 #endif // (defined(OS_WIN) || defined(OS_LINUX)) && !defined(OS_CHROMEOS) |
OLD | NEW |