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/system/shared_buffer_dispatcher.h" | 5 #include "mojo/system/shared_buffer_dispatcher.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "mojo/embedder/simple_platform_shared_buffer.h" | 11 #include "mojo/embedder/platform_support.h" |
| 12 #include "mojo/embedder/simple_platform_shared_buffer.h" // TODO(vtl): Remove. |
12 #include "mojo/public/c/system/macros.h" | 13 #include "mojo/public/c/system/macros.h" |
13 #include "mojo/system/constants.h" | 14 #include "mojo/system/constants.h" |
14 #include "mojo/system/memory.h" | 15 #include "mojo/system/memory.h" |
15 #include "mojo/system/options_validation.h" | 16 #include "mojo/system/options_validation.h" |
16 | 17 |
17 namespace mojo { | 18 namespace mojo { |
18 namespace system { | 19 namespace system { |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 56 |
56 // Checks for fields beyond |flags|: | 57 // Checks for fields beyond |flags|: |
57 | 58 |
58 // (Nothing here yet.) | 59 // (Nothing here yet.) |
59 | 60 |
60 return MOJO_RESULT_OK; | 61 return MOJO_RESULT_OK; |
61 } | 62 } |
62 | 63 |
63 // static | 64 // static |
64 MojoResult SharedBufferDispatcher::Create( | 65 MojoResult SharedBufferDispatcher::Create( |
| 66 embedder::PlatformSupport* platform_support, |
65 const MojoCreateSharedBufferOptions& /*validated_options*/, | 67 const MojoCreateSharedBufferOptions& /*validated_options*/, |
66 uint64_t num_bytes, | 68 uint64_t num_bytes, |
67 scoped_refptr<SharedBufferDispatcher>* result) { | 69 scoped_refptr<SharedBufferDispatcher>* result) { |
68 if (!num_bytes) | 70 if (!num_bytes) |
69 return MOJO_RESULT_INVALID_ARGUMENT; | 71 return MOJO_RESULT_INVALID_ARGUMENT; |
70 if (num_bytes > kMaxSharedMemoryNumBytes) | 72 if (num_bytes > kMaxSharedMemoryNumBytes) |
71 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 73 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
72 | 74 |
73 // TODO(vtl): Call out to "platform support" for this. | |
74 scoped_refptr<embedder::PlatformSharedBuffer> shared_buffer( | 75 scoped_refptr<embedder::PlatformSharedBuffer> shared_buffer( |
75 embedder::SimplePlatformSharedBuffer::Create( | 76 platform_support->CreateSharedBuffer(static_cast<size_t>(num_bytes))); |
76 static_cast<size_t>(num_bytes))); | |
77 if (!shared_buffer) | 77 if (!shared_buffer) |
78 return MOJO_RESULT_RESOURCE_EXHAUSTED; | 78 return MOJO_RESULT_RESOURCE_EXHAUSTED; |
79 | 79 |
80 *result = new SharedBufferDispatcher(shared_buffer); | 80 *result = new SharedBufferDispatcher(shared_buffer); |
81 return MOJO_RESULT_OK; | 81 return MOJO_RESULT_OK; |
82 } | 82 } |
83 | 83 |
84 Dispatcher::Type SharedBufferDispatcher::GetType() const { | 84 Dispatcher::Type SharedBufferDispatcher::GetType() const { |
85 return kTypeSharedBuffer; | 85 return kTypeSharedBuffer; |
86 } | 86 } |
(...skipping 27 matching lines...) Expand all Loading... |
114 } | 114 } |
115 | 115 |
116 // Starts off invalid, which is what we want. | 116 // Starts off invalid, which is what we want. |
117 embedder::PlatformHandle platform_handle; | 117 embedder::PlatformHandle platform_handle; |
118 // We take ownership of the handle, so we have to invalidate the one in | 118 // We take ownership of the handle, so we have to invalidate the one in |
119 // |platform_handles|. | 119 // |platform_handles|. |
120 std::swap(platform_handle, (*platform_handles)[platform_handle_index]); | 120 std::swap(platform_handle, (*platform_handles)[platform_handle_index]); |
121 | 121 |
122 // Wrapping |platform_handle| in a |ScopedPlatformHandle| means that it'll be | 122 // Wrapping |platform_handle| in a |ScopedPlatformHandle| means that it'll be |
123 // closed even if creation fails. | 123 // closed even if creation fails. |
| 124 // TODO(vtl): This is obviously wrong -- but we need to have a |
| 125 // |PlatformSupport| plumbed through (probably via the |Channel|), and use its |
| 126 // |CreateSharedBufferFromHandle()|. |
124 scoped_refptr<embedder::PlatformSharedBuffer> shared_buffer( | 127 scoped_refptr<embedder::PlatformSharedBuffer> shared_buffer( |
125 embedder::SimplePlatformSharedBuffer::CreateFromPlatformHandle( | 128 embedder::SimplePlatformSharedBuffer::CreateFromPlatformHandle( |
126 num_bytes, embedder::ScopedPlatformHandle(platform_handle))); | 129 num_bytes, embedder::ScopedPlatformHandle(platform_handle))); |
127 if (!shared_buffer) { | 130 if (!shared_buffer) { |
128 LOG(ERROR) | 131 LOG(ERROR) |
129 << "Invalid serialized shared buffer dispatcher (invalid num_bytes?)"; | 132 << "Invalid serialized shared buffer dispatcher (invalid num_bytes?)"; |
130 return scoped_refptr<SharedBufferDispatcher>(); | 133 return scoped_refptr<SharedBufferDispatcher>(); |
131 } | 134 } |
132 | 135 |
133 return scoped_refptr<SharedBufferDispatcher>( | 136 return scoped_refptr<SharedBufferDispatcher>( |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 platform_handles->push_back(platform_handle.release()); | 268 platform_handles->push_back(platform_handle.release()); |
266 *actual_size = sizeof(SerializedSharedBufferDispatcher); | 269 *actual_size = sizeof(SerializedSharedBufferDispatcher); |
267 | 270 |
268 shared_buffer_ = NULL; | 271 shared_buffer_ = NULL; |
269 | 272 |
270 return true; | 273 return true; |
271 } | 274 } |
272 | 275 |
273 } // namespace system | 276 } // namespace system |
274 } // namespace mojo | 277 } // namespace mojo |
OLD | NEW |