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

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

Issue 1502503004: Remove kuint64max. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint8
Patch Set: rebase Created 5 years 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 | « storage/common/blob_storage/blob_item_bytes_request.h ('k') | storage/common/data_element.cc » ('j') | 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 <stdint.h>
9
10 #include <limits>
8 #include <ostream> 11 #include <ostream>
9 #include <string> 12 #include <string>
10 #include <vector> 13 #include <vector>
11 14
12 #include "base/basictypes.h"
13 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
14 #include "base/gtest_prod_util.h" 16 #include "base/gtest_prod_util.h"
15 #include "base/logging.h" 17 #include "base/logging.h"
16 #include "base/time/time.h" 18 #include "base/time/time.h"
17 #include "storage/common/storage_common_export.h" 19 #include "storage/common/storage_common_export.h"
18 #include "url/gurl.h" 20 #include "url/gurl.h"
19 21
20 namespace storage { 22 namespace storage {
21 23
22 // Represents a base Web data element. This could be either one of 24 // Represents a base Web data element. This could be either one of
(...skipping 12 matching lines...) Expand all
35 }; 37 };
36 38
37 DataElement(); 39 DataElement();
38 ~DataElement(); 40 ~DataElement();
39 41
40 Type type() const { return type_; } 42 Type type() const { return type_; }
41 const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; } 43 const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; }
42 const base::FilePath& path() const { return path_; } 44 const base::FilePath& path() const { return path_; }
43 const GURL& filesystem_url() const { return filesystem_url_; } 45 const GURL& filesystem_url() const { return filesystem_url_; }
44 const std::string& blob_uuid() const { return blob_uuid_; } 46 const std::string& blob_uuid() const { return blob_uuid_; }
45 uint64 offset() const { return offset_; } 47 uint64_t offset() const { return offset_; }
46 uint64 length() const { return length_; } 48 uint64_t length() const { return length_; }
47 const base::Time& expected_modification_time() const { 49 const base::Time& expected_modification_time() const {
48 return expected_modification_time_; 50 return expected_modification_time_;
49 } 51 }
50 52
51 // For use with SetToAllocatedBytes. Should only be used after calling 53 // For use with SetToAllocatedBytes. Should only be used after calling
52 // SetToAllocatedBytes. 54 // SetToAllocatedBytes.
53 char* mutable_bytes() { return &buf_[0]; } 55 char* mutable_bytes() { return &buf_[0]; }
54 56
55 // Sets TYPE_BYTES data. This copies the given data into the element. 57 // Sets TYPE_BYTES data. This copies the given data into the element.
56 void SetToBytes(const char* bytes, int bytes_len) { 58 void SetToBytes(const char* bytes, int bytes_len) {
57 type_ = TYPE_BYTES; 59 type_ = TYPE_BYTES;
58 bytes_ = nullptr; 60 bytes_ = nullptr;
59 buf_.assign(bytes, bytes + bytes_len); 61 buf_.assign(bytes, bytes + bytes_len);
60 length_ = buf_.size(); 62 length_ = buf_.size();
61 } 63 }
62 64
63 // Sets TYPE_BYTES data, and clears the internal bytes buffer. 65 // Sets TYPE_BYTES data, and clears the internal bytes buffer.
64 // For use with AppendBytes. 66 // For use with AppendBytes.
65 void SetToEmptyBytes() { 67 void SetToEmptyBytes() {
66 type_ = TYPE_BYTES; 68 type_ = TYPE_BYTES;
67 buf_.clear(); 69 buf_.clear();
68 length_ = 0; 70 length_ = 0;
69 bytes_ = nullptr; 71 bytes_ = nullptr;
70 } 72 }
71 73
72 // Copies and appends the given data into the element. SetToEmptyBytes or 74 // Copies and appends the given data into the element. SetToEmptyBytes or
73 // SetToBytes must be called before this method. 75 // SetToBytes must be called before this method.
74 void AppendBytes(const char* bytes, int bytes_len) { 76 void AppendBytes(const char* bytes, int bytes_len) {
75 DCHECK_EQ(type_, TYPE_BYTES); 77 DCHECK_EQ(type_, TYPE_BYTES);
76 DCHECK_NE(length_, kuint64max); 78 DCHECK_NE(length_, std::numeric_limits<uint64_t>::max());
77 DCHECK(!bytes_); 79 DCHECK(!bytes_);
78 buf_.insert(buf_.end(), bytes, bytes + bytes_len); 80 buf_.insert(buf_.end(), bytes, bytes + bytes_len);
79 length_ = buf_.size(); 81 length_ = buf_.size();
80 } 82 }
81 83
82 void SetToBytesDescription(size_t bytes_len) { 84 void SetToBytesDescription(size_t bytes_len) {
83 type_ = TYPE_BYTES_DESCRIPTION; 85 type_ = TYPE_BYTES_DESCRIPTION;
84 bytes_ = nullptr; 86 bytes_ = nullptr;
85 length_ = bytes_len; 87 length_ = bytes_len;
86 } 88 }
(...skipping 12 matching lines...) Expand all
99 // then use the bytes() method to access this buffer and populate it. 101 // then use the bytes() method to access this buffer and populate it.
100 void SetToAllocatedBytes(size_t bytes_len) { 102 void SetToAllocatedBytes(size_t bytes_len) {
101 type_ = TYPE_BYTES; 103 type_ = TYPE_BYTES;
102 bytes_ = nullptr; 104 bytes_ = nullptr;
103 buf_.resize(bytes_len); 105 buf_.resize(bytes_len);
104 length_ = bytes_len; 106 length_ = bytes_len;
105 } 107 }
106 108
107 // Sets TYPE_FILE data. 109 // Sets TYPE_FILE data.
108 void SetToFilePath(const base::FilePath& path) { 110 void SetToFilePath(const base::FilePath& path) {
109 SetToFilePathRange(path, 0, kuint64max, base::Time()); 111 SetToFilePathRange(path, 0, std::numeric_limits<uint64_t>::max(),
112 base::Time());
110 } 113 }
111 114
112 // Sets TYPE_BLOB data. 115 // Sets TYPE_BLOB data.
113 void SetToBlob(const std::string& uuid) { 116 void SetToBlob(const std::string& uuid) {
114 SetToBlobRange(uuid, 0, kuint64max); 117 SetToBlobRange(uuid, 0, std::numeric_limits<uint64_t>::max());
115 } 118 }
116 119
117 // Sets TYPE_FILE data with range. 120 // Sets TYPE_FILE data with range.
118 void SetToFilePathRange(const base::FilePath& path, 121 void SetToFilePathRange(const base::FilePath& path,
119 uint64 offset, uint64 length, 122 uint64_t offset,
123 uint64_t length,
120 const base::Time& expected_modification_time); 124 const base::Time& expected_modification_time);
121 125
122 // Sets TYPE_BLOB data with range. 126 // Sets TYPE_BLOB data with range.
123 void SetToBlobRange(const std::string& blob_uuid, 127 void SetToBlobRange(const std::string& blob_uuid,
124 uint64 offset, uint64 length); 128 uint64_t offset,
129 uint64_t length);
125 130
126 // Sets TYPE_FILE_FILESYSTEM with range. 131 // Sets TYPE_FILE_FILESYSTEM with range.
127 void SetToFileSystemUrlRange(const GURL& filesystem_url, 132 void SetToFileSystemUrlRange(const GURL& filesystem_url,
128 uint64 offset, uint64 length, 133 uint64_t offset,
134 uint64_t length,
129 const base::Time& expected_modification_time); 135 const base::Time& expected_modification_time);
130 136
131 // Sets to TYPE_DISK_CACHE_ENTRY with range. 137 // Sets to TYPE_DISK_CACHE_ENTRY with range.
132 void SetToDiskCacheEntryRange(uint64 offset, uint64 length); 138 void SetToDiskCacheEntryRange(uint64_t offset, uint64_t length);
133 139
134 private: 140 private:
135 FRIEND_TEST_ALL_PREFIXES(BlobAsyncTransportStrategyTest, TestInvalidParams); 141 FRIEND_TEST_ALL_PREFIXES(BlobAsyncTransportStrategyTest, TestInvalidParams);
136 friend STORAGE_COMMON_EXPORT void PrintTo(const DataElement& x, 142 friend STORAGE_COMMON_EXPORT void PrintTo(const DataElement& x,
137 ::std::ostream* os); 143 ::std::ostream* os);
138 Type type_; 144 Type type_;
139 std::vector<char> buf_; // For TYPE_BYTES. 145 std::vector<char> buf_; // For TYPE_BYTES.
140 const char* bytes_; // For TYPE_BYTES. 146 const char* bytes_; // For TYPE_BYTES.
141 base::FilePath path_; // For TYPE_FILE. 147 base::FilePath path_; // For TYPE_FILE.
142 GURL filesystem_url_; // For TYPE_FILE_FILESYSTEM. 148 GURL filesystem_url_; // For TYPE_FILE_FILESYSTEM.
143 std::string blob_uuid_; 149 std::string blob_uuid_;
144 uint64 offset_; 150 uint64_t offset_;
145 uint64 length_; 151 uint64_t length_;
146 base::Time expected_modification_time_; 152 base::Time expected_modification_time_;
147 }; 153 };
148 154
149 STORAGE_COMMON_EXPORT bool operator==(const DataElement& a, 155 STORAGE_COMMON_EXPORT bool operator==(const DataElement& a,
150 const DataElement& b); 156 const DataElement& b);
151 STORAGE_COMMON_EXPORT bool operator!=(const DataElement& a, 157 STORAGE_COMMON_EXPORT bool operator!=(const DataElement& a,
152 const DataElement& b); 158 const DataElement& b);
153 159
154 } // namespace storage 160 } // namespace storage
155 161
156 #endif // STORAGE_COMMON_DATA_ELEMENT_H_ 162 #endif // STORAGE_COMMON_DATA_ELEMENT_H_
OLDNEW
« no previous file with comments | « storage/common/blob_storage/blob_item_bytes_request.h ('k') | storage/common/data_element.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698