OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/common/service_process_util_posix.h" | 5 #include "chrome/common/service_process_util_posix.h" |
6 | 6 |
7 #include <signal.h> | 7 #include <signal.h> |
8 #include <unistd.h> | 8 #include <unistd.h> |
9 | 9 |
| 10 #include "base/base_paths.h" |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "base/file_util.h" | 12 #include "base/file_util.h" |
12 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/path_service.h" |
13 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
14 #include "chrome/common/auto_start_linux.h" | 16 #include "chrome/common/auto_start_linux.h" |
15 #include "chrome/common/multi_process_lock.h" | 17 #include "chrome/common/multi_process_lock.h" |
16 | 18 |
17 namespace { | 19 namespace { |
18 | 20 |
19 // Attempts to take a lock named |name|. If |waiting| is true then this will | 21 // Attempts to take a lock named |name|. If |waiting| is true then this will |
20 // make multiple attempts to acquire the lock. | 22 // make multiple attempts to acquire the lock. |
21 // Caller is responsible for ownership of the MultiProcessLock. | 23 // Caller is responsible for ownership of the MultiProcessLock. |
22 MultiProcessLock* TakeNamedLock(const std::string& name, bool waiting) { | 24 MultiProcessLock* TakeNamedLock(const std::string& name, bool waiting) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 62 |
61 bool ForceServiceProcessShutdown(const std::string& version, | 63 bool ForceServiceProcessShutdown(const std::string& version, |
62 base::ProcessId process_id) { | 64 base::ProcessId process_id) { |
63 if (kill(process_id, SIGTERM) < 0) { | 65 if (kill(process_id, SIGTERM) < 0) { |
64 PLOG(ERROR) << "kill"; | 66 PLOG(ERROR) << "kill"; |
65 return false; | 67 return false; |
66 } | 68 } |
67 return true; | 69 return true; |
68 } | 70 } |
69 | 71 |
| 72 // Gets the name of the service process IPC channel. |
| 73 // Returns an absolute path as required. |
| 74 IPC::ChannelHandle GetServiceProcessChannel() { |
| 75 FilePath temp_dir; |
| 76 PathService::Get(base::DIR_TEMP, &temp_dir); |
| 77 std::string pipe_name = GetServiceProcessScopedVersionedName("_service_ipc"); |
| 78 std::string pipe_path = temp_dir.Append(pipe_name).value(); |
| 79 return pipe_path; |
| 80 } |
| 81 |
| 82 |
| 83 |
70 bool CheckServiceProcessReady() { | 84 bool CheckServiceProcessReady() { |
71 scoped_ptr<MultiProcessLock> running_lock(TakeServiceRunningLock(false)); | 85 scoped_ptr<MultiProcessLock> running_lock(TakeServiceRunningLock(false)); |
72 return running_lock.get() == NULL; | 86 return running_lock.get() == NULL; |
73 } | 87 } |
74 | 88 |
75 bool ServiceProcessState::TakeSingletonLock() { | 89 bool ServiceProcessState::TakeSingletonLock() { |
76 state_->initializing_lock_.reset(TakeServiceInitializingLock(true)); | 90 state_->initializing_lock_.reset(TakeServiceInitializingLock(true)); |
77 return state_->initializing_lock_.get(); | 91 return state_->initializing_lock_.get(); |
78 } | 92 } |
79 | 93 |
80 bool ServiceProcessState::AddToAutoRun() { | 94 bool ServiceProcessState::AddToAutoRun() { |
81 DCHECK(autorun_command_line_.get()); | 95 DCHECK(autorun_command_line_.get()); |
82 #if defined(GOOGLE_CHROME_BUILD) | 96 #if defined(GOOGLE_CHROME_BUILD) |
83 std::string app_name = "Google Chrome Service"; | 97 std::string app_name = "Google Chrome Service"; |
84 #else // CHROMIUM_BUILD | 98 #else // CHROMIUM_BUILD |
85 std::string app_name = "Chromium Service"; | 99 std::string app_name = "Chromium Service"; |
86 #endif | 100 #endif |
87 return AutoStart::AddApplication( | 101 return AutoStart::AddApplication( |
88 GetServiceProcessScopedName(GetBaseDesktopName()), | 102 GetServiceProcessScopedName(GetBaseDesktopName()), |
89 app_name, | 103 app_name, |
90 autorun_command_line_->command_line_string(), | 104 autorun_command_line_->command_line_string(), |
91 false); | 105 false); |
92 } | 106 } |
93 | 107 |
94 bool ServiceProcessState::RemoveFromAutoRun() { | 108 bool ServiceProcessState::RemoveFromAutoRun() { |
95 return AutoStart::Remove( | 109 return AutoStart::Remove( |
96 GetServiceProcessScopedName(GetBaseDesktopName())); | 110 GetServiceProcessScopedName(GetBaseDesktopName())); |
97 } | 111 } |
OLD | NEW |