Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 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 "base/win/object_watcher.h" | 5 #include "base/win/object_watcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/win/windows_version.h" | |
| 9 | 10 |
| 10 namespace base { | 11 namespace base { |
| 11 namespace win { | 12 namespace win { |
| 12 | 13 |
| 13 //----------------------------------------------------------------------------- | 14 //----------------------------------------------------------------------------- |
| 14 | 15 |
| 15 ObjectWatcher::ObjectWatcher() | 16 ObjectWatcher::ObjectWatcher() |
| 16 : object_(NULL), | 17 : object_(NULL), |
| 17 wait_object_(NULL), | 18 wait_object_(NULL), |
| 18 origin_loop_(NULL), | 19 origin_loop_(NULL), |
| 19 weak_factory_(this) { | 20 weak_factory_(this) { |
| 20 } | 21 } |
| 21 | 22 |
| 22 ObjectWatcher::~ObjectWatcher() { | 23 ObjectWatcher::~ObjectWatcher() { |
| 23 StopWatching(); | 24 StopWatching(); |
| 24 } | 25 } |
| 25 | 26 |
| 26 bool ObjectWatcher::StartWatching(HANDLE object, Delegate* delegate) { | 27 bool ObjectWatcher::StartWatching(HANDLE object, Delegate* delegate) { |
| 27 CHECK(delegate); | 28 CHECK(delegate); |
| 28 if (wait_object_) { | 29 if (wait_object_) { |
| 29 NOTREACHED() << "Already watching an object"; | 30 NOTREACHED() << "Already watching an object"; |
| 30 return false; | 31 return false; |
| 31 } | 32 } |
| 32 | 33 |
| 33 // Since our job is to just notice when an object is signaled and report the | 34 // Since our job is to just notice when an object is signaled and report the |
| 34 // result back to this thread, we can just run on a Windows wait thread. | 35 // result back to this thread, we can just run on a Windows wait thread. |
| 35 DWORD wait_flags = WT_EXECUTEINWAITTHREAD | WT_EXECUTEONLYONCE; | 36 DWORD wait_flags = WT_EXECUTEINWAITTHREAD | WT_EXECUTEONLYONCE; |
| 36 | 37 |
| 38 if (base::win::GetVersion() > base::win::VERSION_XP) { | |
| 39 wait_flags |= WT_TRANSFER_IMPERSONATION; | |
|
forshaw
2015/02/20 11:38:02
What's the reason being this change? Currently it'
Shrikant Kelkar
2015/02/21 02:32:40
Removed.. During initial checks, I think chrome_el
| |
| 40 } | |
| 41 | |
| 37 // DoneWaiting can be synchronously called from RegisterWaitForSingleObject, | 42 // DoneWaiting can be synchronously called from RegisterWaitForSingleObject, |
| 38 // so set up all state now. | 43 // so set up all state now. |
| 39 callback_ = base::Bind(&ObjectWatcher::Signal, weak_factory_.GetWeakPtr(), | 44 callback_ = base::Bind(&ObjectWatcher::Signal, weak_factory_.GetWeakPtr(), |
| 40 delegate); | 45 delegate); |
| 41 object_ = object; | 46 object_ = object; |
| 42 origin_loop_ = MessageLoop::current(); | 47 origin_loop_ = MessageLoop::current(); |
| 43 | 48 |
| 44 if (!RegisterWaitForSingleObject(&wait_object_, object, DoneWaiting, | 49 if (!RegisterWaitForSingleObject(&wait_object_, object, DoneWaiting, |
| 45 this, INFINITE, wait_flags)) { | 50 this, INFINITE, wait_flags)) { |
| 46 DPLOG(FATAL) << "RegisterWaitForSingleObject failed"; | 51 DPLOG(FATAL) << "RegisterWaitForSingleObject failed"; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 } | 107 } |
| 103 | 108 |
| 104 void ObjectWatcher::WillDestroyCurrentMessageLoop() { | 109 void ObjectWatcher::WillDestroyCurrentMessageLoop() { |
| 105 // Need to shutdown the watch so that we don't try to access the MessageLoop | 110 // Need to shutdown the watch so that we don't try to access the MessageLoop |
| 106 // after this point. | 111 // after this point. |
| 107 StopWatching(); | 112 StopWatching(); |
| 108 } | 113 } |
| 109 | 114 |
| 110 } // namespace win | 115 } // namespace win |
| 111 } // namespace base | 116 } // namespace base |
| OLD | NEW |