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 3 // found in the LICENSE file. 4 5 #include "mojo/public/cpp/bindings/lib/serialization_context.h" 6 7 #include <limits> 8 9 #include "base/logging.h" 10 #include "mojo/public/cpp/system/core.h" 11 12 namespace mojo { 13 namespace internal { 14 SerializedHandleVector()15SerializedHandleVector::SerializedHandleVector() {} 16 ~SerializedHandleVector()17SerializedHandleVector::~SerializedHandleVector() { 18 for (auto handle : handles_) { 19 if (handle.is_valid()) { 20 MojoResult rv = MojoClose(handle.value()); 21 DCHECK_EQ(rv, MOJO_RESULT_OK); 22 } 23 } 24 } 25 AddHandle(mojo::Handle handle)26Handle_Data SerializedHandleVector::AddHandle(mojo::Handle handle) { 27 Handle_Data data; 28 if (!handle.is_valid()) { 29 data.value = kEncodedInvalidHandleValue; 30 } else { 31 DCHECK_LT(handles_.size(), std::numeric_limits<uint32_t>::max()); 32 data.value = static_cast<uint32_t>(handles_.size()); 33 handles_.push_back(handle); 34 } 35 return data; 36 } 37 TakeHandle(const Handle_Data & encoded_handle)38mojo::Handle SerializedHandleVector::TakeHandle( 39 const Handle_Data& encoded_handle) { 40 if (!encoded_handle.is_valid()) 41 return mojo::Handle(); 42 DCHECK_LT(encoded_handle.value, handles_.size()); 43 return FetchAndReset(&handles_[encoded_handle.value]); 44 } 45 Swap(std::vector<mojo::Handle> * other)46void SerializedHandleVector::Swap(std::vector<mojo::Handle>* other) { 47 handles_.swap(*other); 48 } 49 SerializationContext()50SerializationContext::SerializationContext() {} 51 ~SerializationContext()52SerializationContext::~SerializationContext() { 53 DCHECK(!custom_contexts || custom_contexts->empty()); 54 } 55 56 } // namespace internal 57 } // namespace mojo 58