diff options
author | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-09 03:17:58 +0000 |
---|---|---|
committer | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-09 03:17:58 +0000 |
commit | 7b23c9b94767948f1759e59f779ffe6a09b55c34 (patch) | |
tree | b484b34b2db6e9f35ec90aa79aadefc3c2d9f5c7 /chrome/browser/service | |
parent | c3c1250bec563360a1b4fd409a54c14ec14a4413 (diff) | |
download | chromium_src-7b23c9b94767948f1759e59f779ffe6a09b55c34.zip chromium_src-7b23c9b94767948f1759e59f779ffe6a09b55c34.tar.gz chromium_src-7b23c9b94767948f1759e59f779ffe6a09b55c34.tar.bz2 |
The IPC channel names and event names used by the service process now append the version string so that a browser with the same version only can talk to it.
In addition, the service process writes its version into shared memory (the name of this shared mem does not use a version) and also listens on a shutdown event. This can be used by a newer service process to shutdown an older version when it starts.
BUG=None
TEST=Unittests, with an existing service process running, let chrome autoupdate and then run the service process again. It should kill the old one.
Review URL: http://codereview.chromium.org/3603016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62066 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/service')
-rw-r--r-- | chrome/browser/service/service_process_control.cc | 18 | ||||
-rw-r--r-- | chrome/browser/service/service_process_control_browsertest.cc | 47 |
2 files changed, 49 insertions, 16 deletions
diff --git a/chrome/browser/service/service_process_control.cc b/chrome/browser/service/service_process_control.cc index 22ad863..acccbda 100644 --- a/chrome/browser/service/service_process_control.cc +++ b/chrome/browser/service/service_process_control.cc @@ -27,7 +27,8 @@ class ServiceProcessControl::Launcher Launcher(ServiceProcessControl* process, CommandLine* cmd_line) : process_(process), cmd_line_(cmd_line), - launched_(false) { + launched_(false), + retry_count_(0) { } // Execute the command line to start the process asynchronously. @@ -44,24 +45,26 @@ class ServiceProcessControl::Launcher private: void DoRun(Task* task) { - launched_ = base::LaunchApp(*cmd_line_.get(), false, true, NULL); - + base::LaunchApp(*cmd_line_.get(), false, true, NULL); BrowserThread::PostTask( BrowserThread::IO, FROM_HERE, NewRunnableMethod(this, &Launcher::DoDetectLaunched, task)); } void DoDetectLaunched(Task* task) { - if (CheckServiceProcessRunning()) { + const uint32 kMaxLaunchDetectRetries = 10; + + launched_ = CheckServiceProcessRunning(); + if (launched_ || (retry_count_ >= kMaxLaunchDetectRetries)) { BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, NewRunnableMethod(this, &Launcher::Notify, task)); return; } - + retry_count_++; // If the service process is not launched yet then check again in 2 seconds. const int kDetectLaunchRetry = 2000; - BrowserThread::PostDelayedTask( - BrowserThread::IO, FROM_HERE, + MessageLoop::current()->PostDelayedTask( + FROM_HERE, NewRunnableMethod(this, &Launcher::DoDetectLaunched, task), kDetectLaunchRetry); } @@ -74,6 +77,7 @@ class ServiceProcessControl::Launcher ServiceProcessControl* process_; scoped_ptr<CommandLine> cmd_line_; bool launched_; + uint32 retry_count_; }; // ServiceProcessControl implementation. diff --git a/chrome/browser/service/service_process_control_browsertest.cc b/chrome/browser/service/service_process_control_browsertest.cc index e48a60c..5c59e87 100644 --- a/chrome/browser/service/service_process_control_browsertest.cc +++ b/chrome/browser/service/service_process_control_browsertest.cc @@ -6,6 +6,7 @@ #include "chrome/browser/browser.h" #include "chrome/browser/service/service_process_control.h" #include "chrome/browser/service/service_process_control_manager.h" +#include "chrome/common/chrome_version_info.h" #include "chrome/common/service_process_util.h" #include "chrome/test/in_process_browser_test.h" #include "chrome/test/ui_test_utils.h" @@ -41,20 +42,38 @@ class ServiceProcessControlBrowserTest // connections. ServiceProcessControlManager::instance()->Shutdown(); process_ = NULL; + WaitForShutdown(); + } + + void WaitForShutdown() { + // We will keep trying every second till we hit the terminate timeout. + int retries_left = TestTimeouts::wait_for_terminate_timeout_ms()/1000; MessageLoop::current()->PostDelayedTask( FROM_HERE, NewRunnableMethod(this, - &ServiceProcessControlBrowserTest::DoDetectShutdown), - TestTimeouts::wait_for_terminate_timeout_ms()); + &ServiceProcessControlBrowserTest::DoDetectShutdown, + retries_left), + 1000); ui_test_utils::RunMessageLoop(); } - - void DoDetectShutdown() { - EXPECT_FALSE(CheckServiceProcessRunning()); - // Quit the current message loop. - MessageLoop::current()->PostTask(FROM_HERE, - new MessageLoop::QuitTask()); + void DoDetectShutdown(int retries_left) { + bool service_is_running = CheckServiceProcessRunning(); + if (!retries_left) + EXPECT_FALSE(service_is_running); + if (retries_left && service_is_running) { + retries_left--; + MessageLoop::current()->PostDelayedTask( + FROM_HERE, + NewRunnableMethod(this, + &ServiceProcessControlBrowserTest::DoDetectShutdown, + retries_left), + 1000); + } else { + // Quit the current message loop. + MessageLoop::current()->PostTask(FROM_HERE, + new MessageLoop::QuitTask()); + } } void ProcessControlLaunched() { @@ -112,13 +131,23 @@ IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, LaunchTwice) { // Tests whether disconnecting from the service IPC causes the service process // to die. IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, DieOnDisconnect) { - // Launch the service process the first time. + // Launch the service process. LaunchServiceProcessControl(); // Make sure we are connected to the service process. EXPECT_TRUE(process()->is_connected()); DisconnectAndWaitForShutdown(); } +IN_PROC_BROWSER_TEST_F(ServiceProcessControlBrowserTest, ForceShutdown) { + // Launch the service process. + LaunchServiceProcessControl(); + // Make sure we are connected to the service process. + EXPECT_TRUE(process()->is_connected()); + chrome::VersionInfo version_info; + ForceServiceProcessShutdown(version_info.Version()); + WaitForShutdown(); +} + #endif DISABLE_RUNNABLE_METHOD_REFCOUNT(ServiceProcessControlBrowserTest); |