| 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.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/object_watcher.h" | |
| 11 #include "base/path_service.h" | 10 #include "base/path_service.h" |
| 12 #include "base/scoped_handle_win.h" | 11 #include "base/scoped_handle_win.h" |
| 13 #include "base/string16.h" | 12 #include "base/string16.h" |
| 14 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "base/win/object_watcher.h" |
| 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 |
| 25 string16 GetServiceProcessShutdownEventName() { | 25 string16 GetServiceProcessShutdownEventName() { |
| 26 return UTF8ToWide( | 26 return UTF8ToWide( |
| 27 GetServiceProcessScopedVersionedName("_service_shutdown_evt")); | 27 GetServiceProcessScopedVersionedName("_service_shutdown_evt")); |
| 28 } | 28 } |
| 29 | 29 |
| 30 class ServiceProcessShutdownMonitor : public base::ObjectWatcher::Delegate { | 30 class ServiceProcessShutdownMonitor |
| 31 : public base::win::ObjectWatcher::Delegate { |
| 31 public: | 32 public: |
| 32 explicit ServiceProcessShutdownMonitor(Task* shutdown_task) | 33 explicit ServiceProcessShutdownMonitor(Task* shutdown_task) |
| 33 : shutdown_task_(shutdown_task) { | 34 : shutdown_task_(shutdown_task) { |
| 34 } | 35 } |
| 35 void Start() { | 36 void Start() { |
| 36 string16 event_name = GetServiceProcessShutdownEventName(); | 37 string16 event_name = GetServiceProcessShutdownEventName(); |
| 37 CHECK(event_name.length() <= MAX_PATH); | 38 CHECK(event_name.length() <= MAX_PATH); |
| 38 shutdown_event_.Set(CreateEvent(NULL, TRUE, FALSE, event_name.c_str())); | 39 shutdown_event_.Set(CreateEvent(NULL, TRUE, FALSE, event_name.c_str())); |
| 39 watcher_.StartWatching(shutdown_event_.Get(), this); | 40 watcher_.StartWatching(shutdown_event_.Get(), this); |
| 40 } | 41 } |
| 41 | 42 |
| 42 // base::ObjectWatcher::Delegate implementation. | 43 // base::ObjectWatcher::Delegate implementation. |
| 43 virtual void OnObjectSignaled(HANDLE object) { | 44 virtual void OnObjectSignaled(HANDLE object) { |
| 44 shutdown_task_->Run(); | 45 shutdown_task_->Run(); |
| 45 shutdown_task_.reset(); | 46 shutdown_task_.reset(); |
| 46 } | 47 } |
| 47 | 48 |
| 48 private: | 49 private: |
| 49 ScopedHandle shutdown_event_; | 50 ScopedHandle shutdown_event_; |
| 50 base::ObjectWatcher watcher_; | 51 base::win::ObjectWatcher watcher_; |
| 51 scoped_ptr<Task> shutdown_task_; | 52 scoped_ptr<Task> shutdown_task_; |
| 52 }; | 53 }; |
| 53 | 54 |
| 54 } // namespace | 55 } // namespace |
| 55 | 56 |
| 56 bool ForceServiceProcessShutdown(const std::string& version) { | 57 bool ForceServiceProcessShutdown(const std::string& version) { |
| 57 ScopedHandle shutdown_event; | 58 ScopedHandle shutdown_event; |
| 58 std::string versioned_name = version; | 59 std::string versioned_name = version; |
| 59 versioned_name.append("_service_shutdown_evt"); | 60 versioned_name.append("_service_shutdown_evt"); |
| 60 string16 event_name = | 61 string16 event_name = |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 137 } |
| 137 | 138 |
| 138 void ServiceProcessState::TearDownState() { | 139 void ServiceProcessState::TearDownState() { |
| 139 delete state_; | 140 delete state_; |
| 140 state_ = NULL; | 141 state_ = NULL; |
| 141 } | 142 } |
| 142 | 143 |
| 143 bool ServiceProcessState::ShouldHandleOtherVersion() { | 144 bool ServiceProcessState::ShouldHandleOtherVersion() { |
| 144 return true; | 145 return true; |
| 145 } | 146 } |
| OLD | NEW |