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/platform_handle_dispatcher.h" | 5 #include "mojo/edk/system/platform_handle_dispatcher.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> |
8 | 9 |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 | 11 |
11 namespace mojo { | 12 namespace mojo { |
12 namespace edk { | 13 namespace edk { |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 const size_t kInvalidPlatformHandleIndex = static_cast<size_t>(-1); | 17 const size_t kInvalidPlatformHandleIndex = static_cast<size_t>(-1); |
17 | 18 |
18 struct MOJO_ALIGNAS(8) SerializedPlatformHandleDispatcher { | 19 struct MOJO_ALIGNAS(8) SerializedPlatformHandleDispatcher { |
19 size_t platform_handle_index; // (Or |kInvalidPlatformHandleIndex|.) | 20 size_t platform_handle_index; // (Or |kInvalidPlatformHandleIndex|.) |
20 }; | 21 }; |
21 | 22 |
22 } // namespace | 23 } // namespace |
23 | 24 |
24 ScopedPlatformHandle PlatformHandleDispatcher::PassPlatformHandle() { | 25 ScopedPlatformHandle PlatformHandleDispatcher::PassPlatformHandle() { |
25 base::AutoLock locker(lock()); | 26 base::AutoLock locker(lock()); |
26 return platform_handle_.Pass(); | 27 return std::move(platform_handle_); |
27 } | 28 } |
28 | 29 |
29 Dispatcher::Type PlatformHandleDispatcher::GetType() const { | 30 Dispatcher::Type PlatformHandleDispatcher::GetType() const { |
30 return Type::PLATFORM_HANDLE; | 31 return Type::PLATFORM_HANDLE; |
31 } | 32 } |
32 | 33 |
33 // static | 34 // static |
34 scoped_refptr<PlatformHandleDispatcher> PlatformHandleDispatcher::Deserialize( | 35 scoped_refptr<PlatformHandleDispatcher> PlatformHandleDispatcher::Deserialize( |
35 const void* source, | 36 const void* source, |
36 size_t size, | 37 size_t size, |
(...skipping 21 matching lines...) Expand all Loading... |
58 // We take ownership of the handle, so we have to invalidate the one in | 59 // We take ownership of the handle, so we have to invalidate the one in |
59 // |platform_handles|. | 60 // |platform_handles|. |
60 std::swap(platform_handle, (*platform_handles)[platform_handle_index]); | 61 std::swap(platform_handle, (*platform_handles)[platform_handle_index]); |
61 } | 62 } |
62 | 63 |
63 return Create(ScopedPlatformHandle(platform_handle)); | 64 return Create(ScopedPlatformHandle(platform_handle)); |
64 } | 65 } |
65 | 66 |
66 PlatformHandleDispatcher::PlatformHandleDispatcher( | 67 PlatformHandleDispatcher::PlatformHandleDispatcher( |
67 ScopedPlatformHandle platform_handle) | 68 ScopedPlatformHandle platform_handle) |
68 : platform_handle_(platform_handle.Pass()) { | 69 : platform_handle_(std::move(platform_handle)) {} |
69 } | |
70 | 70 |
71 PlatformHandleDispatcher::~PlatformHandleDispatcher() { | 71 PlatformHandleDispatcher::~PlatformHandleDispatcher() { |
72 } | 72 } |
73 | 73 |
74 void PlatformHandleDispatcher::CloseImplNoLock() { | 74 void PlatformHandleDispatcher::CloseImplNoLock() { |
75 lock().AssertAcquired(); | 75 lock().AssertAcquired(); |
76 platform_handle_.reset(); | 76 platform_handle_.reset(); |
77 } | 77 } |
78 | 78 |
79 scoped_refptr<Dispatcher> | 79 scoped_refptr<Dispatcher> |
80 PlatformHandleDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { | 80 PlatformHandleDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { |
81 lock().AssertAcquired(); | 81 lock().AssertAcquired(); |
82 return Create(platform_handle_.Pass()); | 82 return Create(std::move(platform_handle_)); |
83 } | 83 } |
84 | 84 |
85 void PlatformHandleDispatcher::StartSerializeImplNoLock( | 85 void PlatformHandleDispatcher::StartSerializeImplNoLock( |
86 size_t* max_size, | 86 size_t* max_size, |
87 size_t* max_platform_handles) { | 87 size_t* max_platform_handles) { |
88 *max_size = sizeof(SerializedPlatformHandleDispatcher); | 88 *max_size = sizeof(SerializedPlatformHandleDispatcher); |
89 *max_platform_handles = 1; | 89 *max_platform_handles = 1; |
90 } | 90 } |
91 | 91 |
92 bool PlatformHandleDispatcher::EndSerializeAndCloseImplNoLock( | 92 bool PlatformHandleDispatcher::EndSerializeAndCloseImplNoLock( |
93 void* destination, | 93 void* destination, |
94 size_t* actual_size, | 94 size_t* actual_size, |
95 PlatformHandleVector* platform_handles) { | 95 PlatformHandleVector* platform_handles) { |
96 SerializedPlatformHandleDispatcher* serialization = | 96 SerializedPlatformHandleDispatcher* serialization = |
97 static_cast<SerializedPlatformHandleDispatcher*>(destination); | 97 static_cast<SerializedPlatformHandleDispatcher*>(destination); |
98 if (platform_handle_.is_valid()) { | 98 if (platform_handle_.is_valid()) { |
99 serialization->platform_handle_index = platform_handles->size(); | 99 serialization->platform_handle_index = platform_handles->size(); |
100 platform_handles->push_back(platform_handle_.release()); | 100 platform_handles->push_back(platform_handle_.release()); |
101 } else { | 101 } else { |
102 serialization->platform_handle_index = kInvalidPlatformHandleIndex; | 102 serialization->platform_handle_index = kInvalidPlatformHandleIndex; |
103 } | 103 } |
104 | 104 |
105 *actual_size = sizeof(SerializedPlatformHandleDispatcher); | 105 *actual_size = sizeof(SerializedPlatformHandleDispatcher); |
106 return true; | 106 return true; |
107 } | 107 } |
108 | 108 |
109 } // namespace edk | 109 } // namespace edk |
110 } // namespace mojo | 110 } // namespace mojo |
OLD | NEW |