| 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 25 matching lines...) Expand all Loading... |
| 36 } | 36 } |
| 37 | 37 |
| 38 // static | 38 // static |
| 39 scoped_refptr<PlatformHandleDispatcher> PlatformHandleDispatcher::Deserialize( | 39 scoped_refptr<PlatformHandleDispatcher> PlatformHandleDispatcher::Deserialize( |
| 40 Channel* channel, | 40 Channel* channel, |
| 41 const void* source, | 41 const void* source, |
| 42 size_t size, | 42 size_t size, |
| 43 embedder::PlatformHandleVector* platform_handles) { | 43 embedder::PlatformHandleVector* platform_handles) { |
| 44 if (size != sizeof(SerializedPlatformHandleDispatcher)) { | 44 if (size != sizeof(SerializedPlatformHandleDispatcher)) { |
| 45 LOG(ERROR) << "Invalid serialized platform handle dispatcher (bad size)"; | 45 LOG(ERROR) << "Invalid serialized platform handle dispatcher (bad size)"; |
| 46 return scoped_refptr<PlatformHandleDispatcher>(); | 46 return nullptr; |
| 47 } | 47 } |
| 48 | 48 |
| 49 const SerializedPlatformHandleDispatcher* serialization = | 49 const SerializedPlatformHandleDispatcher* serialization = |
| 50 static_cast<const SerializedPlatformHandleDispatcher*>(source); | 50 static_cast<const SerializedPlatformHandleDispatcher*>(source); |
| 51 size_t platform_handle_index = serialization->platform_handle_index; | 51 size_t platform_handle_index = serialization->platform_handle_index; |
| 52 | 52 |
| 53 // Starts off invalid, which is what we want. | 53 // Starts off invalid, which is what we want. |
| 54 embedder::PlatformHandle platform_handle; | 54 embedder::PlatformHandle platform_handle; |
| 55 | 55 |
| 56 if (platform_handle_index != kInvalidPlatformHandleIndex) { | 56 if (platform_handle_index != kInvalidPlatformHandleIndex) { |
| 57 if (!platform_handles || | 57 if (!platform_handles || |
| 58 platform_handle_index >= platform_handles->size()) { | 58 platform_handle_index >= platform_handles->size()) { |
| 59 LOG(ERROR) | 59 LOG(ERROR) |
| 60 << "Invalid serialized platform handle dispatcher (missing handles)"; | 60 << "Invalid serialized platform handle dispatcher (missing handles)"; |
| 61 return scoped_refptr<PlatformHandleDispatcher>(); | 61 return nullptr; |
| 62 } | 62 } |
| 63 | 63 |
| 64 // We take ownership of the handle, so we have to invalidate the one in | 64 // We take ownership of the handle, so we have to invalidate the one in |
| 65 // |platform_handles|. | 65 // |platform_handles|. |
| 66 std::swap(platform_handle, (*platform_handles)[platform_handle_index]); | 66 std::swap(platform_handle, (*platform_handles)[platform_handle_index]); |
| 67 } | 67 } |
| 68 | 68 |
| 69 return scoped_refptr<PlatformHandleDispatcher>(new PlatformHandleDispatcher( | 69 return scoped_refptr<PlatformHandleDispatcher>(new PlatformHandleDispatcher( |
| 70 embedder::ScopedPlatformHandle(platform_handle))); | 70 embedder::ScopedPlatformHandle(platform_handle))); |
| 71 } | 71 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 } else { | 109 } else { |
| 110 serialization->platform_handle_index = kInvalidPlatformHandleIndex; | 110 serialization->platform_handle_index = kInvalidPlatformHandleIndex; |
| 111 } | 111 } |
| 112 | 112 |
| 113 *actual_size = sizeof(SerializedPlatformHandleDispatcher); | 113 *actual_size = sizeof(SerializedPlatformHandleDispatcher); |
| 114 return true; | 114 return true; |
| 115 } | 115 } |
| 116 | 116 |
| 117 } // namespace system | 117 } // namespace system |
| 118 } // namespace mojo | 118 } // namespace mojo |
| OLD | NEW |