diff options
author | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-22 09:37:21 +0000 |
---|---|---|
committer | finnur@chromium.org <finnur@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-09-22 09:37:21 +0000 |
commit | 5c08f22715e7a86971a9878175d897554a0515f7 (patch) | |
tree | ba06ee8246d4ba966d4c4a4ed69a273bc186941d /chrome | |
parent | 1b3e5390c3b3ad2e4ddc3dd6b3412e89332d07cd (diff) | |
download | chromium_src-5c08f22715e7a86971a9878175d897554a0515f7.zip chromium_src-5c08f22715e7a86971a9878175d897554a0515f7.tar.gz chromium_src-5c08f22715e7a86971a9878175d897554a0515f7.tar.bz2 |
Remove one-time flags when restarting after update.
BUG=53407
TEST=SwitchUtilsTest.AddRemoveSwitches
Review URL: http://codereview.chromium.org/3307024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@60161 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/browser_process_impl.cc | 21 | ||||
-rw-r--r-- | chrome/browser/browser_shutdown.cc | 3 | ||||
-rw-r--r-- | chrome/chrome_common.gypi | 2 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 | ||||
-rw-r--r-- | chrome/common/switch_utils.cc | 29 | ||||
-rw-r--r-- | chrome/common/switch_utils.h | 22 | ||||
-rw-r--r-- | chrome/common/switch_utils_unittest.cc | 46 |
7 files changed, 107 insertions, 17 deletions
diff --git a/chrome/browser/browser_process_impl.cc b/chrome/browser/browser_process_impl.cc index 6ed0109..e9f2b83 100644 --- a/chrome/browser/browser_process_impl.cc +++ b/chrome/browser/browser_process_impl.cc @@ -56,6 +56,7 @@ #include "chrome/common/notification_service.h" #include "chrome/common/pref_names.h" #include "chrome/common/url_constants.h" +#include "chrome/common/switch_utils.h" #include "chrome/installer/util/google_update_constants.h" #include "ipc/ipc_logging.h" #include "webkit/database/database_tracker.h" @@ -755,18 +756,7 @@ bool BrowserProcessImpl::CanAutorestartForUpdate() const { Upgrade::IsUpdatePendingRestart(); } -// Switches enumerated here will be removed when a background instance of -// Chrome restarts itself. If your key is designed to only be used once, -// or if it does not make sense when restarting a background instance to -// pick up an automatic update, be sure to add it to this list. -const char* const kSwitchesToRemoveOnAutorestart[] = { - switches::kApp, - switches::kFirstRun, - switches::kImport, - switches::kImportFromFile, - switches::kMakeDefaultBrowser -}; - +// Switches to add when auto-restarting Chrome. const char* const kSwitchesToAddOnAutorestart[] = { switches::kNoStartupWindow }; @@ -778,10 +768,7 @@ void BrowserProcessImpl::RestartPersistentInstance() { std::map<std::string, CommandLine::StringType> switches = old_cl->GetSwitches(); - // Remove the keys that we shouldn't pass through during restart. - for (size_t i = 0; i < arraysize(kSwitchesToRemoveOnAutorestart); i++) { - switches.erase(kSwitchesToRemoveOnAutorestart[i]); - } + switches::RemoveSwitchesForAutostart(&switches); // Append the rest of the switches (along with their values, if any) // to the new command line @@ -796,7 +783,7 @@ void BrowserProcessImpl::RestartPersistentInstance() { } // Ensure that our desired switches are set on the new process. - for (size_t i = 0; i < arraysize(kSwitchesToAddOnAutorestart); i++) { + for (size_t i = 0; i < arraysize(kSwitchesToAddOnAutorestart); ++i) { if (!new_cl->HasSwitch(kSwitchesToAddOnAutorestart[i])) new_cl->AppendSwitch(kSwitchesToAddOnAutorestart[i]); } diff --git a/chrome/browser/browser_shutdown.cc b/chrome/browser/browser_shutdown.cc index 7824149..9231470 100644 --- a/chrome/browser/browser_shutdown.cc +++ b/chrome/browser/browser_shutdown.cc @@ -33,6 +33,7 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/pref_names.h" #include "chrome/common/chrome_plugin_lib.h" +#include "chrome/common/switch_utils.h" #include "net/predictor_api.h" #if defined(OS_WIN) @@ -176,6 +177,8 @@ void Shutdown() { scoped_ptr<CommandLine> new_cl(new CommandLine(old_cl.GetProgram())); std::map<std::string, CommandLine::StringType> switches = old_cl.GetSwitches(); + // Remove the switches that shouldn't persist across restart. + switches::RemoveSwitchesForAutostart(&switches); // Append the old switches to the new command line. for (std::map<std::string, CommandLine::StringType>::const_iterator i = switches.begin(); i != switches.end(); ++i) { diff --git a/chrome/chrome_common.gypi b/chrome/chrome_common.gypi index c16a141..fa59520 100644 --- a/chrome/chrome_common.gypi +++ b/chrome/chrome_common.gypi @@ -114,6 +114,8 @@ 'common/sandbox_policy.h', 'common/serialized_script_value.cc', 'common/serialized_script_value.h', + 'common/switch_utils.cc', + 'common/switch_utils.h', 'common/time_format.cc', 'common/time_format.h', 'common/chrome_version_info.h', diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 28862b9..f9342b8 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1345,6 +1345,7 @@ 'common/sandbox_mac_unittest_helper.h', 'common/sandbox_mac_unittest_helper.mm', 'common/sandbox_mac_system_access_unittest.mm', + 'common/switch_utils_unittest.cc', 'common/thumbnail_score_unittest.cc', 'common/time_format_unittest.cc', 'common/worker_thread_ticker_unittest.cc', diff --git a/chrome/common/switch_utils.cc b/chrome/common/switch_utils.cc new file mode 100644 index 0000000..d202bcb --- /dev/null +++ b/chrome/common/switch_utils.cc @@ -0,0 +1,29 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/common/switch_utils.h" + +#include "chrome/common/chrome_switches.h" + +namespace switches { + +// Switches enumerated here will be removed when a background instance of +// Chrome restarts itself. If your key is designed to only be used once, +// or if it does not make sense when restarting a background instance to +// pick up an automatic update, be sure to add it to this list. +const char* const kSwitchesToRemoveOnAutorestart[] = { + switches::kApp, + switches::kFirstRun, + switches::kImport, + switches::kImportFromFile, + switches::kMakeDefaultBrowser +}; + +void RemoveSwitchesForAutostart( + std::map<std::string, CommandLine::StringType>* switch_list) { + for (size_t i = 0; i < arraysize(kSwitchesToRemoveOnAutorestart); ++i) + switch_list->erase(kSwitchesToRemoveOnAutorestart[i]); +} + +} // namespace switches diff --git a/chrome/common/switch_utils.h b/chrome/common/switch_utils.h new file mode 100644 index 0000000..3c9088b --- /dev/null +++ b/chrome/common/switch_utils.h @@ -0,0 +1,22 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_COMMON_SWITCH_UTILS_H_ +#define CHROME_COMMON_SWITCH_UTILS_H_ +#pragma once + +#include <map> +#include <string> + +#include "base/command_line.h" + +namespace switches { + +// Remove the keys that we shouldn't pass through during restart. +void RemoveSwitchesForAutostart( + std::map<std::string, CommandLine::StringType>* switches); + +} // namespace switches + +#endif // CHROME_COMMON_SWITCH_UTILS_H_ diff --git a/chrome/common/switch_utils_unittest.cc b/chrome/common/switch_utils_unittest.cc new file mode 100644 index 0000000..2c73b17 --- /dev/null +++ b/chrome/common/switch_utils_unittest.cc @@ -0,0 +1,46 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/common/switch_utils.h" + +#include "base/command_line.h" +#include "chrome/common/chrome_switches.h" +#include "testing/gtest/include/gtest/gtest.h" + +TEST(SwitchUtilsTest, RemoveSwitches) { +#if defined(OS_WIN) + // All these command line args (except foo and bar) will + // be removed after RemoveSwitchesForAutostart: + CommandLine cmd_line = CommandLine::FromString( + L"program" + L" --app=http://www.google.com/" + L" --first-run" + L" --import" + L" --import-from-file=c:\\test.html" + L" --make-default-browser" + L" --foo" + L" --bar"); + EXPECT_FALSE(cmd_line.command_line_string().empty()); +#elif defined(OS_POSIX) + const char* argv[] = { + "program", + "--app=http://www.google.com/", + "--first-run", + "--import", + "--import-from-file=c:\\test.html", + "--make-default-browser", + "--foo", + "--bar"}; + CommandLine cmd_line(arraysize(argv), argv); +#endif + + std::map<std::string, CommandLine::StringType> switches = + cmd_line.GetSwitches(); + EXPECT_EQ(7U, switches.size()); + + switches::RemoveSwitchesForAutostart(&switches); + EXPECT_EQ(2U, switches.size()); + EXPECT_TRUE(cmd_line.HasSwitch("foo")); + EXPECT_TRUE(cmd_line.HasSwitch("bar")); +} |