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 |
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 Loading... |
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_ |
OLD | NEW |