| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "mojo/public/cpp/system/watcher.h" | 5 #include "mojo/public/cpp/system/watcher.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 return handle_.is_valid(); | 65 return handle_.is_valid(); |
| 66 } | 66 } |
| 67 | 67 |
| 68 MojoResult Watcher::Start(Handle handle, | 68 MojoResult Watcher::Start(Handle handle, |
| 69 MojoHandleSignals signals, | 69 MojoHandleSignals signals, |
| 70 const ReadyCallback& callback) { | 70 const ReadyCallback& callback) { |
| 71 DCHECK(thread_checker_.CalledOnValidThread()); | 71 DCHECK(thread_checker_.CalledOnValidThread()); |
| 72 DCHECK(!IsWatching()); | 72 DCHECK(!IsWatching()); |
| 73 DCHECK(!callback.is_null()); | 73 DCHECK(!callback.is_null()); |
| 74 | 74 |
| 75 message_loop_observer_.reset(new MessageLoopObserver(this)); | 75 // message_loop_observer_.reset(new MessageLoopObserver(this)); |
| 76 callback_ = callback; | 76 callback_ = callback; |
| 77 handle_ = handle; | 77 handle_ = handle; |
| 78 MojoResult result = MojoWatch(handle_.value(), signals, | 78 MojoResult result = MojoWatch(handle_.value(), signals, |
| 79 &Watcher::CallOnHandleReady, | 79 &Watcher::CallOnHandleReady, |
| 80 reinterpret_cast<uintptr_t>(this)); | 80 reinterpret_cast<uintptr_t>(this)); |
| 81 if (result != MOJO_RESULT_OK) { | 81 if (result != MOJO_RESULT_OK) { |
| 82 handle_.set_value(kInvalidHandleValue); | 82 handle_.set_value(kInvalidHandleValue); |
| 83 callback_.Reset(); | 83 callback_.Reset(); |
| 84 message_loop_observer_.reset(); | 84 message_loop_observer_.reset(); |
| 85 DCHECK(result == MOJO_RESULT_FAILED_PRECONDITION || | 85 DCHECK(result == MOJO_RESULT_FAILED_PRECONDITION || |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 // default task runner for the IO thread. | 141 // default task runner for the IO thread. |
| 142 watcher->OnHandleReady(result); | 142 watcher->OnHandleReady(result); |
| 143 } else { | 143 } else { |
| 144 watcher->task_runner_->PostTask( | 144 watcher->task_runner_->PostTask( |
| 145 FROM_HERE, | 145 FROM_HERE, |
| 146 base::Bind(&Watcher::OnHandleReady, watcher->weak_self_, result)); | 146 base::Bind(&Watcher::OnHandleReady, watcher->weak_self_, result)); |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 } // namespace mojo | 150 } // namespace mojo |
| OLD | NEW |