Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(493)

Side by Side Diff: chrome/common/service_process_util_posix.cc

Issue 9131016: Cloud Print Policy - service side enforcement, Mac browser tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More tweaks Created 8 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/eintr_wrapper.h" 9 #include "base/eintr_wrapper.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
11 #include "base/synchronization/waitable_event.h" 11 #include "base/synchronization/waitable_event.h"
12 #include "chrome/common/multi_process_lock.h"
12 13
13 namespace { 14 namespace {
14 int g_signal_socket = -1; 15 int g_signal_socket = -1;
15 } 16 }
16 17
18 // Attempts to take a lock named |name|. If |waiting| is true then this will
19 // make multiple attempts to acquire the lock.
20 // Caller is responsible for ownership of the MultiProcessLock.
21 MultiProcessLock* TakeNamedLock(const std::string& name, bool waiting) {
22 scoped_ptr<MultiProcessLock> lock(MultiProcessLock::Create(name));
23 if (lock == NULL) return NULL;
24 bool got_lock = false;
25 for (int i = 0; i < 10; ++i) {
26 if (lock->TryLock()) {
27 got_lock = true;
28 break;
29 }
30 if (!waiting) break;
31 base::PlatformThread::Sleep(100 * i);
32 }
33 if (!got_lock) {
34 lock.reset();
35 }
36 return lock.release();
37 }
38
17 ServiceProcessTerminateMonitor::ServiceProcessTerminateMonitor( 39 ServiceProcessTerminateMonitor::ServiceProcessTerminateMonitor(
18 const base::Closure& terminate_task) 40 const base::Closure& terminate_task)
19 : terminate_task_(terminate_task) { 41 : terminate_task_(terminate_task) {
20 } 42 }
21 43
22 ServiceProcessTerminateMonitor::~ServiceProcessTerminateMonitor() { 44 ServiceProcessTerminateMonitor::~ServiceProcessTerminateMonitor() {
23 } 45 }
24 46
25 void ServiceProcessTerminateMonitor::OnFileCanReadWithoutBlocking(int fd) { 47 void ServiceProcessTerminateMonitor::OnFileCanReadWithoutBlocking(int fd) {
26 if (!terminate_task_.is_null()) { 48 if (!terminate_task_.is_null()) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 signal_ready.Wait(); 186 signal_ready.Wait();
165 return success; 187 return success;
166 } 188 }
167 189
168 void ServiceProcessState::TearDownState() { 190 void ServiceProcessState::TearDownState() {
169 if (state_) { 191 if (state_) {
170 state_->Release(); 192 state_->Release();
171 state_ = NULL; 193 state_ = NULL;
172 } 194 }
173 } 195 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698