diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-12 01:07:24 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-12 01:07:24 +0000 |
commit | 50307586363272bb8b133004889772b4919ad8fd (patch) | |
tree | a7e73d040cbd3d846e60570abd68c731f85b3e48 /chrome/service | |
parent | 7e8a83c5f13b6ed0c5be202f5697efc07cee06ce (diff) | |
download | chromium_src-50307586363272bb8b133004889772b4919ad8fd.zip chromium_src-50307586363272bb8b133004889772b4919ad8fd.tar.gz chromium_src-50307586363272bb8b133004889772b4919ad8fd.tar.bz2 |
ServiceProcessControl to launch a service process and communicate through IPC.
Added two class for use with service process:
ServiceProcessControl
Used by the browser to launch and connect to the service process, also used
to receive messages from the service process.
ServiceProcessControlManager
A singleton to manage multiple ServicProcessControl.
BUG=50244
TEST=browser_tests --gtest_filter=ServiceProcess*
Review URL: http://codereview.chromium.org/3032061
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@55826 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/service')
-rw-r--r-- | chrome/service/service_ipc_server.cc | 9 | ||||
-rw-r--r-- | chrome/service/service_ipc_server.h | 2 | ||||
-rw-r--r-- | chrome/service/service_process.cc | 38 | ||||
-rw-r--r-- | chrome/service/service_process.h | 5 |
4 files changed, 40 insertions, 14 deletions
diff --git a/chrome/service/service_ipc_server.cc b/chrome/service/service_ipc_server.cc index 2199d00..116374f 100644 --- a/chrome/service/service_ipc_server.cc +++ b/chrome/service/service_ipc_server.cc @@ -66,6 +66,8 @@ void ServiceIPCServer::OnMessageReceived(const IPC::Message& msg) { OnEnableCloudPrintProxyWithTokens) IPC_MESSAGE_HANDLER(ServiceMsg_DisableCloudPrintProxy, OnDisableCloudPrintProxy) + IPC_MESSAGE_HANDLER(ServiceMsg_Hello, OnHello); + IPC_MESSAGE_HANDLER(ServiceMsg_Shutdown, OnShutdown); IPC_END_MESSAGE_MAP() } @@ -83,3 +85,10 @@ void ServiceIPCServer::OnDisableCloudPrintProxy() { g_service_process->GetCloudPrintProxy()->DisableForUser(); } +void ServiceIPCServer::OnHello() { + channel_->Send(new ServiceHostMsg_GoodDay()); +} + +void ServiceIPCServer::OnShutdown() { + g_service_process->Shutdown(); +} diff --git a/chrome/service/service_ipc_server.h b/chrome/service/service_ipc_server.h index 9e9b355..521830e 100644 --- a/chrome/service/service_ipc_server.h +++ b/chrome/service/service_ipc_server.h @@ -41,6 +41,8 @@ class ServiceIPCServer : public IPC::Channel::Listener, void OnEnableCloudPrintProxyWithTokens(const std::string& cloud_print_token, const std::string& talk_token); void OnDisableCloudPrintProxy(); + void OnHello(); + void OnShutdown(); std::string channel_name_; scoped_ptr<IPC::SyncChannel> channel_; diff --git a/chrome/service/service_process.cc b/chrome/service/service_process.cc index fbd9c8d..77e8cf0 100644 --- a/chrome/service/service_process.cc +++ b/chrome/service/service_process.cc @@ -11,6 +11,8 @@ #include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_paths.h" #include "chrome/common/json_pref_store.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" #include "net/base/network_change_notifier.h" @@ -62,22 +64,24 @@ bool ServiceProcess::Initialize(MessageLoop* message_loop) { service_prefs_.reset(new JsonPrefStore(pref_path, file_thread_->message_loop_proxy())); service_prefs_->ReadPrefs(); - // TODO(sanjeevr): We need to actually figure out the right way to determine - // a channel name. The below is to facilitate testing only. -#if defined(OS_WIN) - std::string channel_name = WideToUTF8(user_data_dir.value()); -#elif defined(OS_POSIX) - std::string channel_name = user_data_dir.value(); -#endif // defined(OS_WIN) - - std::replace(channel_name.begin(), channel_name.end(), '\\', '!'); - channel_name.append("_service_ipc"); - ipc_server_.reset(new ServiceIPCServer(channel_name)); + + // TODO(hclam): Each type of service process should has it own instance of + // process and thus channel, but now we have only one process for all types + // so the type parameter doesn't matter now. + LOG(INFO) << "Starting Service Process IPC Server"; + ipc_server_.reset(new ServiceIPCServer( + GetServiceProcessChannelName(kServiceProcessCloudPrint))); ipc_server_->Init(); - return true; + + // After the IPC server has started we can create the lock file to indicate + // that we have started. + bool ret = CreateServiceProcessLockFile(kServiceProcessCloudPrint); + DCHECK(ret) << "Failed to create service process lock file."; + return ret; } bool ServiceProcess::Teardown() { + // TODO(hclam): Remove this as this looks like dead code. if (service_prefs_.get()) { service_prefs_->WritePrefs(); service_prefs_.reset(); @@ -98,7 +102,15 @@ bool ServiceProcess::Teardown() { // might use it have been shut down. network_change_notifier_.reset(); - return true; + // Delete the service process lock file when it shuts down. + bool ret = DeleteServiceProcessLockFile(kServiceProcessCloudPrint); + DCHECK(ret) << "Failed to delete service process lock file."; + return ret; +} + +void ServiceProcess::Shutdown() { + // Quit the main message loop. + main_message_loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask()); } CloudPrintProxy* ServiceProcess::GetCloudPrintProxy() { diff --git a/chrome/service/service_process.h b/chrome/service/service_process.h index d4babce..55c7c19 100644 --- a/chrome/service/service_process.h +++ b/chrome/service/service_process.h @@ -65,6 +65,9 @@ class ServiceProcess { return &shutdown_event_; } + // Shutdown the service process. This is likely triggered by a IPC message. + void Shutdown(); + CloudPrintProxy* GetCloudPrintProxy(); #if defined(ENABLE_REMOTING) @@ -116,7 +119,7 @@ class ServiceProcess { // An event that will be signalled when we shutdown. base::WaitableEvent shutdown_event_; - // The main message loop for the service process. + // Pointer to the main message loop that host this object. MessageLoop* main_message_loop_; DISALLOW_COPY_AND_ASSIGN(ServiceProcess); |