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/common | |
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/common')
-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 |
3 files changed, 97 insertions, 0 deletions
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")); +} |