OLD | NEW |
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 Loading... |
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 | |
72 // Sets TYPE_BYTES data. This does NOT copy the given data and the caller | 53 // Sets TYPE_BYTES data. This does NOT copy the given data and the caller |
73 // should make sure the data is alive when this element is accessed. | 54 // should make sure the data is alive when this element is accessed. |
74 // You cannot use AppendBytes with this method. | |
75 void SetToSharedBytes(const char* bytes, int bytes_len) { | 55 void SetToSharedBytes(const char* bytes, int bytes_len) { |
76 type_ = TYPE_BYTES; | 56 type_ = TYPE_BYTES; |
77 bytes_ = bytes; | 57 bytes_ = bytes; |
78 length_ = bytes_len; | 58 length_ = bytes_len; |
79 } | 59 } |
80 | 60 |
81 // Sets TYPE_FILE data. | 61 // Sets TYPE_FILE data. |
82 void SetToFilePath(const base::FilePath& path) { | 62 void SetToFilePath(const base::FilePath& path) { |
83 SetToFilePathRange(path, 0, kuint64max, base::Time()); | 63 SetToFilePathRange(path, 0, kuint64max, base::Time()); |
84 } | 64 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 } | 118 } |
139 | 119 |
140 inline bool operator!=(const DataElement& a, const DataElement& b) { | 120 inline bool operator!=(const DataElement& a, const DataElement& b) { |
141 return !(a == b); | 121 return !(a == b); |
142 } | 122 } |
143 #endif // defined(UNIT_TEST) | 123 #endif // defined(UNIT_TEST) |
144 | 124 |
145 } // namespace storage | 125 } // namespace storage |
146 | 126 |
147 #endif // STORAGE_COMMON_DATA_ELEMENT_H_ | 127 #endif // STORAGE_COMMON_DATA_ELEMENT_H_ |
OLD | NEW |