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-12 01:07:24 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-12 01:07:24 +0000
commit50307586363272bb8b133004889772b4919ad8fd (patch)
treea7e73d040cbd3d846e60570abd68c731f85b3e48 /chrome/common/service_process_util.cc
parent7e8a83c5f13b6ed0c5be202f5697efc07cee06ce (diff)
downloadchromium_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/common/service_process_util.cc')
-rw-r--r--chrome/common/service_process_util.cc55
1 files changed, 55 insertions, 0 deletions
diff --git a/chrome/common/service_process_util.cc b/chrome/common/service_process_util.cc
new file mode 100644
index 0000000..4be6991
--- /dev/null
+++ b/chrome/common/service_process_util.cc
@@ -0,0 +1,55 @@
+// 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.
+
+#include "base/file_util.h"
+#include "base/logging.h"
+#include "base/path_service.h"
+#include "base/utf_string_conversions.h"
+#include "chrome/common/chrome_constants.h"
+#include "chrome/common/chrome_paths.h"
+#include "chrome/common/service_process_util.h"
+
+// 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) {
+ FilePath user_data_dir;
+ PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
+
+ // 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");
+ return channel_name;
+}
+
+// Gets the name of the lock file for service process.
+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"));
+}
+
+bool CreateServiceProcessLockFile(ServiceProcessType type) {
+ const FilePath path = GetServiceProcessLockFilePath(type);
+ FILE* file = file_util::OpenFile(path, "wb+");
+ if (!file)
+ return false;
+ LOG(INFO) << "Created Service Process lock file: " << path.value();
+ return file_util::TruncateFile(file) && file_util::CloseFile(file);
+}
+
+bool DeleteServiceProcessLockFile(ServiceProcessType type) {
+ const FilePath path = GetServiceProcessLockFilePath(type);
+ return file_util::Delete(path, false);
+}
+
+bool CheckServiceProcessRunning(ServiceProcessType type) {
+ const FilePath path = GetServiceProcessLockFilePath(type);
+ return file_util::PathExists(path);
+}