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 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 "webkit/common/webkit_common_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 WEBKIT_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 #if defined(OS_ANDROID) |
| 31 TYPE_CONTENT_URL, |
| 32 #endif |
30 }; | 33 }; |
31 | 34 |
32 DataElement(); | 35 DataElement(); |
33 ~DataElement(); | 36 ~DataElement(); |
34 | 37 |
35 Type type() const { return type_; } | 38 Type type() const { return type_; } |
36 const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; } | 39 const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; } |
37 const base::FilePath& path() const { return path_; } | 40 const base::FilePath& path() const { return path_; } |
38 const GURL& filesystem_url() const { return filesystem_url_; } | 41 const GURL& filesystem_url() const { return filesystem_url_; } |
| 42 #if defined(OS_ANDROID) |
| 43 const GURL& content_url() const { return content_url_; } |
| 44 #endif |
39 const std::string& blob_uuid() const { return blob_uuid_; } | 45 const std::string& blob_uuid() const { return blob_uuid_; } |
40 uint64 offset() const { return offset_; } | 46 uint64 offset() const { return offset_; } |
41 uint64 length() const { return length_; } | 47 uint64 length() const { return length_; } |
42 const base::Time& expected_modification_time() const { | 48 const base::Time& expected_modification_time() const { |
43 return expected_modification_time_; | 49 return expected_modification_time_; |
44 } | 50 } |
45 | 51 |
46 // Sets TYPE_BYTES data. This copies the given data into the element. | 52 // Sets TYPE_BYTES data. This copies the given data into the element. |
47 void SetToBytes(const char* bytes, int bytes_len) { | 53 void SetToBytes(const char* bytes, int bytes_len) { |
48 type_ = TYPE_BYTES; | 54 type_ = TYPE_BYTES; |
(...skipping 26 matching lines...) Expand all Loading... |
75 | 81 |
76 // Sets TYPE_BLOB data with range. | 82 // Sets TYPE_BLOB data with range. |
77 void SetToBlobRange(const std::string& blob_uuid, | 83 void SetToBlobRange(const std::string& blob_uuid, |
78 uint64 offset, uint64 length); | 84 uint64 offset, uint64 length); |
79 | 85 |
80 // Sets TYPE_FILE_FILESYSTEM with range. | 86 // Sets TYPE_FILE_FILESYSTEM with range. |
81 void SetToFileSystemUrlRange(const GURL& filesystem_url, | 87 void SetToFileSystemUrlRange(const GURL& filesystem_url, |
82 uint64 offset, uint64 length, | 88 uint64 offset, uint64 length, |
83 const base::Time& expected_modification_time); | 89 const base::Time& expected_modification_time); |
84 | 90 |
| 91 #if defined(OS_ANDROID) |
| 92 // Sets TYPE_CONTENT_URL with range. |
| 93 void SetToContentUrlRange(const GURL& content_url, |
| 94 uint64 offset, uint64 length, |
| 95 const base::Time& expected_modification_time); |
| 96 #endif |
| 97 |
85 private: | 98 private: |
86 Type type_; | 99 Type type_; |
87 std::vector<char> buf_; // For TYPE_BYTES. | 100 std::vector<char> buf_; // For TYPE_BYTES. |
88 const char* bytes_; // For TYPE_BYTES. | 101 const char* bytes_; // For TYPE_BYTES. |
89 base::FilePath path_; // For TYPE_FILE. | 102 base::FilePath path_; // For TYPE_FILE. |
90 GURL filesystem_url_; // For TYPE_FILE_FILESYSTEM. | 103 GURL filesystem_url_; // For TYPE_FILE_FILESYSTEM. |
| 104 #if defined(OS_ANDROID) |
| 105 GURL content_url_; // For TYPE_CONTENT_URL. |
| 106 #endif |
91 std::string blob_uuid_; | 107 std::string blob_uuid_; |
92 uint64 offset_; | 108 uint64 offset_; |
93 uint64 length_; | 109 uint64 length_; |
94 base::Time expected_modification_time_; | 110 base::Time expected_modification_time_; |
95 }; | 111 }; |
96 | 112 |
97 #if defined(UNIT_TEST) | 113 #if defined(UNIT_TEST) |
98 inline bool operator==(const DataElement& a, const DataElement& b) { | 114 inline bool operator==(const DataElement& a, const DataElement& b) { |
99 if (a.type() != b.type() || | 115 if (a.type() != b.type() || |
100 a.offset() != b.offset() || | 116 a.offset() != b.offset() || |
101 a.length() != b.length()) | 117 a.length() != b.length()) |
102 return false; | 118 return false; |
103 switch (a.type()) { | 119 switch (a.type()) { |
104 case DataElement::TYPE_BYTES: | 120 case DataElement::TYPE_BYTES: |
105 return memcmp(a.bytes(), b.bytes(), b.length()) == 0; | 121 return memcmp(a.bytes(), b.bytes(), b.length()) == 0; |
106 case DataElement::TYPE_FILE: | 122 case DataElement::TYPE_FILE: |
107 return a.path() == b.path() && | 123 return a.path() == b.path() && |
108 a.expected_modification_time() == b.expected_modification_time(); | 124 a.expected_modification_time() == b.expected_modification_time(); |
109 case DataElement::TYPE_BLOB: | 125 case DataElement::TYPE_BLOB: |
110 return a.blob_uuid() == b.blob_uuid(); | 126 return a.blob_uuid() == b.blob_uuid(); |
111 case DataElement::TYPE_FILE_FILESYSTEM: | 127 case DataElement::TYPE_FILE_FILESYSTEM: |
112 return a.filesystem_url() == b.filesystem_url(); | 128 return a.filesystem_url() == b.filesystem_url(); |
| 129 #if defined(OS_ANDROID) |
| 130 case DataElement::TYPE_CONTENT_URL: |
| 131 return a.content_url() == b.content_url(); |
| 132 #endif |
113 case DataElement::TYPE_UNKNOWN: | 133 case DataElement::TYPE_UNKNOWN: |
114 NOTREACHED(); | 134 NOTREACHED(); |
115 return false; | 135 return false; |
116 } | 136 } |
117 return false; | 137 return false; |
118 } | 138 } |
119 | 139 |
120 inline bool operator!=(const DataElement& a, const DataElement& b) { | 140 inline bool operator!=(const DataElement& a, const DataElement& b) { |
121 return !(a == b); | 141 return !(a == b); |
122 } | 142 } |
123 #endif // defined(UNIT_TEST) | 143 #endif // defined(UNIT_TEST) |
124 | 144 |
125 } // namespace webkit_common | 145 } // namespace webkit_common |
126 | 146 |
127 #endif // WEBKIT_COMMON_DATA_ELEMENT_H_ | 147 #endif // WEBKIT_COMMON_DATA_ELEMENT_H_ |
OLD | NEW |