| 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/bindings/sync_handle_registry.h" | 5 #include "mojo/public/cpp/bindings/sync_handle_registry.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 DCHECK_EQ(result.get(), g_current_sync_handle_watcher.Pointer()->Get()); | 27 DCHECK_EQ(result.get(), g_current_sync_handle_watcher.Pointer()->Get()); |
| 28 } | 28 } |
| 29 return result; | 29 return result; |
| 30 } | 30 } |
| 31 | 31 |
| 32 bool SyncHandleRegistry::RegisterHandle(const Handle& handle, | 32 bool SyncHandleRegistry::RegisterHandle(const Handle& handle, |
| 33 MojoHandleSignals handle_signals, | 33 MojoHandleSignals handle_signals, |
| 34 const HandleCallback& callback) { | 34 const HandleCallback& callback) { |
| 35 DCHECK(thread_checker_.CalledOnValidThread()); | 35 DCHECK(thread_checker_.CalledOnValidThread()); |
| 36 | 36 |
| 37 if (ContainsKey(handles_, handle)) | 37 if (base::ContainsKey(handles_, handle)) |
| 38 return false; | 38 return false; |
| 39 | 39 |
| 40 MojoResult result = MojoAddHandle(wait_set_handle_.get().value(), | 40 MojoResult result = MojoAddHandle(wait_set_handle_.get().value(), |
| 41 handle.value(), handle_signals); | 41 handle.value(), handle_signals); |
| 42 if (result != MOJO_RESULT_OK) | 42 if (result != MOJO_RESULT_OK) |
| 43 return false; | 43 return false; |
| 44 | 44 |
| 45 handles_[handle] = callback; | 45 handles_[handle] = callback; |
| 46 return true; | 46 return true; |
| 47 } | 47 } |
| 48 | 48 |
| 49 void SyncHandleRegistry::UnregisterHandle(const Handle& handle) { | 49 void SyncHandleRegistry::UnregisterHandle(const Handle& handle) { |
| 50 DCHECK(thread_checker_.CalledOnValidThread()); | 50 DCHECK(thread_checker_.CalledOnValidThread()); |
| 51 if (!ContainsKey(handles_, handle)) | 51 if (!base::ContainsKey(handles_, handle)) |
| 52 return; | 52 return; |
| 53 | 53 |
| 54 MojoResult result = | 54 MojoResult result = |
| 55 MojoRemoveHandle(wait_set_handle_.get().value(), handle.value()); | 55 MojoRemoveHandle(wait_set_handle_.get().value(), handle.value()); |
| 56 DCHECK_EQ(MOJO_RESULT_OK, result); | 56 DCHECK_EQ(MOJO_RESULT_OK, result); |
| 57 handles_.erase(handle); | 57 handles_.erase(handle); |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool SyncHandleRegistry::WatchAllHandles(const bool* should_stop[], | 60 bool SyncHandleRegistry::WatchAllHandles(const bool* should_stop[], |
| 61 size_t count) { | 61 size_t count) { |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 DCHECK(!g_current_sync_handle_watcher.Pointer()->Get()); | 104 DCHECK(!g_current_sync_handle_watcher.Pointer()->Get()); |
| 105 g_current_sync_handle_watcher.Pointer()->Set(this); | 105 g_current_sync_handle_watcher.Pointer()->Set(this); |
| 106 } | 106 } |
| 107 | 107 |
| 108 SyncHandleRegistry::~SyncHandleRegistry() { | 108 SyncHandleRegistry::~SyncHandleRegistry() { |
| 109 DCHECK(thread_checker_.CalledOnValidThread()); | 109 DCHECK(thread_checker_.CalledOnValidThread()); |
| 110 g_current_sync_handle_watcher.Pointer()->Set(nullptr); | 110 g_current_sync_handle_watcher.Pointer()->Set(nullptr); |
| 111 } | 111 } |
| 112 | 112 |
| 113 } // namespace mojo | 113 } // namespace mojo |
| OLD | NEW |