| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/edk/system/handle_table.h" | 5 #include "mojo/edk/system/handle_table.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <limits> | 9 #include <limits> |
| 10 | 10 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 return MOJO_RESULT_BUSY; | 67 return MOJO_RESULT_BUSY; |
| 68 | 68 |
| 69 *dispatcher = it->second.dispatcher; | 69 *dispatcher = it->second.dispatcher; |
| 70 handles_.erase(it); | 70 handles_.erase(it); |
| 71 return MOJO_RESULT_OK; | 71 return MOJO_RESULT_OK; |
| 72 } | 72 } |
| 73 | 73 |
| 74 MojoResult HandleTable::BeginTransit( | 74 MojoResult HandleTable::BeginTransit( |
| 75 const MojoHandle* handles, | 75 const MojoHandle* handles, |
| 76 uint32_t num_handles, | 76 uint32_t num_handles, |
| 77 std::vector<Dispatcher::DispatcherInTransit>* dispatchers) { | 77 std::vector<Dispatcher::DispatcherInTransit>* dispatchers, |
| 78 Dispatcher::RequestContext* request_context) { |
| 78 dispatchers->clear(); | 79 dispatchers->clear(); |
| 79 dispatchers->reserve(num_handles); | 80 dispatchers->reserve(num_handles); |
| 80 for (size_t i = 0; i < num_handles; ++i) { | 81 for (size_t i = 0; i < num_handles; ++i) { |
| 81 auto it = handles_.find(handles[i]); | 82 auto it = handles_.find(handles[i]); |
| 82 if (it == handles_.end()) | 83 if (it == handles_.end()) |
| 83 return MOJO_RESULT_INVALID_ARGUMENT; | 84 return MOJO_RESULT_INVALID_ARGUMENT; |
| 84 if (it->second.busy) | 85 if (it->second.busy) |
| 85 return MOJO_RESULT_BUSY; | 86 return MOJO_RESULT_BUSY; |
| 86 | 87 |
| 87 Dispatcher::DispatcherInTransit d; | 88 Dispatcher::DispatcherInTransit d; |
| 88 d.local_handle = handles[i]; | 89 d.local_handle = handles[i]; |
| 89 d.dispatcher = it->second.dispatcher; | 90 d.dispatcher = it->second.dispatcher; |
| 90 if (!d.dispatcher->BeginTransit()) | 91 if (!d.dispatcher->BeginTransit(request_context)) |
| 91 return MOJO_RESULT_BUSY; | 92 return MOJO_RESULT_BUSY; |
| 92 it->second.busy = true; | 93 it->second.busy = true; |
| 93 dispatchers->push_back(d); | 94 dispatchers->push_back(d); |
| 94 } | 95 } |
| 95 return MOJO_RESULT_OK; | 96 return MOJO_RESULT_OK; |
| 96 } | 97 } |
| 97 | 98 |
| 98 void HandleTable::CompleteTransitAndClose( | 99 void HandleTable::CompleteTransitAndClose( |
| 99 const std::vector<Dispatcher::DispatcherInTransit>& dispatchers) { | 100 const std::vector<Dispatcher::DispatcherInTransit>& dispatchers, |
| 101 Dispatcher::RequestContext* request_context) { |
| 100 for (const auto& dispatcher : dispatchers) { | 102 for (const auto& dispatcher : dispatchers) { |
| 101 auto it = handles_.find(dispatcher.local_handle); | 103 auto it = handles_.find(dispatcher.local_handle); |
| 102 DCHECK(it != handles_.end() && it->second.busy); | 104 DCHECK(it != handles_.end() && it->second.busy); |
| 103 handles_.erase(it); | 105 handles_.erase(it); |
| 104 dispatcher.dispatcher->CompleteTransitAndClose(); | 106 dispatcher.dispatcher->CompleteTransitAndClose(request_context); |
| 105 } | 107 } |
| 106 } | 108 } |
| 107 | 109 |
| 108 void HandleTable::CancelTransit( | 110 void HandleTable::CancelTransit( |
| 109 const std::vector<Dispatcher::DispatcherInTransit>& dispatchers) { | 111 const std::vector<Dispatcher::DispatcherInTransit>& dispatchers, |
| 112 Dispatcher::RequestContext* request_context) { |
| 110 for (const auto& dispatcher : dispatchers) { | 113 for (const auto& dispatcher : dispatchers) { |
| 111 auto it = handles_.find(dispatcher.local_handle); | 114 auto it = handles_.find(dispatcher.local_handle); |
| 112 DCHECK(it != handles_.end() && it->second.busy); | 115 DCHECK(it != handles_.end() && it->second.busy); |
| 113 it->second.busy = false; | 116 it->second.busy = false; |
| 114 dispatcher.dispatcher->CancelTransit(); | 117 dispatcher.dispatcher->CancelTransit(request_context); |
| 115 } | 118 } |
| 116 } | 119 } |
| 117 | 120 |
| 118 void HandleTable::GetActiveHandlesForTest(std::vector<MojoHandle>* handles) { | 121 void HandleTable::GetActiveHandlesForTest(std::vector<MojoHandle>* handles) { |
| 119 handles->clear(); | 122 handles->clear(); |
| 120 for (const auto& entry : handles_) | 123 for (const auto& entry : handles_) |
| 121 handles->push_back(entry.first); | 124 handles->push_back(entry.first); |
| 122 } | 125 } |
| 123 | 126 |
| 124 HandleTable::Entry::Entry() {} | 127 HandleTable::Entry::Entry() {} |
| 125 | 128 |
| 126 HandleTable::Entry::Entry(scoped_refptr<Dispatcher> dispatcher) | 129 HandleTable::Entry::Entry(scoped_refptr<Dispatcher> dispatcher) |
| 127 : dispatcher(dispatcher) {} | 130 : dispatcher(dispatcher) {} |
| 128 | 131 |
| 129 HandleTable::Entry::~Entry() {} | 132 HandleTable::Entry::~Entry() {} |
| 130 | 133 |
| 131 } // namespace edk | 134 } // namespace edk |
| 132 } // namespace mojo | 135 } // namespace mojo |
| OLD | NEW |