diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-12 22:50:39 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-12 22:50:39 +0000 |
commit | 0189bbd4cc569eaec4c6664109659c32fed8e4b7 (patch) | |
tree | f792f823d15a1e806d1b25d0f6d318622db6daf4 /chrome | |
parent | 079487b08bf7867eb7c078b59dec61f142a42df2 (diff) | |
download | chromium_src-0189bbd4cc569eaec4c6664109659c32fed8e4b7.zip chromium_src-0189bbd4cc569eaec4c6664109659c32fed8e4b7.tar.gz chromium_src-0189bbd4cc569eaec4c6664109659c32fed8e4b7.tar.bz2 |
CommandLine: rejigger how initialization works.
I'm attempting to clean up CommandLine.
This change rearranges how initialization is done. I am trying
to eliminate redundant functions; more will come in subsequent changes.
Review URL: http://codereview.chromium.org/273018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28752 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/process_singleton.h | 5 | ||||
-rw-r--r-- | chrome/browser/process_singleton_linux.cc | 7 | ||||
-rw-r--r-- | chrome/browser/process_singleton_linux_uitest.cc | 72 | ||||
-rw-r--r-- | chrome/browser/zygote_main_linux.cc | 5 |
4 files changed, 44 insertions, 45 deletions
diff --git a/chrome/browser/process_singleton.h b/chrome/browser/process_singleton.h index c7fc904..76c9c22 100644 --- a/chrome/browser/process_singleton.h +++ b/chrome/browser/process_singleton.h @@ -18,6 +18,8 @@ #include "base/non_thread_safe.h" #include "base/ref_counted.h" +class CommandLine; + // ProcessSingleton ---------------------------------------------------------- // // This class allows different browser processes to communicate with @@ -53,7 +55,8 @@ class ProcessSingleton : public NonThreadSafe { #if defined(OS_LINUX) // Exposed for testing. We use a timeout on Linux, and in tests we want // this timeout to be short. - NotifyResult NotifyOtherProcessWithTimeout(int timeout_seconds); + NotifyResult NotifyOtherProcessWithTimeout(const CommandLine& command_line, + int timeout_seconds); #endif // Sets ourself up as the singleton instance. diff --git a/chrome/browser/process_singleton_linux.cc b/chrome/browser/process_singleton_linux.cc index 634b68f..bfff289 100644 --- a/chrome/browser/process_singleton_linux.cc +++ b/chrome/browser/process_singleton_linux.cc @@ -627,10 +627,12 @@ ProcessSingleton::~ProcessSingleton() { } ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcess() { - return NotifyOtherProcessWithTimeout(kTimeoutInSeconds); + return NotifyOtherProcessWithTimeout(*CommandLine::ForCurrentProcess(), + kTimeoutInSeconds); } ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcessWithTimeout( + const CommandLine& cmd_line, int timeout_seconds) { int socket; sockaddr_un addr; @@ -666,8 +668,7 @@ ProcessSingleton::NotifyResult ProcessSingleton::NotifyOtherProcessWithTimeout( return PROCESS_NONE; to_send.append(current_dir.value()); - const std::vector<std::string>& argv = - CommandLine::ForCurrentProcess()->argv(); + const std::vector<std::string>& argv = cmd_line.argv(); for (std::vector<std::string>::const_iterator it = argv.begin(); it != argv.end(); ++it) { to_send.push_back(kTokenDelimiter); diff --git a/chrome/browser/process_singleton_linux_uitest.cc b/chrome/browser/process_singleton_linux_uitest.cc index d7f309a..2e775f4 100644 --- a/chrome/browser/process_singleton_linux_uitest.cc +++ b/chrome/browser/process_singleton_linux_uitest.cc @@ -25,46 +25,38 @@ #include "chrome/test/ui/ui_test.h" #include "testing/gtest/include/gtest/gtest.h" -class ProcessSingletonLinuxTest : public UITest { - public: - virtual void SetUp() { - UITest::SetUp(); - old_argv_ = CommandLine::ForCurrentProcess()->argv(); - } - - virtual void TearDown() { - if (!old_argv_.empty()) { - CommandLine::Reset(); - CommandLine::Init(old_argv_); - } - UITest::TearDown(); - } - - protected: - // A helper method to call ProcessSingleton::NotifyOtherProcess(). - // |url| will be added to CommandLine for current process, so that it can be - // sent to browser process by ProcessSingleton::NotifyOtherProcess(). - ProcessSingleton::NotifyResult NotifyOtherProcess(const std::string& url) { - FilePath user_data_dir; - PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); - - std::vector<std::string> argv; - argv.push_back(old_argv_[0]); - argv.push_back(url); - argv.push_back("--" + WideToASCII(switches::kNoProcessSingletonDialog)); - - CommandLine::Reset(); - CommandLine::Init(argv); - - ProcessSingleton process_singleton(user_data_dir); - - // Use a short timeout to keep tests fast. - const int kTimeoutSeconds = 3; - return process_singleton.NotifyOtherProcessWithTimeout(kTimeoutSeconds); - } - - std::vector<std::string> old_argv_; -}; + +namespace { + +typedef UITest ProcessSingletonLinuxTest; + +// A helper method to call ProcessSingleton::NotifyOtherProcess(). +// |url| will be added to CommandLine for current process, so that it can be +// sent to browser process by ProcessSingleton::NotifyOtherProcess(). +ProcessSingleton::NotifyResult NotifyOtherProcess(const std::string& url) { + FilePath user_data_dir; + PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); + + // Hack: mutate the current process's command line so we don't show a dialog. + // Note that this only works if we have no loose values on the command line, + // but that's fine for unit tests. In a UI test we disable error dialogs + // when spawning Chrome, but this test hits the ProcessSingleton directly. + CommandLine* cmd_line = CommandLine::ForCurrentProcess(); + if (!cmd_line->HasSwitch(switches::kNoProcessSingletonDialog)) + cmd_line->AppendSwitch(switches::kNoProcessSingletonDialog); + + CommandLine new_cmd_line(*cmd_line); + new_cmd_line.AppendLooseValue(ASCIIToWide(url)); + + ProcessSingleton process_singleton(user_data_dir); + + // Use a short timeout to keep tests fast. + const int kTimeoutSeconds = 3; + return process_singleton.NotifyOtherProcessWithTimeout(new_cmd_line, + kTimeoutSeconds); +} + +} // namespace // Test if the socket file and symbol link created by ProcessSingletonLinux // are valid. When running this test, the ProcessSingleton object is already diff --git a/chrome/browser/zygote_main_linux.cc b/chrome/browser/zygote_main_linux.cc index eb0ef42..ecf7291 100644 --- a/chrome/browser/zygote_main_linux.cc +++ b/chrome/browser/zygote_main_linux.cc @@ -193,8 +193,11 @@ class Zygote { if (!child) { close(3); // our socket from the browser is in fd 3 Singleton<base::GlobalDescriptors>()->Reset(mapping); + + // Reset the process-wide command line to our new command line. CommandLine::Reset(); - CommandLine::Init(args); + CommandLine::Init(0, NULL); + CommandLine::ForCurrentProcess()->InitFromArgv(args); CommandLine::SetProcTitle(); return true; } |