Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(211)

Side by Side Diff: media/cdm/simple_cdm_buffer.cc

Issue 1802183002: Convert CreateCdmBuffer() to use size_t for |capacity| (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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. Requests bigger than
19 // uint32_max will fail.
20 if (capacity > static_cast<size_t>(std::numeric_limits<uint32_t>::max()))
21 return nullptr;
xhwang 2016/03/15 06:17:22 This should really never happen since the caller o
jrummell 2016/03/15 18:49:42 Done.
22
23 return new SimpleCdmBuffer(base::checked_cast<uint32_t>(capacity));
15 } 24 }
16 25
17 SimpleCdmBuffer::SimpleCdmBuffer(uint32_t capacity) 26 SimpleCdmBuffer::SimpleCdmBuffer(uint32_t capacity)
18 : buffer_(capacity), size_(0) {} 27 : buffer_(capacity), size_(0) {}
19 28
20 SimpleCdmBuffer::~SimpleCdmBuffer() {} 29 SimpleCdmBuffer::~SimpleCdmBuffer() {}
21 30
22 void SimpleCdmBuffer::Destroy() { 31 void SimpleCdmBuffer::Destroy() {
23 delete this; 32 delete this;
24 } 33 }
25 34
26 uint32_t SimpleCdmBuffer::Capacity() const { 35 uint32_t SimpleCdmBuffer::Capacity() const {
27 return buffer_.size(); 36 return buffer_.size();
28 } 37 }
29 38
30 uint8_t* SimpleCdmBuffer::Data() { 39 uint8_t* SimpleCdmBuffer::Data() {
31 return buffer_.data(); 40 return buffer_.data();
32 } 41 }
33 42
34 void SimpleCdmBuffer::SetSize(uint32_t size) { 43 void SimpleCdmBuffer::SetSize(uint32_t size) {
35 DCHECK(size <= Capacity()); 44 DCHECK(size <= Capacity());
36 size_ = size > Capacity() ? 0 : size; 45 size_ = size > Capacity() ? 0 : size;
37 } 46 }
38 47
39 uint32_t SimpleCdmBuffer::Size() const { 48 uint32_t SimpleCdmBuffer::Size() const {
40 return size_; 49 return size_;
41 } 50 }
42 51
43 } // namespace media 52 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698