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_BASE_DATA_ELEMENT_H_ | 5 #ifndef WEBKIT_BASE_DATA_ELEMENT_H_ |
6 #define WEBKIT_BASE_DATA_ELEMENT_H_ | 6 #define WEBKIT_BASE_DATA_ELEMENT_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 TYPE_FILE, | 26 TYPE_FILE, |
27 TYPE_BLOB, | 27 TYPE_BLOB, |
28 TYPE_FILE_FILESYSTEM, | 28 TYPE_FILE_FILESYSTEM, |
29 }; | 29 }; |
30 | 30 |
31 DataElement(); | 31 DataElement(); |
32 ~DataElement(); | 32 ~DataElement(); |
33 | 33 |
34 Type type() const { return type_; } | 34 Type type() const { return type_; } |
35 const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; } | 35 const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; } |
36 const FilePath& path() const { return path_; } | 36 const base::FilePath& path() const { return path_; } |
37 const GURL& url() const { return url_; } | 37 const GURL& url() const { return url_; } |
38 uint64 offset() const { return offset_; } | 38 uint64 offset() const { return offset_; } |
39 uint64 length() const { return length_; } | 39 uint64 length() const { return length_; } |
40 const base::Time& expected_modification_time() const { | 40 const base::Time& expected_modification_time() const { |
41 return expected_modification_time_; | 41 return expected_modification_time_; |
42 } | 42 } |
43 | 43 |
44 // Sets TYPE_BYTES data. This copies the given data into the element. | 44 // Sets TYPE_BYTES data. This copies the given data into the element. |
45 void SetToBytes(const char* bytes, int bytes_len) { | 45 void SetToBytes(const char* bytes, int bytes_len) { |
46 type_ = TYPE_BYTES; | 46 type_ = TYPE_BYTES; |
47 buf_.assign(bytes, bytes + bytes_len); | 47 buf_.assign(bytes, bytes + bytes_len); |
48 length_ = buf_.size(); | 48 length_ = buf_.size(); |
49 } | 49 } |
50 | 50 |
51 // Sets TYPE_BYTES data. This does NOT copy the given data and the caller | 51 // Sets TYPE_BYTES data. This does NOT copy the given data and the caller |
52 // should make sure the data is alive when this element is accessed. | 52 // should make sure the data is alive when this element is accessed. |
53 void SetToSharedBytes(const char* bytes, int bytes_len) { | 53 void SetToSharedBytes(const char* bytes, int bytes_len) { |
54 type_ = TYPE_BYTES; | 54 type_ = TYPE_BYTES; |
55 bytes_ = bytes; | 55 bytes_ = bytes; |
56 length_ = bytes_len; | 56 length_ = bytes_len; |
57 } | 57 } |
58 | 58 |
59 // Sets TYPE_FILE data. | 59 // Sets TYPE_FILE data. |
60 void SetToFilePath(const FilePath& path) { | 60 void SetToFilePath(const base::FilePath& path) { |
61 SetToFilePathRange(path, 0, kuint64max, base::Time()); | 61 SetToFilePathRange(path, 0, kuint64max, base::Time()); |
62 } | 62 } |
63 | 63 |
64 // Sets TYPE_BLOB data. | 64 // Sets TYPE_BLOB data. |
65 void SetToBlobUrl(const GURL& blob_url) { | 65 void SetToBlobUrl(const GURL& blob_url) { |
66 SetToBlobUrlRange(blob_url, 0, kuint64max); | 66 SetToBlobUrlRange(blob_url, 0, kuint64max); |
67 } | 67 } |
68 | 68 |
69 // Sets TYPE_FILE data with range. | 69 // Sets TYPE_FILE data with range. |
70 void SetToFilePathRange(const FilePath& path, | 70 void SetToFilePathRange(const base::FilePath& path, |
71 uint64 offset, uint64 length, | 71 uint64 offset, uint64 length, |
72 const base::Time& expected_modification_time); | 72 const base::Time& expected_modification_time); |
73 | 73 |
74 // Sets TYPE_BLOB data with range. | 74 // Sets TYPE_BLOB data with range. |
75 void SetToBlobUrlRange(const GURL& blob_url, | 75 void SetToBlobUrlRange(const GURL& blob_url, |
76 uint64 offset, uint64 length); | 76 uint64 offset, uint64 length); |
77 | 77 |
78 // Sets TYPE_FILE_FILESYSTEM with range. | 78 // Sets TYPE_FILE_FILESYSTEM with range. |
79 void SetToFileSystemUrlRange(const GURL& filesystem_url, | 79 void SetToFileSystemUrlRange(const GURL& filesystem_url, |
80 uint64 offset, uint64 length, | 80 uint64 offset, uint64 length, |
81 const base::Time& expected_modification_time); | 81 const base::Time& expected_modification_time); |
82 | 82 |
83 private: | 83 private: |
84 Type type_; | 84 Type type_; |
85 std::vector<char> buf_; // For TYPE_BYTES. | 85 std::vector<char> buf_; // For TYPE_BYTES. |
86 const char* bytes_; // For TYPE_BYTES. | 86 const char* bytes_; // For TYPE_BYTES. |
87 FilePath path_; // For TYPE_FILE. | 87 base::FilePath path_; // For TYPE_FILE. |
88 GURL url_; // For TYPE_BLOB or TYPE_FILE_FILESYSTEM. | 88 GURL url_; // For TYPE_BLOB or TYPE_FILE_FILESYSTEM. |
89 uint64 offset_; | 89 uint64 offset_; |
90 uint64 length_; | 90 uint64 length_; |
91 base::Time expected_modification_time_; | 91 base::Time expected_modification_time_; |
92 }; | 92 }; |
93 | 93 |
94 #if defined(UNIT_TEST) | 94 #if defined(UNIT_TEST) |
95 inline bool operator==(const DataElement& a, const DataElement& b) { | 95 inline bool operator==(const DataElement& a, const DataElement& b) { |
96 if (a.type() != b.type() || | 96 if (a.type() != b.type() || |
97 a.offset() != b.offset() || | 97 a.offset() != b.offset() || |
(...skipping 16 matching lines...) Expand all Loading... |
114 } | 114 } |
115 | 115 |
116 inline bool operator!=(const DataElement& a, const DataElement& b) { | 116 inline bool operator!=(const DataElement& a, const DataElement& b) { |
117 return !(a == b); | 117 return !(a == b); |
118 } | 118 } |
119 #endif // defined(UNIT_TEST) | 119 #endif // defined(UNIT_TEST) |
120 | 120 |
121 } // namespace webkit_base | 121 } // namespace webkit_base |
122 | 122 |
123 #endif // WEBKIT_BASE_DATA_ELEMENT_H_ | 123 #endif // WEBKIT_BASE_DATA_ELEMENT_H_ |
OLD | NEW |