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

Side by Side Diff: storage/common/data_element.h

Issue 821913004: [Storage] Consoliation of BlobItems with small size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge and length calc fix Created 5 years, 11 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
« no previous file with comments | « content/child/webblobregistry_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 #ifndef STORAGE_COMMON_DATA_ELEMENT_H_ 5 #ifndef STORAGE_COMMON_DATA_ELEMENT_H_
6 #define STORAGE_COMMON_DATA_ELEMENT_H_ 6 #define STORAGE_COMMON_DATA_ELEMENT_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 return expected_modification_time_; 43 return expected_modification_time_;
44 } 44 }
45 45
46 // Sets TYPE_BYTES data. This copies the given data into the element. 46 // Sets TYPE_BYTES data. This copies the given data into the element.
47 void SetToBytes(const char* bytes, int bytes_len) { 47 void SetToBytes(const char* bytes, int bytes_len) {
48 type_ = TYPE_BYTES; 48 type_ = TYPE_BYTES;
49 buf_.assign(bytes, bytes + bytes_len); 49 buf_.assign(bytes, bytes + bytes_len);
50 length_ = buf_.size(); 50 length_ = buf_.size();
51 } 51 }
52 52
53 // Sets TYPE_BYTES data, and clears the internal bytes buffer.
54 // For use with AppendBytes.
55 void SetToEmptyBytes() {
56 type_ = TYPE_BYTES;
57 buf_.clear();
58 length_ = 0;
59 bytes_ = nullptr;
60 }
61
62 // Copies and appends the given data into the element. SetToEmptyBytes or
63 // SetToBytes must be called before this method.
64 void AppendBytes(const char* bytes, int bytes_len) {
65 DCHECK_EQ(type_, TYPE_BYTES);
66 DCHECK_NE(length_, kuint64max);
67 DCHECK(!bytes_);
68 buf_.insert(buf_.end(), bytes, bytes + bytes_len);
69 length_ = buf_.size();
70 }
71
53 // Sets TYPE_BYTES data. This does NOT copy the given data and the caller 72 // Sets TYPE_BYTES data. This does NOT copy the given data and the caller
54 // should make sure the data is alive when this element is accessed. 73 // should make sure the data is alive when this element is accessed.
74 // You cannot use AppendBytes with this method.
55 void SetToSharedBytes(const char* bytes, int bytes_len) { 75 void SetToSharedBytes(const char* bytes, int bytes_len) {
56 type_ = TYPE_BYTES; 76 type_ = TYPE_BYTES;
57 bytes_ = bytes; 77 bytes_ = bytes;
58 length_ = bytes_len; 78 length_ = bytes_len;
59 } 79 }
60 80
61 // Sets TYPE_FILE data. 81 // Sets TYPE_FILE data.
62 void SetToFilePath(const base::FilePath& path) { 82 void SetToFilePath(const base::FilePath& path) {
63 SetToFilePathRange(path, 0, kuint64max, base::Time()); 83 SetToFilePathRange(path, 0, kuint64max, base::Time());
64 } 84 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 } 138 }
119 139
120 inline bool operator!=(const DataElement& a, const DataElement& b) { 140 inline bool operator!=(const DataElement& a, const DataElement& b) {
121 return !(a == b); 141 return !(a == b);
122 } 142 }
123 #endif // defined(UNIT_TEST) 143 #endif // defined(UNIT_TEST)
124 144
125 } // namespace storage 145 } // namespace storage
126 146
127 #endif // STORAGE_COMMON_DATA_ELEMENT_H_ 147 #endif // STORAGE_COMMON_DATA_ELEMENT_H_
OLDNEW
« no previous file with comments | « content/child/webblobregistry_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698