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

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: Created 5 years, 7 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 "net/disk_cache/disk_cache.h"
15 #include "storage/common/storage_common_export.h" 16 #include "storage/common/storage_common_export.h"
16 #include "url/gurl.h" 17 #include "url/gurl.h"
17 18
18 namespace storage { 19 namespace storage {
19 20
20 // Represents a base Web data element. This could be either one of 21 // Represents a base Web data element. This could be either one of
21 // bytes, file or blob data. 22 // bytes, file or blob data.
22 class STORAGE_COMMON_EXPORT DataElement { 23 class STORAGE_COMMON_EXPORT DataElement {
23 public: 24 public:
24 enum Type { 25 enum Type {
25 TYPE_UNKNOWN = -1, 26 TYPE_UNKNOWN = -1,
26 TYPE_BYTES, 27 TYPE_BYTES,
27 TYPE_FILE, 28 TYPE_FILE,
28 TYPE_BLOB, 29 TYPE_BLOB,
29 TYPE_FILE_FILESYSTEM, 30 TYPE_FILE_FILESYSTEM,
31 TYPE_DISK_CACHE_ENTRY,
30 }; 32 };
31 33
32 DataElement(); 34 DataElement();
33 ~DataElement(); 35 ~DataElement();
34 36
35 Type type() const { return type_; } 37 Type type() const { return type_; }
36 const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; } 38 const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; }
37 const base::FilePath& path() const { return path_; } 39 const base::FilePath& path() const { return path_; }
38 const GURL& filesystem_url() const { return filesystem_url_; } 40 const GURL& filesystem_url() const { return filesystem_url_; }
39 const std::string& blob_uuid() const { return blob_uuid_; } 41 const std::string& blob_uuid() const { return blob_uuid_; }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 97
96 // Sets TYPE_BLOB data with range. 98 // Sets TYPE_BLOB data with range.
97 void SetToBlobRange(const std::string& blob_uuid, 99 void SetToBlobRange(const std::string& blob_uuid,
98 uint64 offset, uint64 length); 100 uint64 offset, uint64 length);
99 101
100 // Sets TYPE_FILE_FILESYSTEM with range. 102 // Sets TYPE_FILE_FILESYSTEM with range.
101 void SetToFileSystemUrlRange(const GURL& filesystem_url, 103 void SetToFileSystemUrlRange(const GURL& filesystem_url,
102 uint64 offset, uint64 length, 104 uint64 offset, uint64 length,
103 const base::Time& expected_modification_time); 105 const base::Time& expected_modification_time);
104 106
107 // Sets TYPE_DISK_CACHE_ENTRY data.
108 void SetToDiskCacheEntry();
109
105 private: 110 private:
106 Type type_; 111 Type type_;
107 std::vector<char> buf_; // For TYPE_BYTES. 112 std::vector<char> buf_; // For TYPE_BYTES.
108 const char* bytes_; // For TYPE_BYTES. 113 const char* bytes_; // For TYPE_BYTES.
109 base::FilePath path_; // For TYPE_FILE. 114 base::FilePath path_; // For TYPE_FILE.
110 GURL filesystem_url_; // For TYPE_FILE_FILESYSTEM. 115 GURL filesystem_url_; // For TYPE_FILE_FILESYSTEM.
111 std::string blob_uuid_; 116 std::string blob_uuid_; // For TYPE_BLOB and TYPE_DISK_CACHE_ENTRY.
michaeln 2015/06/12 22:35:10 where/how is this used for TYPE_DISK_CACHE_ENTRY?
112 uint64 offset_; 117 uint64 offset_;
113 uint64 length_; 118 uint64 length_;
114 base::Time expected_modification_time_; 119 base::Time expected_modification_time_;
115 }; 120 };
116 121
117 #if defined(UNIT_TEST) 122 #if defined(UNIT_TEST)
118 inline bool operator==(const DataElement& a, const DataElement& b) { 123 inline bool operator==(const DataElement& a, const DataElement& b) {
119 if (a.type() != b.type() || 124 if (a.type() != b.type() ||
120 a.offset() != b.offset() || 125 a.offset() != b.offset() ||
121 a.length() != b.length()) 126 a.length() != b.length())
122 return false; 127 return false;
123 switch (a.type()) { 128 switch (a.type()) {
124 case DataElement::TYPE_BYTES: 129 case DataElement::TYPE_BYTES:
125 return memcmp(a.bytes(), b.bytes(), b.length()) == 0; 130 return memcmp(a.bytes(), b.bytes(), b.length()) == 0;
126 case DataElement::TYPE_FILE: 131 case DataElement::TYPE_FILE:
127 return a.path() == b.path() && 132 return a.path() == b.path() &&
128 a.expected_modification_time() == b.expected_modification_time(); 133 a.expected_modification_time() == b.expected_modification_time();
129 case DataElement::TYPE_BLOB: 134 case DataElement::TYPE_BLOB:
130 return a.blob_uuid() == b.blob_uuid(); 135 return a.blob_uuid() == b.blob_uuid();
131 case DataElement::TYPE_FILE_FILESYSTEM: 136 case DataElement::TYPE_FILE_FILESYSTEM:
132 return a.filesystem_url() == b.filesystem_url(); 137 return a.filesystem_url() == b.filesystem_url();
138 case DataElement::TYPE_DISK_CACHE_ENTRY:
139 return true; // XYZZY really?
133 case DataElement::TYPE_UNKNOWN: 140 case DataElement::TYPE_UNKNOWN:
134 NOTREACHED(); 141 NOTREACHED();
135 return false; 142 return false;
136 } 143 }
137 return false; 144 return false;
138 } 145 }
139 146
140 inline bool operator!=(const DataElement& a, const DataElement& b) { 147 inline bool operator!=(const DataElement& a, const DataElement& b) {
141 return !(a == b); 148 return !(a == b);
142 } 149 }
143 #endif // defined(UNIT_TEST) 150 #endif // defined(UNIT_TEST)
144 151
145 } // namespace storage 152 } // namespace storage
146 153
147 #endif // STORAGE_COMMON_DATA_ELEMENT_H_ 154 #endif // STORAGE_COMMON_DATA_ELEMENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698