| 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/debug/alias.h" | |
| 9 #include "base/logging.h" | 8 #include "base/logging.h" |
| 10 | 9 |
| 11 namespace base { | 10 namespace base { |
| 12 namespace win { | 11 namespace win { |
| 13 | 12 |
| 14 //----------------------------------------------------------------------------- | 13 //----------------------------------------------------------------------------- |
| 15 | 14 |
| 16 ObjectWatcher::ObjectWatcher() | 15 ObjectWatcher::ObjectWatcher() |
| 17 : weak_factory_(this), | 16 : weak_factory_(this), |
| 18 object_(NULL), | 17 object_(NULL), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 34 // Since our job is to just notice when an object is signaled and report the | 33 // Since our job is to just notice when an object is signaled and report the |
| 35 // result back to this thread, we can just run on a Windows wait thread. | 34 // result back to this thread, we can just run on a Windows wait thread. |
| 36 DWORD wait_flags = WT_EXECUTEINWAITTHREAD | WT_EXECUTEONLYONCE; | 35 DWORD wait_flags = WT_EXECUTEINWAITTHREAD | WT_EXECUTEONLYONCE; |
| 37 | 36 |
| 38 // DoneWaiting can be synchronously called from RegisterWaitForSingleObject, | 37 // DoneWaiting can be synchronously called from RegisterWaitForSingleObject, |
| 39 // so set up all state now. | 38 // so set up all state now. |
| 40 callback_ = base::Bind(&ObjectWatcher::Signal, weak_factory_.GetWeakPtr(), | 39 callback_ = base::Bind(&ObjectWatcher::Signal, weak_factory_.GetWeakPtr(), |
| 41 delegate); | 40 delegate); |
| 42 object_ = object; | 41 object_ = object; |
| 43 origin_loop_ = MessageLoop::current(); | 42 origin_loop_ = MessageLoop::current(); |
| 44 stack_trace_ = base::debug::StackTrace(); | |
| 45 | 43 |
| 46 if (!RegisterWaitForSingleObject(&wait_object_, object, DoneWaiting, | 44 if (!RegisterWaitForSingleObject(&wait_object_, object, DoneWaiting, |
| 47 this, INFINITE, wait_flags)) { | 45 this, INFINITE, wait_flags)) { |
| 48 NOTREACHED() << "RegisterWaitForSingleObject failed: " << GetLastError(); | 46 NOTREACHED() << "RegisterWaitForSingleObject failed: " << GetLastError(); |
| 49 object_ = NULL; | 47 object_ = NULL; |
| 50 wait_object_ = NULL; | 48 wait_object_ = NULL; |
| 51 return false; | 49 return false; |
| 52 } | 50 } |
| 53 | 51 |
| 54 // We need to know if the current message loop is going away so we can | 52 // We need to know if the current message loop is going away so we can |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 ObjectWatcher* that = static_cast<ObjectWatcher*>(param); | 90 ObjectWatcher* that = static_cast<ObjectWatcher*>(param); |
| 93 that->origin_loop_->PostTask(FROM_HERE, that->callback_); | 91 that->origin_loop_->PostTask(FROM_HERE, that->callback_); |
| 94 that->callback_.Reset(); | 92 that->callback_.Reset(); |
| 95 } | 93 } |
| 96 | 94 |
| 97 void ObjectWatcher::Signal(Delegate* delegate) { | 95 void ObjectWatcher::Signal(Delegate* delegate) { |
| 98 // Signaling the delegate may result in our destruction or a nested call to | 96 // Signaling the delegate may result in our destruction or a nested call to |
| 99 // StartWatching(). As a result, we save any state we need and clear previous | 97 // StartWatching(). As a result, we save any state we need and clear previous |
| 100 // watcher state before signaling the delegate. | 98 // watcher state before signaling the delegate. |
| 101 HANDLE object = object_; | 99 HANDLE object = object_; |
| 102 // Alias the stack trace where the watch was started so it'll be available in | |
| 103 // minidumps. | |
| 104 base::debug::StackTrace stack_trace = stack_trace_; | |
| 105 base::debug::Alias(&stack_trace); | |
| 106 StopWatching(); | 100 StopWatching(); |
| 107 delegate->OnObjectSignaled(object); | 101 delegate->OnObjectSignaled(object); |
| 108 } | 102 } |
| 109 | 103 |
| 110 void ObjectWatcher::WillDestroyCurrentMessageLoop() { | 104 void ObjectWatcher::WillDestroyCurrentMessageLoop() { |
| 111 // Need to shutdown the watch so that we don't try to access the MessageLoop | 105 // Need to shutdown the watch so that we don't try to access the MessageLoop |
| 112 // after this point. | 106 // after this point. |
| 113 StopWatching(); | 107 StopWatching(); |
| 114 } | 108 } |
| 115 | 109 |
| 116 } // namespace win | 110 } // namespace win |
| 117 } // namespace base | 111 } // namespace base |
| OLD | NEW |