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; | |
michaeln
2015/01/22 21:57:46
maybe also set bytes_ to nullptr
dmurph
2015/01/23 00:42:00
Done.
| |
59 } | |
60 | |
61 // Copies and appends the given data into the element. SetToEmptyBytes or | |
62 // SetToBytes must be called before this method. | |
63 void AppendBytes(const char* bytes, int bytes_len) { | |
64 DCHECK_EQ(type_, TYPE_BYTES); | |
65 DCHECK_NE(length_, kuint64max); | |
michaeln
2015/01/22 21:57:46
i think you can DCHECK(!bytes_);
dmurph
2015/01/23 00:42:00
Done.
| |
66 buf_.insert(buf_.end(), bytes, bytes + bytes_len); | |
67 length_ += buf_.size(); | |
68 } | |
69 | |
53 // Sets TYPE_BYTES data. This does NOT copy the given data and the caller | 70 // 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. | 71 // should make sure the data is alive when this element is accessed. |
72 // You cannot use AppendBytes with this method. | |
55 void SetToSharedBytes(const char* bytes, int bytes_len) { | 73 void SetToSharedBytes(const char* bytes, int bytes_len) { |
56 type_ = TYPE_BYTES; | 74 type_ = TYPE_BYTES; |
57 bytes_ = bytes; | 75 bytes_ = bytes; |
58 length_ = bytes_len; | 76 length_ = bytes_len; |
59 } | 77 } |
60 | 78 |
61 // Sets TYPE_FILE data. | 79 // Sets TYPE_FILE data. |
62 void SetToFilePath(const base::FilePath& path) { | 80 void SetToFilePath(const base::FilePath& path) { |
63 SetToFilePathRange(path, 0, kuint64max, base::Time()); | 81 SetToFilePathRange(path, 0, kuint64max, base::Time()); |
64 } | 82 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 } | 136 } |
119 | 137 |
120 inline bool operator!=(const DataElement& a, const DataElement& b) { | 138 inline bool operator!=(const DataElement& a, const DataElement& b) { |
121 return !(a == b); | 139 return !(a == b); |
122 } | 140 } |
123 #endif // defined(UNIT_TEST) | 141 #endif // defined(UNIT_TEST) |
124 | 142 |
125 } // namespace storage | 143 } // namespace storage |
126 | 144 |
127 #endif // STORAGE_COMMON_DATA_ELEMENT_H_ | 145 #endif // STORAGE_COMMON_DATA_ELEMENT_H_ |
OLD | NEW |