OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_BLOB_BLOB_DATA_H_ | 5 #ifndef WEBKIT_BLOB_BLOB_DATA_H_ |
6 #define WEBKIT_BLOB_BLOB_DATA_H_ | 6 #define WEBKIT_BLOB_BLOB_DATA_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "googleurl/src/gurl.h" | 14 #include "googleurl/src/gurl.h" |
15 #include "webkit/blob/blob_export.h" | 15 #include "webkit/blob/blob_export.h" |
16 #include "webkit/blob/shareable_file_reference.h" | 16 #include "webkit/blob/shareable_file_reference.h" |
17 | 17 |
18 namespace WebKit { | 18 namespace WebKit { |
19 class WebBlobData; | 19 class WebBlobData; |
20 } | 20 } |
21 | 21 |
22 namespace webkit_blob { | 22 namespace webkit_blob { |
23 | 23 |
24 class BLOB_EXPORT BlobData : public base::RefCounted<BlobData> { | 24 class BLOB_EXPORT BlobData : public base::RefCounted<BlobData> { |
25 public: | 25 public: |
26 enum Type { | 26 enum Type { |
27 TYPE_DATA, | 27 TYPE_DATA, |
28 TYPE_DATA_EXTERNAL, | 28 TYPE_DATA_EXTERNAL, |
29 TYPE_FILE, | 29 TYPE_FILE, |
30 TYPE_BLOB | 30 TYPE_BLOB, |
| 31 TYPE_FILE_FILESYSTEM, |
31 }; | 32 }; |
32 | 33 |
33 struct BLOB_EXPORT Item { | 34 struct BLOB_EXPORT Item { |
34 Item(); | 35 Item(); |
35 ~Item(); | 36 ~Item(); |
36 | 37 |
37 void SetToData(const std::string& data) { | 38 void SetToData(const std::string& data) { |
38 SetToData(data.c_str(), data.size()); | 39 SetToData(data.c_str(), data.size()); |
39 } | 40 } |
40 | 41 |
(...skipping 15 matching lines...) Expand all Loading... |
56 const base::Time& expected_modification_time) { | 57 const base::Time& expected_modification_time) { |
57 type = TYPE_FILE; | 58 type = TYPE_FILE; |
58 this->file_path = file_path; | 59 this->file_path = file_path; |
59 this->offset = offset; | 60 this->offset = offset; |
60 this->length = length; | 61 this->length = length; |
61 this->expected_modification_time = expected_modification_time; | 62 this->expected_modification_time = expected_modification_time; |
62 } | 63 } |
63 | 64 |
64 void SetToBlob(const GURL& blob_url, uint64 offset, uint64 length) { | 65 void SetToBlob(const GURL& blob_url, uint64 offset, uint64 length) { |
65 type = TYPE_BLOB; | 66 type = TYPE_BLOB; |
66 this->blob_url = blob_url; | 67 this->url = blob_url; |
67 this->offset = offset; | 68 this->offset = offset; |
68 this->length = length; | 69 this->length = length; |
69 } | 70 } |
70 | 71 |
| 72 void SetToFileSystemFile( |
| 73 const GURL& url, uint64 offset, uint64 length, |
| 74 const base::Time& expected_modification_time) { |
| 75 type = TYPE_FILE_FILESYSTEM; |
| 76 this->url = url; |
| 77 this->offset = offset; |
| 78 this->length = length; |
| 79 this->expected_modification_time = expected_modification_time; |
| 80 } |
| 81 |
71 Type type; | 82 Type type; |
72 std::string data; // For Data type. | 83 std::string data; // For Data type. |
73 const char* data_external; // For DataExternal type. | 84 const char* data_external; // For DataExternal type. |
74 GURL blob_url; // For Blob type. | 85 GURL url; // For Blob or FileSystem File type. |
75 FilePath file_path; // For File type. | 86 FilePath file_path; // For File type. |
76 base::Time expected_modification_time; // Also for File type. | 87 base::Time expected_modification_time; // Also for File type. |
77 uint64 offset; | 88 uint64 offset; |
78 uint64 length; | 89 uint64 length; |
79 }; | 90 }; |
80 | 91 |
81 BlobData(); | 92 BlobData(); |
82 explicit BlobData(const WebKit::WebBlobData& data); | 93 explicit BlobData(const WebKit::WebBlobData& data); |
83 | 94 |
84 void AppendData(const std::string& data) { | 95 void AppendData(const std::string& data) { |
85 AppendData(data.c_str(), data.size()); | 96 AppendData(data.c_str(), data.size()); |
86 } | 97 } |
87 | 98 |
88 void AppendData(const char* data, size_t length); | 99 void AppendData(const char* data, size_t length); |
89 | 100 |
90 void AppendFile(const FilePath& file_path, uint64 offset, uint64 length, | 101 void AppendFile(const FilePath& file_path, uint64 offset, uint64 length, |
91 const base::Time& expected_modification_time); | 102 const base::Time& expected_modification_time); |
92 | 103 |
| 104 void AppendFileSystemFile(const GURL& url, uint64 offset, uint64 length, |
| 105 const base::Time& expected_modification_time); |
| 106 |
93 void AppendBlob(const GURL& blob_url, uint64 offset, uint64 length); | 107 void AppendBlob(const GURL& blob_url, uint64 offset, uint64 length); |
94 | 108 |
95 void AttachShareableFileReference(ShareableFileReference* reference) { | 109 void AttachShareableFileReference(ShareableFileReference* reference) { |
96 shareable_files_.push_back(reference); | 110 shareable_files_.push_back(reference); |
97 } | 111 } |
98 | 112 |
99 const std::vector<Item>& items() const { return items_; } | 113 const std::vector<Item>& items() const { return items_; } |
100 | 114 |
101 const std::string& content_type() const { return content_type_; } | 115 const std::string& content_type() const { return content_type_; } |
102 void set_content_type(const std::string& content_type) { | 116 void set_content_type(const std::string& content_type) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 a.offset == b.offset && | 148 a.offset == b.offset && |
135 a.length == b.length; | 149 a.length == b.length; |
136 } | 150 } |
137 if (a.type == BlobData::TYPE_FILE) { | 151 if (a.type == BlobData::TYPE_FILE) { |
138 return a.file_path == b.file_path && | 152 return a.file_path == b.file_path && |
139 a.offset == b.offset && | 153 a.offset == b.offset && |
140 a.length == b.length && | 154 a.length == b.length && |
141 a.expected_modification_time == b.expected_modification_time; | 155 a.expected_modification_time == b.expected_modification_time; |
142 } | 156 } |
143 if (a.type == BlobData::TYPE_BLOB) { | 157 if (a.type == BlobData::TYPE_BLOB) { |
144 return a.blob_url == b.blob_url && | 158 return a.url == b.url && |
145 a.offset == b.offset && | 159 a.offset == b.offset && |
146 a.length == b.length; | 160 a.length == b.length; |
147 } | 161 } |
148 return false; | 162 return false; |
149 } | 163 } |
150 | 164 |
151 inline bool operator!=(const BlobData::Item& a, const BlobData::Item& b) { | 165 inline bool operator!=(const BlobData::Item& a, const BlobData::Item& b) { |
152 return !(a == b); | 166 return !(a == b); |
153 } | 167 } |
154 | 168 |
(...skipping 12 matching lines...) Expand all Loading... |
167 } | 181 } |
168 | 182 |
169 inline bool operator!=(const BlobData& a, const BlobData& b) { | 183 inline bool operator!=(const BlobData& a, const BlobData& b) { |
170 return !(a == b); | 184 return !(a == b); |
171 } | 185 } |
172 #endif // defined(UNIT_TEST) | 186 #endif // defined(UNIT_TEST) |
173 | 187 |
174 } // namespace webkit_blob | 188 } // namespace webkit_blob |
175 | 189 |
176 #endif // WEBKIT_BLOB_BLOB_DATA_H_ | 190 #endif // WEBKIT_BLOB_BLOB_DATA_H_ |
OLD | NEW |