summaryrefslogtreecommitdiffstats
path: root/chrome/common/service_process_util.cc
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-31 19:23:14 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-31 19:23:14 +0000
commit1e1fd49cfd5b770a7bdba08bfbba321748325f31 (patch)
treea7ff5c758fd389beaac2c7ac8ffc4b96635a383f /chrome/common/service_process_util.cc
parentb21d691e4e486071ac8601fee7867c29729faca6 (diff)
downloadchromium_src-1e1fd49cfd5b770a7bdba08bfbba321748325f31.zip
chromium_src-1e1fd49cfd5b770a7bdba08bfbba321748325f31.tar.gz
chromium_src-1e1fd49cfd5b770a7bdba08bfbba321748325f31.tar.bz2
Use named events instead of lock files for service process
Use named events to signal that a service process is running. BUG=52891 TEST=browser_tests --gtest_filter=ServiceProcess* Review URL: http://codereview.chromium.org/3268003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@58041 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/common/service_process_util.cc')
-rw-r--r--chrome/common/service_process_util.cc56
1 files changed, 50 insertions, 6 deletions
diff --git a/chrome/common/service_process_util.cc b/chrome/common/service_process_util.cc
index 4be6991..fe600fc 100644
--- a/chrome/common/service_process_util.cc
+++ b/chrome/common/service_process_util.cc
@@ -10,6 +10,11 @@
#include "chrome/common/chrome_paths.h"
#include "chrome/common/service_process_util.h"
+#if defined(OS_WIN)
+#include "base/scoped_handle_win.h"
+#endif
+
+// TODO(hclam): Split this file for different platforms.
// TODO(hclam): |type| is not used at all. Different types of service process
// should have a different instance of process and channel.
std::string GetServiceProcessChannelName(ServiceProcessType type) {
@@ -32,24 +37,63 @@ std::string GetServiceProcessChannelName(ServiceProcessType type) {
static FilePath GetServiceProcessLockFilePath(ServiceProcessType type) {
FilePath user_data_dir;
PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
- return user_data_dir.Append(FILE_PATH_LITERAL("Service Process.Lock"));
+ 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);
+ std::wstring event_name = path.value();
+ std::replace(event_name.begin(), event_name.end(), '\\', '!');
+ return event_name;
}
-bool CreateServiceProcessLockFile(ServiceProcessType type) {
+// 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;
+#endif
+
+void SignalServiceProcessRunning(ServiceProcessType type) {
+#if defined(OS_WIN)
+ std::wstring event_name = GetServiceProcessEventName(type);
+ service_process_running_event.Set(
+ CreateEvent(NULL, true, true, event_name.c_str()));
+ DCHECK(service_process_running_event.IsValid());
+#else
+ // TODO(hclam): Implement better mechanism for these platform.
const FilePath path = GetServiceProcessLockFilePath(type);
FILE* file = file_util::OpenFile(path, "wb+");
if (!file)
- return false;
+ return;
LOG(INFO) << "Created Service Process lock file: " << path.value();
- return file_util::TruncateFile(file) && file_util::CloseFile(file);
+ file_util::TruncateFile(file) && file_util::CloseFile(file);
+#endif
}
-bool DeleteServiceProcessLockFile(ServiceProcessType type) {
+void SignalServiceProcessStopped(ServiceProcessType type) {
+#if defined(OS_WIN)
+ // Close the handle to the event.
+ service_process_running_event.Close();
+#else
+ // TODO(hclam): Implement better mechanism for these platform.
const FilePath path = GetServiceProcessLockFilePath(type);
- return file_util::Delete(path, false);
+ file_util::Delete(path, false);
+#endif
}
bool CheckServiceProcessRunning(ServiceProcessType type) {
+#if defined(OS_WIN)
+ std::wstring event_name = GetServiceProcessEventName(type);
+ ScopedHandle event(
+ OpenEvent(SYNCHRONIZE | READ_CONTROL, false, event_name.c_str()));
+ if (!event.IsValid())
+ return false;
+ // Check if the event is signaled.
+ return WaitForSingleObject(event, 0) == WAIT_OBJECT_0;
+#else
+ // TODO(hclam): Implement better mechanism for these platform.
const FilePath path = GetServiceProcessLockFilePath(type);
return file_util::PathExists(path);
+#endif
}