Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "media/cdm/simple_cdm_buffer.h" | 5 #include "media/cdm/simple_cdm_buffer.h" |
| 6 | 6 |
| 7 #include <limits> | |
| 8 | |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/numerics/safe_conversions.h" | |
| 8 | 11 |
| 9 namespace media { | 12 namespace media { |
| 10 | 13 |
| 11 // static | 14 // static |
| 12 SimpleCdmBuffer* SimpleCdmBuffer::Create(uint32_t capacity) { | 15 SimpleCdmBuffer* SimpleCdmBuffer::Create(size_t capacity) { |
| 13 DCHECK(capacity); | 16 DCHECK(capacity); |
| 14 return new SimpleCdmBuffer(capacity); | 17 |
| 18 // cdm::Buffer interface limits capacity to uint32. | |
| 19 DCHECK_LE(capacity, | |
| 20 static_cast<size_t>(std::numeric_limits<uint32_t>::max())); | |
|
xhwang
2016/03/15 18:57:37
OOC, can you drop the static_cast since both size_
jrummell
2016/03/15 19:43:12
Done.
| |
| 21 return new SimpleCdmBuffer(base::checked_cast<uint32_t>(capacity)); | |
| 15 } | 22 } |
| 16 | 23 |
| 17 SimpleCdmBuffer::SimpleCdmBuffer(uint32_t capacity) | 24 SimpleCdmBuffer::SimpleCdmBuffer(uint32_t capacity) |
| 18 : buffer_(capacity), size_(0) {} | 25 : buffer_(capacity), size_(0) {} |
| 19 | 26 |
| 20 SimpleCdmBuffer::~SimpleCdmBuffer() {} | 27 SimpleCdmBuffer::~SimpleCdmBuffer() {} |
| 21 | 28 |
| 22 void SimpleCdmBuffer::Destroy() { | 29 void SimpleCdmBuffer::Destroy() { |
| 23 delete this; | 30 delete this; |
| 24 } | 31 } |
| 25 | 32 |
| 26 uint32_t SimpleCdmBuffer::Capacity() const { | 33 uint32_t SimpleCdmBuffer::Capacity() const { |
| 27 return buffer_.size(); | 34 return buffer_.size(); |
| 28 } | 35 } |
| 29 | 36 |
| 30 uint8_t* SimpleCdmBuffer::Data() { | 37 uint8_t* SimpleCdmBuffer::Data() { |
| 31 return buffer_.data(); | 38 return buffer_.data(); |
| 32 } | 39 } |
| 33 | 40 |
| 34 void SimpleCdmBuffer::SetSize(uint32_t size) { | 41 void SimpleCdmBuffer::SetSize(uint32_t size) { |
| 35 DCHECK(size <= Capacity()); | 42 DCHECK(size <= Capacity()); |
| 36 size_ = size > Capacity() ? 0 : size; | 43 size_ = size > Capacity() ? 0 : size; |
| 37 } | 44 } |
| 38 | 45 |
| 39 uint32_t SimpleCdmBuffer::Size() const { | 46 uint32_t SimpleCdmBuffer::Size() const { |
| 40 return size_; | 47 return size_; |
| 41 } | 48 } |
| 42 | 49 |
| 43 } // namespace media | 50 } // namespace media |
| OLD | NEW |