| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base_paths.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/threading/platform_thread.h" | 15 #include "base/threading/platform_thread.h" |
| 16 #include "chrome/common/auto_start_linux.h" | 16 #include "chrome/common/auto_start_linux.h" |
| 17 #include "chrome/common/multi_process_lock.h" | 17 #include "chrome/common/multi_process_lock.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 | 20 |
| 21 // Attempts to take a lock named |name|. If |waiting| is true then this will | |
| 22 // make multiple attempts to acquire the lock. | |
| 23 // Caller is responsible for ownership of the MultiProcessLock. | |
| 24 MultiProcessLock* TakeNamedLock(const std::string& name, bool waiting) { | |
| 25 scoped_ptr<MultiProcessLock> lock(MultiProcessLock::Create(name)); | |
| 26 if (lock == NULL) return NULL; | |
| 27 bool got_lock = false; | |
| 28 for (int i = 0; i < 10; ++i) { | |
| 29 if (lock->TryLock()) { | |
| 30 got_lock = true; | |
| 31 break; | |
| 32 } | |
| 33 if (!waiting) break; | |
| 34 base::PlatformThread::Sleep(100 * i); | |
| 35 } | |
| 36 if (!got_lock) { | |
| 37 lock.reset(); | |
| 38 } | |
| 39 return lock.release(); | |
| 40 } | |
| 41 | |
| 42 MultiProcessLock* TakeServiceInitializingLock(bool waiting) { | 21 MultiProcessLock* TakeServiceInitializingLock(bool waiting) { |
| 43 std::string lock_name = | 22 std::string lock_name = |
| 44 GetServiceProcessScopedName("_service_initializing"); | 23 GetServiceProcessScopedName("_service_initializing"); |
| 45 return TakeNamedLock(lock_name, waiting); | 24 return TakeNamedLock(lock_name, waiting); |
| 46 } | 25 } |
| 47 | 26 |
| 48 std::string GetBaseDesktopName() { | 27 std::string GetBaseDesktopName() { |
| 49 #if defined(GOOGLE_CHROME_BUILD) | 28 #if defined(GOOGLE_CHROME_BUILD) |
| 50 return "google-chrome-service.desktop"; | 29 return "google-chrome-service.desktop"; |
| 51 #else // CHROMIUM_BUILD | 30 #else // CHROMIUM_BUILD |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 GetServiceProcessScopedName(GetBaseDesktopName()), | 81 GetServiceProcessScopedName(GetBaseDesktopName()), |
| 103 app_name, | 82 app_name, |
| 104 autorun_command_line_->GetCommandLineString(), | 83 autorun_command_line_->GetCommandLineString(), |
| 105 false); | 84 false); |
| 106 } | 85 } |
| 107 | 86 |
| 108 bool ServiceProcessState::RemoveFromAutoRun() { | 87 bool ServiceProcessState::RemoveFromAutoRun() { |
| 109 return AutoStart::Remove( | 88 return AutoStart::Remove( |
| 110 GetServiceProcessScopedName(GetBaseDesktopName())); | 89 GetServiceProcessScopedName(GetBaseDesktopName())); |
| 111 } | 90 } |
| OLD | NEW |