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

Side by Side Diff: base/memory/ref_counted_memory.cc

Issue 1803263002: base: Make RefCountedBytes::TakeVector return ref ptr instead of raw ptr (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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "base/memory/ref_counted_memory.h" 5 #include "base/memory/ref_counted_memory.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 8
9 namespace base { 9 namespace base {
10 10
(...skipping 20 matching lines...) Expand all
31 31
32 RefCountedBytes::RefCountedBytes() {} 32 RefCountedBytes::RefCountedBytes() {}
33 33
34 RefCountedBytes::RefCountedBytes(const std::vector<unsigned char>& initializer) 34 RefCountedBytes::RefCountedBytes(const std::vector<unsigned char>& initializer)
35 : data_(initializer) { 35 : data_(initializer) {
36 } 36 }
37 37
38 RefCountedBytes::RefCountedBytes(const unsigned char* p, size_t size) 38 RefCountedBytes::RefCountedBytes(const unsigned char* p, size_t size)
39 : data_(p, p + size) {} 39 : data_(p, p + size) {}
40 40
41 RefCountedBytes* RefCountedBytes::TakeVector( 41 scoped_refptr<RefCountedBytes> RefCountedBytes::TakeVector(
42 std::vector<unsigned char>* to_destroy) { 42 std::vector<unsigned char>* to_destroy) {
43 RefCountedBytes* bytes = new RefCountedBytes; 43 scoped_refptr<RefCountedBytes> bytes(new RefCountedBytes);
44 bytes->data_.swap(*to_destroy); 44 bytes->data_.swap(*to_destroy);
45 return bytes; 45 return bytes;
46 } 46 }
47 47
48 const unsigned char* RefCountedBytes::front() const { 48 const unsigned char* RefCountedBytes::front() const {
49 // STL will assert if we do front() on an empty vector, but calling code 49 // STL will assert if we do front() on an empty vector, but calling code
50 // expects a NULL. 50 // expects a NULL.
51 return size() ? &data_.front() : NULL; 51 return size() ? &data_.front() : NULL;
52 } 52 }
53 53
(...skipping 18 matching lines...) Expand all
72 const unsigned char* RefCountedString::front() const { 72 const unsigned char* RefCountedString::front() const {
73 return data_.empty() ? NULL : 73 return data_.empty() ? NULL :
74 reinterpret_cast<const unsigned char*>(data_.data()); 74 reinterpret_cast<const unsigned char*>(data_.data());
75 } 75 }
76 76
77 size_t RefCountedString::size() const { 77 size_t RefCountedString::size() const {
78 return data_.size(); 78 return data_.size();
79 } 79 }
80 80
81 } // namespace base 81 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/ref_counted_memory.h ('k') | chrome/browser/history/android/sqlite_cursor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698