diff options
author | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-05 19:48:58 +0000 |
---|---|---|
committer | sanjeevr@chromium.org <sanjeevr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-05 19:48:58 +0000 |
commit | de2658d5131e55239517f66c9ee19e3153941599 (patch) | |
tree | 7a262c083c035746b2916c662762e3b2d16fb4f8 | |
parent | ed27fa208601080479f3ef4e85d48c80ec778f97 (diff) | |
download | chromium_src-de2658d5131e55239517f66c9ee19e3153941599.zip chromium_src-de2658d5131e55239517f66c9ee19e3153941599.tar.gz chromium_src-de2658d5131e55239517f66c9ee19e3153941599.tar.bz2 |
Removed the ServiceProcessType enum because a single service process should host all types of services. Also implemeneted a rudimentary singleton mechanism for the service process on Windows.
BUG=None
TEST=Test cloud print proxy and remoting UI.
Review URL: http://codereview.chromium.org/3521012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61549 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/browser_main.cc | 3 | ||||
-rw-r--r-- | chrome/browser/printing/cloud_print/cloud_print_setup_flow.cc | 13 | ||||
-rw-r--r-- | chrome/browser/remoting/remoting_setup_flow.cc | 11 | ||||
-rw-r--r-- | chrome/browser/service/service_process_control.cc | 8 | ||||
-rw-r--r-- | chrome/browser/service/service_process_control.h | 9 | ||||
-rw-r--r-- | chrome/browser/service/service_process_control_browsertest.cc | 3 | ||||
-rw-r--r-- | chrome/browser/service/service_process_control_manager.cc | 4 | ||||
-rw-r--r-- | chrome/browser/service/service_process_control_manager.h | 8 | ||||
-rw-r--r-- | chrome/common/service_process_type.h | 17 | ||||
-rw-r--r-- | chrome/common/service_process_util.cc | 45 | ||||
-rw-r--r-- | chrome/common/service_process_util.h | 16 | ||||
-rw-r--r-- | chrome/service/service_main.cc | 5 | ||||
-rw-r--r-- | chrome/service/service_process.cc | 5 |
13 files changed, 65 insertions, 82 deletions
diff --git a/chrome/browser/browser_main.cc b/chrome/browser/browser_main.cc index 1679475..a922f06 100644 --- a/chrome/browser/browser_main.cc +++ b/chrome/browser/browser_main.cc @@ -81,7 +81,6 @@ #include "chrome/common/net/net_resource_provider.h" #include "chrome/common/pref_names.h" #include "chrome/common/result_codes.h" -#include "chrome/common/service_process_type.h" #include "chrome/installer/util/google_update_settings.h" #include "chrome/installer/util/master_preferences.h" #include "grit/app_locale_settings.h" @@ -1426,7 +1425,7 @@ int BrowserMain(const MainFunctionParams& parameters) { if (parsed_command_line.HasSwitch(switches::kEnableRemoting)) { if (user_prefs->GetBoolean(prefs::kRemotingHasSetupCompleted)) { ServiceProcessControl* control = ServiceProcessControlManager::instance() - ->GetProcessControl(profile, kServiceProcessRemoting); + ->GetProcessControl(profile); control->Launch(NULL); } } diff --git a/chrome/browser/printing/cloud_print/cloud_print_setup_flow.cc b/chrome/browser/printing/cloud_print/cloud_print_setup_flow.cc index 2dfc19f..c6e459a 100644 --- a/chrome/browser/printing/cloud_print/cloud_print_setup_flow.cc +++ b/chrome/browser/printing/cloud_print/cloud_print_setup_flow.cc @@ -34,7 +34,6 @@ #include "chrome/common/net/gaia/google_service_auth_error.h" #include "chrome/common/pref_names.h" #include "chrome/common/service_messages.h" -#include "chrome/common/service_process_type.h" #include "gfx/font.h" #include "grit/locale_settings.h" @@ -93,9 +92,7 @@ class CloudPrintServiceDisableTask DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); process_control_ = - ServiceProcessControlManager::instance()->GetProcessControl( - profile_, - kServiceProcessCloudPrint); + ServiceProcessControlManager::instance()->GetProcessControl(profile_); if (process_control_) { // If the process isn't connected, launch it now. This will run @@ -145,9 +142,7 @@ class CloudPrintServiceRefreshTask DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); process_control_ = - ServiceProcessControlManager::instance()->GetProcessControl( - profile_, - kServiceProcessCloudPrint); + ServiceProcessControlManager::instance()->GetProcessControl(profile_); if (process_control_) { // If the process isn't connected, launch it now. This will run @@ -351,9 +346,7 @@ void CloudPrintSetupFlow::OnClientLoginSuccess( // If we have already connected to the service process then submit the tokens // to it to register the host. process_control_ = - ServiceProcessControlManager::instance()->GetProcessControl( - profile_, - kServiceProcessCloudPrint); + ServiceProcessControlManager::instance()->GetProcessControl(profile_); #if defined(OS_WIN) // TODO(hclam): This call only works on Windows. I need to make it diff --git a/chrome/browser/remoting/remoting_setup_flow.cc b/chrome/browser/remoting/remoting_setup_flow.cc index 856fd72..f2c3c33 100644 --- a/chrome/browser/remoting/remoting_setup_flow.cc +++ b/chrome/browser/remoting/remoting_setup_flow.cc @@ -27,7 +27,6 @@ #include "chrome/common/net/gaia/gaia_constants.h" #include "chrome/common/net/gaia/google_service_auth_error.h" #include "chrome/common/pref_names.h" -#include "chrome/common/service_process_type.h" #include "gfx/font.h" #include "grit/locale_settings.h" @@ -41,10 +40,10 @@ static const wchar_t kDoneIframeXPath[] = L"//iframe[@id='done']"; // is connected or launched. The events are sent back to RemotingSetupFlow // when the dialog is still active. RemotingSetupFlow can detach from this // helper class when the dialog is closed. -class RemotingServiceProcessHelper : - public base::RefCountedThreadSafe<RemotingServiceProcessHelper> { +class RemotingServiceProcessHelper + : public base::RefCountedThreadSafe<RemotingServiceProcessHelper> { public: - RemotingServiceProcessHelper(RemotingSetupFlow* flow) + explicit RemotingServiceProcessHelper(RemotingSetupFlow* flow) : flow_(flow) { } @@ -205,9 +204,7 @@ void RemotingSetupFlow::OnIssueAuthTokenSuccess(const std::string& service, // If we have already connected to the service process then submit the tokens // to it to register the host. process_control_ = - ServiceProcessControlManager::instance()->GetProcessControl( - profile_, - kServiceProcessRemoting); + ServiceProcessControlManager::instance()->GetProcessControl(profile_); if (process_control_->is_connected()) { // TODO(hclam): Need to figure out what to do when the service process is diff --git a/chrome/browser/service/service_process_control.cc b/chrome/browser/service/service_process_control.cc index c3c16d8..6af47c3 100644 --- a/chrome/browser/service/service_process_control.cc +++ b/chrome/browser/service/service_process_control.cc @@ -50,7 +50,7 @@ class ServiceProcessControl::Launcher } void DoDetectLaunched(Task* task) { - if (CheckServiceProcessRunning(kServiceProcessCloudPrint)) { + if (CheckServiceProcessRunning()) { ChromeThread::PostTask(ChromeThread::UI, FROM_HERE, NewRunnableMethod(this, &Launcher::Notify, task)); return; @@ -75,10 +75,8 @@ class ServiceProcessControl::Launcher }; // ServiceProcessControl implementation. -ServiceProcessControl::ServiceProcessControl(Profile* profile, - ServiceProcessType type) +ServiceProcessControl::ServiceProcessControl(Profile* profile) : profile_(profile), - type_(type), message_handler_(NULL) { } @@ -116,7 +114,7 @@ void ServiceProcessControl::Launch(Task* task) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); // If the service process is already running then connects to it. - if (CheckServiceProcessRunning(kServiceProcessCloudPrint)) { + if (CheckServiceProcessRunning()) { ConnectInternal(task); return; } diff --git a/chrome/browser/service/service_process_control.h b/chrome/browser/service/service_process_control.h index 46c2a18..021b669 100644 --- a/chrome/browser/service/service_process_control.h +++ b/chrome/browser/service/service_process_control.h @@ -13,7 +13,6 @@ #include "base/process.h" #include "base/scoped_ptr.h" #include "base/task.h" -#include "chrome/common/service_process_type.h" #include "ipc/ipc_sync_channel.h" class Profile; @@ -43,16 +42,13 @@ class ServiceProcessControl : public IPC::Channel::Sender, virtual void OnGoodDay() = 0; }; - // Construct a ServiceProcessControl with |profile| and a specific |type|. - ServiceProcessControl(Profile* profile, ServiceProcessType type); + // Construct a ServiceProcessControl with |profile|.. + explicit ServiceProcessControl(Profile* profile); virtual ~ServiceProcessControl(); // Return the user profile associated with this service process. Profile* profile() const { return profile_; } - // Return the type of this object. - ServiceProcessType type() const { return type_; } - // Return true if this object is connected to the service. bool is_connected() const { return channel_.get() != NULL; } @@ -114,7 +110,6 @@ class ServiceProcessControl : public IPC::Channel::Sender, void ConnectInternal(Task* task); Profile* profile_; - ServiceProcessType type_; // IPC channel to the service process. scoped_ptr<IPC::SyncChannel> channel_; diff --git a/chrome/browser/service/service_process_control_browsertest.cc b/chrome/browser/service/service_process_control_browsertest.cc index 854a7ab..391f99f 100644 --- a/chrome/browser/service/service_process_control_browsertest.cc +++ b/chrome/browser/service/service_process_control_browsertest.cc @@ -7,7 +7,6 @@ #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/service_process_type.h" class ServiceProcessControlBrowserTest : public InProcessBrowserTest, @@ -16,7 +15,7 @@ class ServiceProcessControlBrowserTest void LaunchServiceProcessControl() { ServiceProcessControl* process = ServiceProcessControlManager::instance()->GetProcessControl( - browser()->profile(), kServiceProcessCloudPrint); + browser()->profile()); process_ = process; // Launch the process asynchronously. diff --git a/chrome/browser/service/service_process_control_manager.cc b/chrome/browser/service/service_process_control_manager.cc index 5750970..5e391a8 100644 --- a/chrome/browser/service/service_process_control_manager.cc +++ b/chrome/browser/service/service_process_control_manager.cc @@ -18,7 +18,7 @@ ServiceProcessControlManager::~ServiceProcessControlManager() { } ServiceProcessControl* ServiceProcessControlManager::GetProcessControl( - Profile* profile, ServiceProcessType type) { + Profile* profile) { DCHECK(ChromeThread::CurrentlyOn(ChromeThread::UI)); // TODO(hclam): We will have different service process for different types of @@ -30,7 +30,7 @@ ServiceProcessControl* ServiceProcessControlManager::GetProcessControl( } // Couldn't find a ServiceProcess so construct a new one. - ServiceProcessControl* process = new ServiceProcessControl(profile, type); + ServiceProcessControl* process = new ServiceProcessControl(profile); process_control_list_.push_back(process); return process; } diff --git a/chrome/browser/service/service_process_control_manager.h b/chrome/browser/service/service_process_control_manager.h index c57f65c..a57c43e 100644 --- a/chrome/browser/service/service_process_control_manager.h +++ b/chrome/browser/service/service_process_control_manager.h @@ -7,8 +7,6 @@ #include <vector> -#include "chrome/common/service_process_type.h" - class Profile; class ServiceProcessControl; @@ -25,12 +23,10 @@ class ServiceProcessControlManager { // Get the ServiceProcess instance corresponding to |profile| and |type|. // If such an instance doesn't exist a new instance is created. // - // There will be at most one ServiceProcess for a |profile| and |type| - // pair. + // There will be at most one ServiceProcess for a |profile|. // // This method should only be accessed on the UI thread. - ServiceProcessControl* GetProcessControl(Profile* profile, - ServiceProcessType type); + ServiceProcessControl* GetProcessControl(Profile* profile); // Destroy all ServiceProcess objects created. void Shutdown(); diff --git a/chrome/common/service_process_type.h b/chrome/common/service_process_type.h deleted file mode 100644 index 7f80ede..0000000 --- a/chrome/common/service_process_type.h +++ /dev/null @@ -1,17 +0,0 @@ -// 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_SERVICE_PROCESS_TYPE_H_ -#define CHROME_COMMON_SERVICE_PROCESS_TYPE_H_ - -// Defines different types of service process. -enum ServiceProcessType { - // A service process that hosts a cloud print proxy. - kServiceProcessCloudPrint, - - // A service process that hosts a remoting host process. - kServiceProcessRemoting, -}; - -#endif // CHROME_COMMON_SERVICE_PROCESS_TYPE_H_ diff --git a/chrome/common/service_process_util.cc b/chrome/common/service_process_util.cc index df3839c..5cf30df 100644 --- a/chrome/common/service_process_util.cc +++ b/chrome/common/service_process_util.cc @@ -32,16 +32,15 @@ std::string GetServiceProcessChannelName() { } // Gets the name of the lock file for service process. -static FilePath GetServiceProcessLockFilePath(ServiceProcessType type) { +static FilePath GetServiceProcessLockFilePath() { FilePath user_data_dir; PathService::Get(chrome::DIR_USER_DATA, &user_data_dir); return user_data_dir.Append(FILE_PATH_LITERAL("Service Process Lock")); } #if defined(OS_WIN) -static std::wstring GetServiceProcessEventName( - ServiceProcessType type) { - FilePath path = GetServiceProcessLockFilePath(type); +static std::wstring GetServiceProcessEventName() { + FilePath path = GetServiceProcessLockFilePath(); std::wstring event_name = path.value(); std::replace(event_name.begin(), event_name.end(), '\\', '!'); return event_name; @@ -49,18 +48,33 @@ static std::wstring GetServiceProcessEventName( // An event that is signaled when a service process is running. This // variable is used only in the service process. -static ScopedHandle service_process_running_event; +static HANDLE g_service_process_running_event; #endif -void SignalServiceProcessRunning(ServiceProcessType type) { +bool TakeServiceProcessSingletonLock() { #if defined(OS_WIN) - std::wstring event_name = GetServiceProcessEventName(type); + std::wstring event_name = GetServiceProcessEventName(); + DCHECK(g_service_process_running_event == NULL); + ScopedHandle service_process_running_event; service_process_running_event.Set( - CreateEvent(NULL, true, true, event_name.c_str())); + CreateEvent(NULL, TRUE, FALSE, event_name.c_str())); + DWORD error = GetLastError(); + if ((error == ERROR_ALREADY_EXISTS) || (error == ERROR_ACCESS_DENIED)) + return false; DCHECK(service_process_running_event.IsValid()); + g_service_process_running_event = service_process_running_event.Take(); +#endif + // TODO(sanjeevr): Implement singleton mechanism for other platforms. + return true; +} + +void SignalServiceProcessRunning() { +#if defined(OS_WIN) + DCHECK(g_service_process_running_event != NULL); + SetEvent(g_service_process_running_event); #else // TODO(hclam): Implement better mechanism for these platform. - const FilePath path = GetServiceProcessLockFilePath(type); + const FilePath path = GetServiceProcessLockFilePath(); FILE* file = file_util::OpenFile(path, "wb+"); if (!file) return; @@ -69,20 +83,21 @@ void SignalServiceProcessRunning(ServiceProcessType type) { #endif } -void SignalServiceProcessStopped(ServiceProcessType type) { +void SignalServiceProcessStopped() { #if defined(OS_WIN) // Close the handle to the event. - service_process_running_event.Close(); + CloseHandle(g_service_process_running_event); + g_service_process_running_event = NULL; #else // TODO(hclam): Implement better mechanism for these platform. - const FilePath path = GetServiceProcessLockFilePath(type); + const FilePath path = GetServiceProcessLockFilePath(); file_util::Delete(path, false); #endif } -bool CheckServiceProcessRunning(ServiceProcessType type) { +bool CheckServiceProcessRunning() { #if defined(OS_WIN) - std::wstring event_name = GetServiceProcessEventName(type); + std::wstring event_name = GetServiceProcessEventName(); ScopedHandle event( OpenEvent(SYNCHRONIZE | READ_CONTROL, false, event_name.c_str())); if (!event.IsValid()) @@ -91,7 +106,7 @@ bool CheckServiceProcessRunning(ServiceProcessType type) { return WaitForSingleObject(event, 0) == WAIT_OBJECT_0; #else // TODO(hclam): Implement better mechanism for these platform. - const FilePath path = GetServiceProcessLockFilePath(type); + const FilePath path = GetServiceProcessLockFilePath(); return file_util::PathExists(path); #endif } diff --git a/chrome/common/service_process_util.h b/chrome/common/service_process_util.h index 37ea33c..5f54f75 100644 --- a/chrome/common/service_process_util.h +++ b/chrome/common/service_process_util.h @@ -7,8 +7,6 @@ #include <string> -#include "chrome/common/service_process_type.h" - class Profile; // Return the IPC channel to connect to the service process. @@ -19,14 +17,20 @@ std::string GetServiceProcessChannelName(); // The following methods are used as a mechanism to signal a service process // is running properly and all initialized. // + +// Tries to become the sole service process for the current user data dir. +// Returns false is another service process is already running. +bool TakeServiceProcessSingletonLock(); + // Signal that the service process is running. // This method is called when the service process is running and initialized. -void SignalServiceProcessRunning(ServiceProcessType type); +void SignalServiceProcessRunning(); // Signal that the service process is stopped. -void SignalServiceProcessStopped(ServiceProcessType type); +void SignalServiceProcessStopped(); -// This method checks that if the service process is running. -bool CheckServiceProcessRunning(ServiceProcessType type); +// This method checks that if the service process is running (ready to receive +// IPC commands). +bool CheckServiceProcessRunning(); #endif // CHROME_COMMON_SERVICE_PROCESS_UTIL_H_ diff --git a/chrome/service/service_main.cc b/chrome/service/service_main.cc index f71c405..b0765fa 100644 --- a/chrome/service/service_main.cc +++ b/chrome/service/service_main.cc @@ -9,11 +9,16 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/main_function_params.h" #include "chrome/common/sandbox_policy.h" +#include "chrome/common/service_process_util.h" #include "chrome/service/cloud_print/cloud_print_proxy.h" #include "chrome/service/service_process.h" // Mainline routine for running as the service process. int ServiceProcessMain(const MainFunctionParams& parameters) { + // If there is already a service process running, quit now. + if (!TakeServiceProcessSingletonLock()) + return 0; + MessageLoopForUI main_message_loop; if (parameters.command_line_.HasSwitch(switches::kWaitForDebugger)) { DebugUtil::WaitForDebugger(60, true); diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc index 821bfd2..86d787b 100644 --- a/chrome/service/service_process.cc +++ b/chrome/service/service_process.cc @@ -19,7 +19,6 @@ #include "chrome/common/chrome_switches.h" #include "chrome/common/json_pref_store.h" #include "chrome/common/pref_names.h" -#include "chrome/common/service_process_type.h" #include "chrome/common/service_process_util.h" #include "chrome/service/cloud_print/cloud_print_proxy.h" #include "chrome/service/service_ipc_server.h" @@ -113,7 +112,7 @@ bool ServiceProcess::Initialize(MessageLoop* message_loop, // After the IPC server has started we signal that the service process is // running. - SignalServiceProcessRunning(kServiceProcessCloudPrint); + SignalServiceProcessRunning(); // See if we need to stay running. ScheduleShutdownCheck(); @@ -142,7 +141,7 @@ bool ServiceProcess::Teardown() { network_change_notifier_.reset(); // Delete the service process lock file when it shuts down. - SignalServiceProcessStopped(kServiceProcessCloudPrint); + SignalServiceProcessStopped(); return true; } |