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

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

Issue 6349029: Get service processes working on Mac and Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix up small typo in comment Created 9 years, 10 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
« no previous file with comments | « chrome/common/service_process_util_unittest.cc ('k') | chrome/service/service_ipc_server.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 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/string16.h" 11 #include "base/string16.h"
12 #include "base/task.h"
12 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
13 #include "base/win/object_watcher.h" 14 #include "base/win/object_watcher.h"
14 #include "base/win/scoped_handle.h" 15 #include "base/win/scoped_handle.h"
15 #include "base/win/win_util.h" 16 #include "base/win/win_util.h"
16 #include "chrome/common/chrome_switches.h" 17 #include "chrome/common/chrome_switches.h"
17 18
18 namespace { 19 namespace {
19 20
20 string16 GetServiceProcessReadyEventName() { 21 string16 GetServiceProcessReadyEventName() {
21 return UTF8ToWide( 22 return UTF8ToWide(
(...skipping 25 matching lines...) Expand all
47 } 48 }
48 49
49 private: 50 private:
50 base::win::ScopedHandle shutdown_event_; 51 base::win::ScopedHandle shutdown_event_;
51 base::win::ObjectWatcher watcher_; 52 base::win::ObjectWatcher watcher_;
52 scoped_ptr<Task> shutdown_task_; 53 scoped_ptr<Task> shutdown_task_;
53 }; 54 };
54 55
55 } // namespace 56 } // namespace
56 57
57 bool ForceServiceProcessShutdown(const std::string& version) { 58 bool ForceServiceProcessShutdown(const std::string& version,
59 base::ProcessId process_id) {
58 base::win::ScopedHandle shutdown_event; 60 base::win::ScopedHandle shutdown_event;
59 std::string versioned_name = version; 61 std::string versioned_name = version;
60 versioned_name.append("_service_shutdown_evt"); 62 versioned_name.append("_service_shutdown_evt");
61 string16 event_name = 63 string16 event_name =
62 UTF8ToWide(GetServiceProcessScopedName(versioned_name)); 64 UTF8ToWide(GetServiceProcessScopedName(versioned_name));
63 shutdown_event.Set(OpenEvent(EVENT_MODIFY_STATE, FALSE, event_name.c_str())); 65 shutdown_event.Set(OpenEvent(EVENT_MODIFY_STATE, FALSE, event_name.c_str()));
64 if (!shutdown_event.IsValid()) 66 if (!shutdown_event.IsValid())
65 return false; 67 return false;
66 SetEvent(shutdown_event.Get()); 68 SetEvent(shutdown_event.Get());
67 return true; 69 return true;
(...skipping 24 matching lines...) Expand all
92 CreateEvent(NULL, TRUE, FALSE, event_name.c_str())); 94 CreateEvent(NULL, TRUE, FALSE, event_name.c_str()));
93 DWORD error = GetLastError(); 95 DWORD error = GetLastError();
94 if ((error == ERROR_ALREADY_EXISTS) || (error == ERROR_ACCESS_DENIED)) 96 if ((error == ERROR_ALREADY_EXISTS) || (error == ERROR_ACCESS_DENIED))
95 return false; 97 return false;
96 DCHECK(service_process_ready_event.IsValid()); 98 DCHECK(service_process_ready_event.IsValid());
97 state_ = new StateData; 99 state_ = new StateData;
98 state_->ready_event.Set(service_process_ready_event.Take()); 100 state_->ready_event.Set(service_process_ready_event.Take());
99 return true; 101 return true;
100 } 102 }
101 103
102 void ServiceProcessState::SignalReady(Task* shutdown_task) { 104 bool ServiceProcessState::SignalReady(MessageLoop *message_loop,
105 Task* shutdown_task) {
103 DCHECK(state_); 106 DCHECK(state_);
104 DCHECK(state_->ready_event.IsValid()); 107 DCHECK(state_->ready_event.IsValid());
105 SetEvent(state_->ready_event.Get()); 108 if (!SetEvent(state_->ready_event.Get())) {
109 return false;
110 }
106 if (shutdown_task) { 111 if (shutdown_task) {
107 state_->shutdown_monitor.reset( 112 state_->shutdown_monitor.reset(
108 new ServiceProcessShutdownMonitor(shutdown_task)); 113 new ServiceProcessShutdownMonitor(shutdown_task));
109 state_->shutdown_monitor->Start(); 114 state_->shutdown_monitor->Start();
110 } 115 }
111 } 116 return true;
112
113 void ServiceProcessState::SignalStopped() {
114 TearDownState();
115 shared_mem_service_data_.reset();
116 } 117 }
117 118
118 bool ServiceProcessState::AddToAutoRun() { 119 bool ServiceProcessState::AddToAutoRun() {
119 FilePath chrome_path; 120 FilePath chrome_path;
120 if (PathService::Get(base::FILE_EXE, &chrome_path)) { 121 if (PathService::Get(base::FILE_EXE, &chrome_path)) {
121 CommandLine cmd_line(chrome_path); 122 CommandLine cmd_line(chrome_path);
122 cmd_line.AppendSwitchASCII(switches::kProcessType, 123 cmd_line.AppendSwitchASCII(switches::kProcessType,
123 switches::kServiceProcess); 124 switches::kServiceProcess);
124 // We need a unique name for the command per user-date-dir. Just use the 125 // We need a unique name for the command per user-date-dir. Just use the
125 // channel name. 126 // channel name.
126 return base::win::AddCommandToAutoRun( 127 return base::win::AddCommandToAutoRun(
127 HKEY_CURRENT_USER, 128 HKEY_CURRENT_USER,
128 UTF8ToWide(GetAutoRunKey()), 129 UTF8ToWide(GetAutoRunKey()),
129 cmd_line.command_line_string()); 130 cmd_line.command_line_string());
130 } 131 }
131 return false; 132 return false;
132 } 133 }
133 134
134 bool ServiceProcessState::RemoveFromAutoRun() { 135 bool ServiceProcessState::RemoveFromAutoRun() {
135 return base::win::RemoveCommandFromAutoRun( 136 return base::win::RemoveCommandFromAutoRun(
136 HKEY_CURRENT_USER, UTF8ToWide(GetAutoRunKey())); 137 HKEY_CURRENT_USER, UTF8ToWide(GetAutoRunKey()));
137 } 138 }
138 139
139 void ServiceProcessState::TearDownState() { 140 void ServiceProcessState::TearDownState() {
140 delete state_; 141 delete state_;
141 state_ = NULL; 142 state_ = NULL;
142 } 143 }
143
144 bool ServiceProcessState::ShouldHandleOtherVersion() {
145 return true;
146 }
OLDNEW
« no previous file with comments | « chrome/common/service_process_util_unittest.cc ('k') | chrome/service/service_ipc_server.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698