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

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

Issue 6126002: Remove base/scoped_handle_win.h stub and fix up all callers to use the new location and namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: linux_view fix Created 9 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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.h" 5 #include "chrome/common/service_process_util.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/scoped_handle_win.h"
12 #include "base/string16.h" 11 #include "base/string16.h"
13 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
14 #include "base/win/object_watcher.h" 13 #include "base/win/object_watcher.h"
14 #include "base/win/scoped_handle.h"
brettw 2011/01/07 18:03:46 Got some extra indentation.
tfarina 2011/01/07 22:23:08 Done.
15 #include "base/win/win_util.h" 15 #include "base/win/win_util.h"
16 #include "chrome/common/chrome_switches.h" 16 #include "chrome/common/chrome_switches.h"
17 17
18 namespace { 18 namespace {
19 19
20 string16 GetServiceProcessReadyEventName() { 20 string16 GetServiceProcessReadyEventName() {
21 return UTF8ToWide( 21 return UTF8ToWide(
22 GetServiceProcessScopedVersionedName("_service_ready")); 22 GetServiceProcessScopedVersionedName("_service_ready"));
23 } 23 }
24 24
(...skipping 15 matching lines...) Expand all
40 watcher_.StartWatching(shutdown_event_.Get(), this); 40 watcher_.StartWatching(shutdown_event_.Get(), this);
41 } 41 }
42 42
43 // base::ObjectWatcher::Delegate implementation. 43 // base::ObjectWatcher::Delegate implementation.
44 virtual void OnObjectSignaled(HANDLE object) { 44 virtual void OnObjectSignaled(HANDLE object) {
45 shutdown_task_->Run(); 45 shutdown_task_->Run();
46 shutdown_task_.reset(); 46 shutdown_task_.reset();
47 } 47 }
48 48
49 private: 49 private:
50 ScopedHandle shutdown_event_; 50 base::win::ScopedHandle shutdown_event_;
51 base::win::ObjectWatcher watcher_; 51 base::win::ObjectWatcher watcher_;
52 scoped_ptr<Task> shutdown_task_; 52 scoped_ptr<Task> shutdown_task_;
53 }; 53 };
54 54
55 } // namespace 55 } // namespace
56 56
57 bool ForceServiceProcessShutdown(const std::string& version) { 57 bool ForceServiceProcessShutdown(const std::string& version) {
58 ScopedHandle shutdown_event; 58 base::win::ScopedHandle shutdown_event;
59 std::string versioned_name = version; 59 std::string versioned_name = version;
60 versioned_name.append("_service_shutdown_evt"); 60 versioned_name.append("_service_shutdown_evt");
61 string16 event_name = 61 string16 event_name =
62 UTF8ToWide(GetServiceProcessScopedName(versioned_name)); 62 UTF8ToWide(GetServiceProcessScopedName(versioned_name));
63 shutdown_event.Set(OpenEvent(EVENT_MODIFY_STATE, FALSE, event_name.c_str())); 63 shutdown_event.Set(OpenEvent(EVENT_MODIFY_STATE, FALSE, event_name.c_str()));
64 if (!shutdown_event.IsValid()) 64 if (!shutdown_event.IsValid())
65 return false; 65 return false;
66 SetEvent(shutdown_event.Get()); 66 SetEvent(shutdown_event.Get());
67 return true; 67 return true;
68 } 68 }
69 69
70 bool CheckServiceProcessReady() { 70 bool CheckServiceProcessReady() {
71 string16 event_name = GetServiceProcessReadyEventName(); 71 string16 event_name = GetServiceProcessReadyEventName();
72 ScopedHandle event( 72 base::win::ScopedHandle event(
73 OpenEvent(SYNCHRONIZE | READ_CONTROL, false, event_name.c_str())); 73 OpenEvent(SYNCHRONIZE | READ_CONTROL, false, event_name.c_str()));
74 if (!event.IsValid()) 74 if (!event.IsValid())
75 return false; 75 return false;
76 // Check if the event is signaled. 76 // Check if the event is signaled.
77 return WaitForSingleObject(event, 0) == WAIT_OBJECT_0; 77 return WaitForSingleObject(event, 0) == WAIT_OBJECT_0;
78 } 78 }
79 79
80 struct ServiceProcessState::StateData { 80 struct ServiceProcessState::StateData {
81 // An event that is signaled when a service process is ready. 81 // An event that is signaled when a service process is ready.
82 ScopedHandle ready_event; 82 base::win::ScopedHandle ready_event;
83 scoped_ptr<ServiceProcessShutdownMonitor> shutdown_monitor; 83 scoped_ptr<ServiceProcessShutdownMonitor> shutdown_monitor;
84 }; 84 };
85 85
86 bool ServiceProcessState::TakeSingletonLock() { 86 bool ServiceProcessState::TakeSingletonLock() {
87 DCHECK(!state_); 87 DCHECK(!state_);
88 string16 event_name = GetServiceProcessReadyEventName(); 88 string16 event_name = GetServiceProcessReadyEventName();
89 CHECK(event_name.length() <= MAX_PATH); 89 CHECK(event_name.length() <= MAX_PATH);
90 ScopedHandle service_process_ready_event; 90 base::win::ScopedHandle service_process_ready_event;
91 service_process_ready_event.Set( 91 service_process_ready_event.Set(
92 CreateEvent(NULL, TRUE, FALSE, event_name.c_str())); 92 CreateEvent(NULL, TRUE, FALSE, event_name.c_str()));
93 DWORD error = GetLastError(); 93 DWORD error = GetLastError();
94 if ((error == ERROR_ALREADY_EXISTS) || (error == ERROR_ACCESS_DENIED)) 94 if ((error == ERROR_ALREADY_EXISTS) || (error == ERROR_ACCESS_DENIED))
95 return false; 95 return false;
96 DCHECK(service_process_ready_event.IsValid()); 96 DCHECK(service_process_ready_event.IsValid());
97 state_ = new StateData; 97 state_ = new StateData;
98 state_->ready_event.Set(service_process_ready_event.Take()); 98 state_->ready_event.Set(service_process_ready_event.Take());
99 return true; 99 return true;
100 } 100 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 } 137 }
138 138
139 void ServiceProcessState::TearDownState() { 139 void ServiceProcessState::TearDownState() {
140 delete state_; 140 delete state_;
141 state_ = NULL; 141 state_ = NULL;
142 } 142 }
143 143
144 bool ServiceProcessState::ShouldHandleOtherVersion() { 144 bool ServiceProcessState::ShouldHandleOtherVersion() {
145 return true; 145 return true;
146 } 146 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698