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

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

Issue 1108083002: Create blobs from Disk Cache entries. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: remediate + windows build Created 5 years, 6 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
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
11 #include "base/basictypes.h" 11 #include "base/basictypes.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/time/time.h" 14 #include "base/time/time.h"
15 #include "storage/common/storage_common_export.h" 15 #include "storage/common/storage_common_export.h"
16 #include "url/gurl.h" 16 #include "url/gurl.h"
17 17
18 namespace storage { 18 namespace storage {
19 19
20 // Represents a base Web data element. This could be either one of 20 // Represents a base Web data element. This could be either one of
21 // bytes, file or blob data. 21 // bytes, file or blob data.
22 class STORAGE_COMMON_EXPORT DataElement { 22 class STORAGE_COMMON_EXPORT DataElement {
23 public: 23 public:
24 enum Type { 24 enum Type {
25 TYPE_UNKNOWN = -1, 25 TYPE_UNKNOWN = -1,
26 TYPE_BYTES, 26 TYPE_BYTES,
27 TYPE_FILE, 27 TYPE_FILE,
28 TYPE_BLOB, 28 TYPE_BLOB,
29 TYPE_FILE_FILESYSTEM, 29 TYPE_FILE_FILESYSTEM,
30 TYPE_DISK_CACHE_ENTRY,
30 }; 31 };
31 32
32 DataElement(); 33 DataElement();
33 ~DataElement(); 34 ~DataElement();
34 35
35 Type type() const { return type_; } 36 Type type() const { return type_; }
36 const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; } 37 const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; }
37 const base::FilePath& path() const { return path_; } 38 const base::FilePath& path() const { return path_; }
38 const GURL& filesystem_url() const { return filesystem_url_; } 39 const GURL& filesystem_url() const { return filesystem_url_; }
39 const std::string& blob_uuid() const { return blob_uuid_; } 40 const std::string& blob_uuid() const { return blob_uuid_; }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 96
96 // Sets TYPE_BLOB data with range. 97 // Sets TYPE_BLOB data with range.
97 void SetToBlobRange(const std::string& blob_uuid, 98 void SetToBlobRange(const std::string& blob_uuid,
98 uint64 offset, uint64 length); 99 uint64 offset, uint64 length);
99 100
100 // Sets TYPE_FILE_FILESYSTEM with range. 101 // Sets TYPE_FILE_FILESYSTEM with range.
101 void SetToFileSystemUrlRange(const GURL& filesystem_url, 102 void SetToFileSystemUrlRange(const GURL& filesystem_url,
102 uint64 offset, uint64 length, 103 uint64 offset, uint64 length,
103 const base::Time& expected_modification_time); 104 const base::Time& expected_modification_time);
104 105
106 // Sets to TYPE_DISK_CACHE_ENTRY with range.
107 void SetToDiskCacheEntryRange(uint64 offset, uint64 length);
108
105 private: 109 private:
106 Type type_; 110 Type type_;
107 std::vector<char> buf_; // For TYPE_BYTES. 111 std::vector<char> buf_; // For TYPE_BYTES.
108 const char* bytes_; // For TYPE_BYTES. 112 const char* bytes_; // For TYPE_BYTES.
109 base::FilePath path_; // For TYPE_FILE. 113 base::FilePath path_; // For TYPE_FILE.
110 GURL filesystem_url_; // For TYPE_FILE_FILESYSTEM. 114 GURL filesystem_url_; // For TYPE_FILE_FILESYSTEM.
111 std::string blob_uuid_; 115 std::string blob_uuid_;
112 uint64 offset_; 116 uint64 offset_;
113 uint64 length_; 117 uint64 length_;
114 base::Time expected_modification_time_; 118 base::Time expected_modification_time_;
115 }; 119 };
116 120
117 #if defined(UNIT_TEST) 121 #if defined(UNIT_TEST)
118 inline bool operator==(const DataElement& a, const DataElement& b) { 122 inline bool operator==(const DataElement& a, const DataElement& b) {
119 if (a.type() != b.type() || 123 if (a.type() != b.type() ||
120 a.offset() != b.offset() || 124 a.offset() != b.offset() ||
121 a.length() != b.length()) 125 a.length() != b.length())
122 return false; 126 return false;
123 switch (a.type()) { 127 switch (a.type()) {
124 case DataElement::TYPE_BYTES: 128 case DataElement::TYPE_BYTES:
125 return memcmp(a.bytes(), b.bytes(), b.length()) == 0; 129 return memcmp(a.bytes(), b.bytes(), b.length()) == 0;
126 case DataElement::TYPE_FILE: 130 case DataElement::TYPE_FILE:
127 return a.path() == b.path() && 131 return a.path() == b.path() &&
128 a.expected_modification_time() == b.expected_modification_time(); 132 a.expected_modification_time() == b.expected_modification_time();
129 case DataElement::TYPE_BLOB: 133 case DataElement::TYPE_BLOB:
130 return a.blob_uuid() == b.blob_uuid(); 134 return a.blob_uuid() == b.blob_uuid();
131 case DataElement::TYPE_FILE_FILESYSTEM: 135 case DataElement::TYPE_FILE_FILESYSTEM:
132 return a.filesystem_url() == b.filesystem_url(); 136 return a.filesystem_url() == b.filesystem_url();
137 case DataElement::TYPE_DISK_CACHE_ENTRY:
138 // We compare only length and offset; we trust the entry itself was
139 // compared at some higher level such as in BlobDataItem.
140 return true;
133 case DataElement::TYPE_UNKNOWN: 141 case DataElement::TYPE_UNKNOWN:
134 NOTREACHED(); 142 NOTREACHED();
135 return false; 143 return false;
136 } 144 }
137 return false; 145 return false;
138 } 146 }
139 147
140 inline bool operator!=(const DataElement& a, const DataElement& b) { 148 inline bool operator!=(const DataElement& a, const DataElement& b) {
141 return !(a == b); 149 return !(a == b);
142 } 150 }
143 #endif // defined(UNIT_TEST) 151 #endif // defined(UNIT_TEST)
144 152
145 } // namespace storage 153 } // namespace storage
146 154
147 #endif // STORAGE_COMMON_DATA_ELEMENT_H_ 155 #endif // STORAGE_COMMON_DATA_ELEMENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698