| 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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "mojo/edk/embedder/platform_handle_utils.h" | 8 #include "mojo/edk/embedder/platform_handle_utils.h" |
| 9 | 9 |
| 10 namespace mojo { | 10 namespace mojo { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 return nullptr; | 41 return nullptr; |
| 42 } | 42 } |
| 43 | 43 |
| 44 return rv; | 44 return rv; |
| 45 } | 45 } |
| 46 | 46 |
| 47 size_t SimplePlatformSharedBuffer::GetNumBytes() const { | 47 size_t SimplePlatformSharedBuffer::GetNumBytes() const { |
| 48 return num_bytes_; | 48 return num_bytes_; |
| 49 } | 49 } |
| 50 | 50 |
| 51 scoped_ptr<PlatformSharedBufferMapping> SimplePlatformSharedBuffer::Map( | 51 std::unique_ptr<PlatformSharedBufferMapping> SimplePlatformSharedBuffer::Map( |
| 52 size_t offset, | 52 size_t offset, |
| 53 size_t length) { | 53 size_t length) { |
| 54 if (!IsValidMap(offset, length)) | 54 if (!IsValidMap(offset, length)) |
| 55 return nullptr; | 55 return nullptr; |
| 56 | 56 |
| 57 return MapNoCheck(offset, length); | 57 return MapNoCheck(offset, length); |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool SimplePlatformSharedBuffer::IsValidMap(size_t offset, size_t length) { | 60 bool SimplePlatformSharedBuffer::IsValidMap(size_t offset, size_t length) { |
| 61 if (offset > num_bytes_ || length == 0) | 61 if (offset > num_bytes_ || length == 0) |
| 62 return false; | 62 return false; |
| 63 | 63 |
| 64 // Note: This is an overflow-safe check of |offset + length > num_bytes_| | 64 // Note: This is an overflow-safe check of |offset + length > num_bytes_| |
| 65 // (that |num_bytes >= offset| is verified above). | 65 // (that |num_bytes >= offset| is verified above). |
| 66 if (length > num_bytes_ - offset) | 66 if (length > num_bytes_ - offset) |
| 67 return false; | 67 return false; |
| 68 | 68 |
| 69 return true; | 69 return true; |
| 70 } | 70 } |
| 71 | 71 |
| 72 scoped_ptr<PlatformSharedBufferMapping> SimplePlatformSharedBuffer::MapNoCheck( | 72 std::unique_ptr<PlatformSharedBufferMapping> |
| 73 size_t offset, | 73 SimplePlatformSharedBuffer::MapNoCheck(size_t offset, size_t length) { |
| 74 size_t length) { | |
| 75 DCHECK(IsValidMap(offset, length)); | 74 DCHECK(IsValidMap(offset, length)); |
| 76 return MapImpl(offset, length); | 75 return MapImpl(offset, length); |
| 77 } | 76 } |
| 78 | 77 |
| 79 ScopedPlatformHandle SimplePlatformSharedBuffer::DuplicatePlatformHandle() { | 78 ScopedPlatformHandle SimplePlatformSharedBuffer::DuplicatePlatformHandle() { |
| 80 return mojo::embedder::DuplicatePlatformHandle(handle_.get()); | 79 return mojo::embedder::DuplicatePlatformHandle(handle_.get()); |
| 81 } | 80 } |
| 82 | 81 |
| 83 ScopedPlatformHandle SimplePlatformSharedBuffer::PassPlatformHandle() { | 82 ScopedPlatformHandle SimplePlatformSharedBuffer::PassPlatformHandle() { |
| 84 DCHECK(HasOneRef()); | 83 DCHECK(HasOneRef()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 99 void* SimplePlatformSharedBufferMapping::GetBase() const { | 98 void* SimplePlatformSharedBufferMapping::GetBase() const { |
| 100 return base_; | 99 return base_; |
| 101 } | 100 } |
| 102 | 101 |
| 103 size_t SimplePlatformSharedBufferMapping::GetLength() const { | 102 size_t SimplePlatformSharedBufferMapping::GetLength() const { |
| 104 return length_; | 103 return length_; |
| 105 } | 104 } |
| 106 | 105 |
| 107 } // namespace embedder | 106 } // namespace embedder |
| 108 } // namespace mojo | 107 } // namespace mojo |
| OLD | NEW |