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

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

Issue 442383002: Move storage-related files from webkit/ to new top-level directory storage/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « storage/common/blob/shareable_file_reference.cc ('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 WEBKIT_COMMON_DATA_ELEMENT_H_ 5 #ifndef WEBKIT_COMMON_DATA_ELEMENT_H_
6 #define WEBKIT_COMMON_DATA_ELEMENT_H_ 6 #define WEBKIT_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 "url/gurl.h" 15 #include "url/gurl.h"
16 #include "webkit/common/webkit_common_export.h" 16 #include "storage/common/storage_export.h"
17 17
18 namespace webkit_common { 18 namespace webkit_common {
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 WEBKIT_COMMON_EXPORT DataElement { 22 class STORAGE_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 }; 30 };
31 31
32 DataElement(); 32 DataElement();
(...skipping 30 matching lines...) Expand all
63 SetToFilePathRange(path, 0, kuint64max, base::Time()); 63 SetToFilePathRange(path, 0, kuint64max, base::Time());
64 } 64 }
65 65
66 // Sets TYPE_BLOB data. 66 // Sets TYPE_BLOB data.
67 void SetToBlob(const std::string& uuid) { 67 void SetToBlob(const std::string& uuid) {
68 SetToBlobRange(uuid, 0, kuint64max); 68 SetToBlobRange(uuid, 0, kuint64max);
69 } 69 }
70 70
71 // Sets TYPE_FILE data with range. 71 // Sets TYPE_FILE data with range.
72 void SetToFilePathRange(const base::FilePath& path, 72 void SetToFilePathRange(const base::FilePath& path,
73 uint64 offset, uint64 length, 73 uint64 offset,
74 uint64 length,
74 const base::Time& expected_modification_time); 75 const base::Time& expected_modification_time);
75 76
76 // Sets TYPE_BLOB data with range. 77 // Sets TYPE_BLOB data with range.
77 void SetToBlobRange(const std::string& blob_uuid, 78 void SetToBlobRange(const std::string& blob_uuid,
78 uint64 offset, uint64 length); 79 uint64 offset,
80 uint64 length);
79 81
80 // Sets TYPE_FILE_FILESYSTEM with range. 82 // Sets TYPE_FILE_FILESYSTEM with range.
81 void SetToFileSystemUrlRange(const GURL& filesystem_url, 83 void SetToFileSystemUrlRange(const GURL& filesystem_url,
82 uint64 offset, uint64 length, 84 uint64 offset,
85 uint64 length,
83 const base::Time& expected_modification_time); 86 const base::Time& expected_modification_time);
84 87
85 private: 88 private:
86 Type type_; 89 Type type_;
87 std::vector<char> buf_; // For TYPE_BYTES. 90 std::vector<char> buf_; // For TYPE_BYTES.
88 const char* bytes_; // For TYPE_BYTES. 91 const char* bytes_; // For TYPE_BYTES.
89 base::FilePath path_; // For TYPE_FILE. 92 base::FilePath path_; // For TYPE_FILE.
90 GURL filesystem_url_; // For TYPE_FILE_FILESYSTEM. 93 GURL filesystem_url_; // For TYPE_FILE_FILESYSTEM.
91 std::string blob_uuid_; 94 std::string blob_uuid_;
92 uint64 offset_; 95 uint64 offset_;
93 uint64 length_; 96 uint64 length_;
94 base::Time expected_modification_time_; 97 base::Time expected_modification_time_;
95 }; 98 };
96 99
97 #if defined(UNIT_TEST) 100 #if defined(UNIT_TEST)
98 inline bool operator==(const DataElement& a, const DataElement& b) { 101 inline bool operator==(const DataElement& a, const DataElement& b) {
99 if (a.type() != b.type() || 102 if (a.type() != b.type() || a.offset() != b.offset() ||
100 a.offset() != b.offset() ||
101 a.length() != b.length()) 103 a.length() != b.length())
102 return false; 104 return false;
103 switch (a.type()) { 105 switch (a.type()) {
104 case DataElement::TYPE_BYTES: 106 case DataElement::TYPE_BYTES:
105 return memcmp(a.bytes(), b.bytes(), b.length()) == 0; 107 return memcmp(a.bytes(), b.bytes(), b.length()) == 0;
106 case DataElement::TYPE_FILE: 108 case DataElement::TYPE_FILE:
107 return a.path() == b.path() && 109 return a.path() == b.path() &&
108 a.expected_modification_time() == b.expected_modification_time(); 110 a.expected_modification_time() == b.expected_modification_time();
109 case DataElement::TYPE_BLOB: 111 case DataElement::TYPE_BLOB:
110 return a.blob_uuid() == b.blob_uuid(); 112 return a.blob_uuid() == b.blob_uuid();
111 case DataElement::TYPE_FILE_FILESYSTEM: 113 case DataElement::TYPE_FILE_FILESYSTEM:
112 return a.filesystem_url() == b.filesystem_url(); 114 return a.filesystem_url() == b.filesystem_url();
113 case DataElement::TYPE_UNKNOWN: 115 case DataElement::TYPE_UNKNOWN:
114 NOTREACHED(); 116 NOTREACHED();
115 return false; 117 return false;
116 } 118 }
117 return false; 119 return false;
118 } 120 }
119 121
120 inline bool operator!=(const DataElement& a, const DataElement& b) { 122 inline bool operator!=(const DataElement& a, const DataElement& b) {
121 return !(a == b); 123 return !(a == b);
122 } 124 }
123 #endif // defined(UNIT_TEST) 125 #endif // defined(UNIT_TEST)
124 126
125 } // namespace webkit_common 127 } // namespace webkit_common
126 128
127 #endif // WEBKIT_COMMON_DATA_ELEMENT_H_ 129 #endif // WEBKIT_COMMON_DATA_ELEMENT_H_
OLDNEW
« no previous file with comments | « storage/common/blob/shareable_file_reference.cc ('k') | storage/common/data_element.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698