Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: mojo/public/cpp/bindings/lib/serialization_util.cc

Issue 1955123003: Mojo C++ bindings: switch the remaining callsites of the old serialization interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@24_union_and_others
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/lib/serialization_util.h" 5 #include "mojo/public/cpp/bindings/lib/serialization_util.h"
6 6
7 #include <stddef.h>
8 #include <stdint.h>
9
10 #include <limits>
11
12 #include "base/logging.h"
13
14 namespace mojo { 7 namespace mojo {
15 namespace internal { 8 namespace internal {
16 9
17 namespace { 10 namespace {
18 11
19 const size_t kAlignment = 8; 12 const size_t kAlignment = 8;
20 13
21 template <typename T> 14 template <typename T>
22 T AlignImpl(T t) { 15 T AlignImpl(T t) {
23 return t + (kAlignment - (t % kAlignment)) % kAlignment; 16 return t + (kAlignment - (t % kAlignment)) % kAlignment;
(...skipping 25 matching lines...) Expand all
49 42
50 *offset = static_cast<uint64_t>(p_obj - p_slot); 43 *offset = static_cast<uint64_t>(p_obj - p_slot);
51 } 44 }
52 45
53 const void* DecodePointerRaw(const uint64_t* offset) { 46 const void* DecodePointerRaw(const uint64_t* offset) {
54 if (!*offset) 47 if (!*offset)
55 return nullptr; 48 return nullptr;
56 return reinterpret_cast<const char*>(offset) + *offset; 49 return reinterpret_cast<const char*>(offset) + *offset;
57 } 50 }
58 51
59 SerializedHandleVector::SerializedHandleVector() {}
60
61 SerializedHandleVector::~SerializedHandleVector() {
62 for (auto handle : handles_) {
63 if (handle.is_valid()) {
64 MojoResult rv = MojoClose(handle.value());
65 DCHECK_EQ(rv, MOJO_RESULT_OK);
66 }
67 }
68 }
69
70 Handle_Data SerializedHandleVector::AddHandle(mojo::Handle handle) {
71 Handle_Data data;
72 if (!handle.is_valid()) {
73 data.value = kEncodedInvalidHandleValue;
74 } else {
75 DCHECK_LT(handles_.size(), std::numeric_limits<uint32_t>::max());
76 data.value = static_cast<uint32_t>(handles_.size());
77 handles_.push_back(handle);
78 }
79 return data;
80 }
81
82 mojo::Handle SerializedHandleVector::TakeHandle(
83 const Handle_Data& encoded_handle) {
84 if (!encoded_handle.is_valid())
85 return mojo::Handle();
86 DCHECK_LT(encoded_handle.value, handles_.size());
87 return FetchAndReset(&handles_[encoded_handle.value]);
88 }
89
90 void SerializedHandleVector::Swap(std::vector<mojo::Handle>* other) {
91 handles_.swap(*other);
92 }
93
94 SerializationContext::SerializationContext() {}
95
96 SerializationContext::SerializationContext(
97 scoped_refptr<MultiplexRouter> in_router)
98 : router(std::move(in_router)) {}
99
100 SerializationContext::~SerializationContext() {
101 DCHECK(!custom_contexts || custom_contexts->empty());
102 }
103
104 } // namespace internal 52 } // namespace internal
105 } // namespace mojo 53 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/serialization_util.h ('k') | mojo/public/cpp/bindings/lib/string_serialization.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698