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/embedder/simple_platform_shared_buffer.h" | 5 #include "mojo/edk/embedder/simple_platform_shared_buffer.h" |
6 | 6 |
| 7 #include <utility> |
| 8 |
7 #include "base/logging.h" | 9 #include "base/logging.h" |
8 #include "mojo/edk/embedder/platform_handle_utils.h" | 10 #include "mojo/edk/embedder/platform_handle_utils.h" |
9 | 11 |
10 namespace mojo { | 12 namespace mojo { |
11 namespace edk { | 13 namespace edk { |
12 | 14 |
13 // static | 15 // static |
14 SimplePlatformSharedBuffer* SimplePlatformSharedBuffer::Create( | 16 SimplePlatformSharedBuffer* SimplePlatformSharedBuffer::Create( |
15 size_t num_bytes) { | 17 size_t num_bytes) { |
16 DCHECK_GT(num_bytes, 0u); | 18 DCHECK_GT(num_bytes, 0u); |
(...skipping 10 matching lines...) Expand all Loading... |
27 } | 29 } |
28 | 30 |
29 // static | 31 // static |
30 SimplePlatformSharedBuffer* | 32 SimplePlatformSharedBuffer* |
31 SimplePlatformSharedBuffer::CreateFromPlatformHandle( | 33 SimplePlatformSharedBuffer::CreateFromPlatformHandle( |
32 size_t num_bytes, | 34 size_t num_bytes, |
33 ScopedPlatformHandle platform_handle) { | 35 ScopedPlatformHandle platform_handle) { |
34 DCHECK_GT(num_bytes, 0u); | 36 DCHECK_GT(num_bytes, 0u); |
35 | 37 |
36 SimplePlatformSharedBuffer* rv = new SimplePlatformSharedBuffer(num_bytes); | 38 SimplePlatformSharedBuffer* rv = new SimplePlatformSharedBuffer(num_bytes); |
37 if (!rv->InitFromPlatformHandle(platform_handle.Pass())) { | 39 if (!rv->InitFromPlatformHandle(std::move(platform_handle))) { |
38 // We can't just delete it directly, due to the "in destructor" (debug) | 40 // We can't just delete it directly, due to the "in destructor" (debug) |
39 // check. | 41 // check. |
40 scoped_refptr<SimplePlatformSharedBuffer> deleter(rv); | 42 scoped_refptr<SimplePlatformSharedBuffer> deleter(rv); |
41 return nullptr; | 43 return nullptr; |
42 } | 44 } |
43 | 45 |
44 return rv; | 46 return rv; |
45 } | 47 } |
46 | 48 |
47 size_t SimplePlatformSharedBuffer::GetNumBytes() const { | 49 size_t SimplePlatformSharedBuffer::GetNumBytes() const { |
(...skipping 27 matching lines...) Expand all Loading... |
75 DCHECK(IsValidMap(offset, length)); | 77 DCHECK(IsValidMap(offset, length)); |
76 return MapImpl(offset, length); | 78 return MapImpl(offset, length); |
77 } | 79 } |
78 | 80 |
79 ScopedPlatformHandle SimplePlatformSharedBuffer::DuplicatePlatformHandle() { | 81 ScopedPlatformHandle SimplePlatformSharedBuffer::DuplicatePlatformHandle() { |
80 return mojo::edk::DuplicatePlatformHandle(handle_.get()); | 82 return mojo::edk::DuplicatePlatformHandle(handle_.get()); |
81 } | 83 } |
82 | 84 |
83 ScopedPlatformHandle SimplePlatformSharedBuffer::PassPlatformHandle() { | 85 ScopedPlatformHandle SimplePlatformSharedBuffer::PassPlatformHandle() { |
84 DCHECK(HasOneRef()); | 86 DCHECK(HasOneRef()); |
85 return handle_.Pass(); | 87 return std::move(handle_); |
86 } | 88 } |
87 | 89 |
88 SimplePlatformSharedBuffer::SimplePlatformSharedBuffer(size_t num_bytes) | 90 SimplePlatformSharedBuffer::SimplePlatformSharedBuffer(size_t num_bytes) |
89 : num_bytes_(num_bytes) { | 91 : num_bytes_(num_bytes) { |
90 } | 92 } |
91 | 93 |
92 SimplePlatformSharedBuffer::~SimplePlatformSharedBuffer() { | 94 SimplePlatformSharedBuffer::~SimplePlatformSharedBuffer() { |
93 } | 95 } |
94 | 96 |
95 SimplePlatformSharedBufferMapping::~SimplePlatformSharedBufferMapping() { | 97 SimplePlatformSharedBufferMapping::~SimplePlatformSharedBufferMapping() { |
96 Unmap(); | 98 Unmap(); |
97 } | 99 } |
98 | 100 |
99 void* SimplePlatformSharedBufferMapping::GetBase() const { | 101 void* SimplePlatformSharedBufferMapping::GetBase() const { |
100 return base_; | 102 return base_; |
101 } | 103 } |
102 | 104 |
103 size_t SimplePlatformSharedBufferMapping::GetLength() const { | 105 size_t SimplePlatformSharedBufferMapping::GetLength() const { |
104 return length_; | 106 return length_; |
105 } | 107 } |
106 | 108 |
107 } // namespace edk | 109 } // namespace edk |
108 } // namespace mojo | 110 } // namespace mojo |
OLD | NEW |