summaryrefslogtreecommitdiffstats
path: root/chrome/common/service_process_util_posix.cc
blob: e547223865decae38b3fd719bbb2f8fea2f75cd0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// 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 "chrome/common/service_process_util.h"

#include "base/file_util.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/chrome_version_info.h"

namespace {

// Gets the name of the lock file for service process.
FilePath GetServiceProcessLockFilePath() {
  FilePath user_data_dir;
  PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
  chrome::VersionInfo version_info;
  std::string lock_file_name = version_info.Version() + "Service Process Lock";
  return user_data_dir.Append(lock_file_name);
}

}  // namespace

bool ForceServiceProcessShutdown(const std::string& version) {
  NOTIMPLEMENTED();
  return false;
}

bool CheckServiceProcessReady() {
  const FilePath path = GetServiceProcessLockFilePath();
  return file_util::PathExists(path);
}

struct ServiceProcessState::StateData {
  // No state yet for Posix.
};

bool ServiceProcessState::TakeSingletonLock() {
  // TODO(sanjeevr): Implement singleton mechanism for POSIX.
  NOTIMPLEMENTED();
  return true;
}

void ServiceProcessState::SignalReady(Task* shutdown_task) {
  // TODO(hclam): Implement better mechanism for these platform.
  // Also we need to save shutdown task. For now we just delete the shutdown
  // task because we have not way to listen for shutdown requests.
  delete shutdown_task;
  const FilePath path = GetServiceProcessLockFilePath();
  FILE* file = file_util::OpenFile(path, "wb+");
  if (!file)
    return;
  VLOG(1) << "Created Service Process lock file: " << path.value();
  file_util::TruncateFile(file) && file_util::CloseFile(file);
}

void ServiceProcessState::SignalStopped() {
  const FilePath path = GetServiceProcessLockFilePath();
  file_util::Delete(path, false);
  shared_mem_service_data_.reset();
}

bool ServiceProcessState::AddToAutoRun() {
  NOTIMPLEMENTED();
  return false;
}

bool ServiceProcessState::RemoveFromAutoRun() {
  NOTIMPLEMENTED();
  return false;
}

void ServiceProcessState::TearDownState() {
}

bool ServiceProcessState::ShouldHandleOtherVersion() {
  // On POSIX, the shared memory is a file in disk. We may have a stale file
  // lying around from a previous run. So the check is not reliable.
  return false;
}