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 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 embedder::ScopedPlatformHandle PlatformHandleDispatcher::PassPlatformHandle() { | 24 embedder::ScopedPlatformHandle PlatformHandleDispatcher::PassPlatformHandle() { |
25 MutexLocker locker(&mutex()); | 25 MutexLocker locker(&mutex()); |
26 return platform_handle_.Pass(); | 26 return platform_handle_.Pass(); |
27 } | 27 } |
28 | 28 |
29 Dispatcher::Type PlatformHandleDispatcher::GetType() const { | 29 Dispatcher::Type PlatformHandleDispatcher::GetType() const { |
30 return Type::PLATFORM_HANDLE; | 30 return Type::PLATFORM_HANDLE; |
31 } | 31 } |
32 | 32 |
33 // static | 33 // static |
34 scoped_refptr<PlatformHandleDispatcher> PlatformHandleDispatcher::Deserialize( | 34 RefPtr<PlatformHandleDispatcher> PlatformHandleDispatcher::Deserialize( |
35 Channel* channel, | 35 Channel* channel, |
36 const void* source, | 36 const void* source, |
37 size_t size, | 37 size_t size, |
38 embedder::PlatformHandleVector* platform_handles) { | 38 embedder::PlatformHandleVector* platform_handles) { |
39 if (size != sizeof(SerializedPlatformHandleDispatcher)) { | 39 if (size != sizeof(SerializedPlatformHandleDispatcher)) { |
40 LOG(ERROR) << "Invalid serialized platform handle dispatcher (bad size)"; | 40 LOG(ERROR) << "Invalid serialized platform handle dispatcher (bad size)"; |
41 return nullptr; | 41 return nullptr; |
42 } | 42 } |
43 | 43 |
44 const SerializedPlatformHandleDispatcher* serialization = | 44 const SerializedPlatformHandleDispatcher* serialization = |
(...skipping 25 matching lines...) Expand all Loading... |
70 } | 70 } |
71 | 71 |
72 PlatformHandleDispatcher::~PlatformHandleDispatcher() { | 72 PlatformHandleDispatcher::~PlatformHandleDispatcher() { |
73 } | 73 } |
74 | 74 |
75 void PlatformHandleDispatcher::CloseImplNoLock() { | 75 void PlatformHandleDispatcher::CloseImplNoLock() { |
76 mutex().AssertHeld(); | 76 mutex().AssertHeld(); |
77 platform_handle_.reset(); | 77 platform_handle_.reset(); |
78 } | 78 } |
79 | 79 |
80 scoped_refptr<Dispatcher> | 80 RefPtr<Dispatcher> |
81 PlatformHandleDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { | 81 PlatformHandleDispatcher::CreateEquivalentDispatcherAndCloseImplNoLock() { |
82 mutex().AssertHeld(); | 82 mutex().AssertHeld(); |
83 return Create(platform_handle_.Pass()); | 83 return Create(platform_handle_.Pass()); |
84 } | 84 } |
85 | 85 |
86 void PlatformHandleDispatcher::StartSerializeImplNoLock( | 86 void PlatformHandleDispatcher::StartSerializeImplNoLock( |
87 Channel* /*channel*/, | 87 Channel* /*channel*/, |
88 size_t* max_size, | 88 size_t* max_size, |
89 size_t* max_platform_handles) { | 89 size_t* max_platform_handles) { |
90 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. | 90 AssertHasOneRef(); // Only one ref => no need to take the lock. |
91 *max_size = sizeof(SerializedPlatformHandleDispatcher); | 91 *max_size = sizeof(SerializedPlatformHandleDispatcher); |
92 *max_platform_handles = 1; | 92 *max_platform_handles = 1; |
93 } | 93 } |
94 | 94 |
95 bool PlatformHandleDispatcher::EndSerializeAndCloseImplNoLock( | 95 bool PlatformHandleDispatcher::EndSerializeAndCloseImplNoLock( |
96 Channel* /*channel*/, | 96 Channel* /*channel*/, |
97 void* destination, | 97 void* destination, |
98 size_t* actual_size, | 98 size_t* actual_size, |
99 embedder::PlatformHandleVector* platform_handles) { | 99 embedder::PlatformHandleVector* platform_handles) { |
100 DCHECK(HasOneRef()); // Only one ref => no need to take the lock. | 100 AssertHasOneRef(); // Only one ref => no need to take the lock. |
101 | 101 |
102 SerializedPlatformHandleDispatcher* serialization = | 102 SerializedPlatformHandleDispatcher* serialization = |
103 static_cast<SerializedPlatformHandleDispatcher*>(destination); | 103 static_cast<SerializedPlatformHandleDispatcher*>(destination); |
104 if (platform_handle_.is_valid()) { | 104 if (platform_handle_.is_valid()) { |
105 serialization->platform_handle_index = platform_handles->size(); | 105 serialization->platform_handle_index = platform_handles->size(); |
106 platform_handles->push_back(platform_handle_.release()); | 106 platform_handles->push_back(platform_handle_.release()); |
107 } else { | 107 } else { |
108 serialization->platform_handle_index = kInvalidPlatformHandleIndex; | 108 serialization->platform_handle_index = kInvalidPlatformHandleIndex; |
109 } | 109 } |
110 | 110 |
111 *actual_size = sizeof(SerializedPlatformHandleDispatcher); | 111 *actual_size = sizeof(SerializedPlatformHandleDispatcher); |
112 return true; | 112 return true; |
113 } | 113 } |
114 | 114 |
115 } // namespace system | 115 } // namespace system |
116 } // namespace mojo | 116 } // namespace mojo |
OLD | NEW |