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

Side by Side Diff: webkit/base/data_element.h

Issue 10828252: Support FileSystem URL in File object (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment fix Created 8 years, 3 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 | « content/public/common/common_param_traits.cc ('k') | webkit/base/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 (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"
11 #include "base/file_path.h" 11 #include "base/file_path.h"
12 #include "base/logging.h" 12 #include "base/logging.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/base/webkit_base_export.h" 15 #include "webkit/base/webkit_base_export.h"
16 16
17 namespace webkit_base { 17 namespace webkit_base {
18 18
19 // Represents a base Web data element. This could be either one of 19 // Represents a base Web data element. This could be either one of
20 // bytes, file or blob data. 20 // bytes, file or blob data.
21 class WEBKIT_BASE_EXPORT DataElement { 21 class WEBKIT_BASE_EXPORT DataElement {
22 public: 22 public:
23 enum Type { 23 enum Type {
24 TYPE_UNKNOWN = -1, 24 TYPE_UNKNOWN = -1,
25 TYPE_BYTES, 25 TYPE_BYTES,
26 TYPE_FILE, 26 TYPE_FILE,
27 TYPE_BLOB, 27 TYPE_BLOB,
28 TYPE_FILE_FILESYSTEM,
28 }; 29 };
29 30
30 DataElement(); 31 DataElement();
31 ~DataElement(); 32 ~DataElement();
32 33
33 Type type() const { return type_; } 34 Type type() const { return type_; }
34 const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; } 35 const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; }
35 const FilePath& path() const { return path_; } 36 const FilePath& path() const { return path_; }
36 const GURL& url() const { return url_; } 37 const GURL& url() const { return url_; }
37 uint64 offset() const { return offset_; } 38 uint64 offset() const { return offset_; }
(...skipping 29 matching lines...) Expand all
67 68
68 // Sets TYPE_FILE data with range. 69 // Sets TYPE_FILE data with range.
69 void SetToFilePathRange(const FilePath& path, 70 void SetToFilePathRange(const FilePath& path,
70 uint64 offset, uint64 length, 71 uint64 offset, uint64 length,
71 const base::Time& expected_modification_time); 72 const base::Time& expected_modification_time);
72 73
73 // Sets TYPE_BLOB data with range. 74 // Sets TYPE_BLOB data with range.
74 void SetToBlobUrlRange(const GURL& blob_url, 75 void SetToBlobUrlRange(const GURL& blob_url,
75 uint64 offset, uint64 length); 76 uint64 offset, uint64 length);
76 77
78 // Sets TYPE_FILE_FILESYSTEM with range.
79 void SetToFileSystemUrlRange(const GURL& filesystem_url,
80 uint64 offset, uint64 length,
81 const base::Time& expected_modification_time);
82
77 private: 83 private:
78 Type type_; 84 Type type_;
79 std::vector<char> buf_; 85 std::vector<char> buf_; // For TYPE_BYTES.
80 const char* bytes_; 86 const char* bytes_; // For TYPE_BYTES.
81 FilePath path_; 87 FilePath path_; // For TYPE_FILE.
82 GURL url_; 88 GURL url_; // For TYPE_BLOB or TYPE_FILE_FILESYSTEM.
83 uint64 offset_; 89 uint64 offset_;
84 uint64 length_; 90 uint64 length_;
85 base::Time expected_modification_time_; 91 base::Time expected_modification_time_;
86 }; 92 };
87 93
88 #if defined(UNIT_TEST) 94 #if defined(UNIT_TEST)
89 inline bool operator==(const DataElement& a, const DataElement& b) { 95 inline bool operator==(const DataElement& a, const DataElement& b) {
90 if (a.type() != b.type() || 96 if (a.type() != b.type() ||
91 a.offset() != b.offset() || 97 a.offset() != b.offset() ||
92 a.length() != b.length()) 98 a.length() != b.length())
93 return false; 99 return false;
94 switch (a.type()) { 100 switch (a.type()) {
95 case DataElement::TYPE_BYTES: 101 case DataElement::TYPE_BYTES:
96 return memcmp(a.bytes(), b.bytes(), b.length()) == 0; 102 return memcmp(a.bytes(), b.bytes(), b.length()) == 0;
97 case DataElement::TYPE_FILE: 103 case DataElement::TYPE_FILE:
98 return a.path() == b.path() && 104 return a.path() == b.path() &&
99 a.expected_modification_time() == b.expected_modification_time(); 105 a.expected_modification_time() == b.expected_modification_time();
100 case DataElement::TYPE_BLOB: 106 case DataElement::TYPE_BLOB:
107 case DataElement::TYPE_FILE_FILESYSTEM:
101 return a.url() == b.url(); 108 return a.url() == b.url();
102 case DataElement::TYPE_UNKNOWN: 109 case DataElement::TYPE_UNKNOWN:
103 NOTREACHED(); 110 NOTREACHED();
104 return false; 111 return false;
105 } 112 }
106 return false; 113 return false;
107 } 114 }
108 115
109 inline bool operator!=(const DataElement& a, const DataElement& b) { 116 inline bool operator!=(const DataElement& a, const DataElement& b) {
110 return !(a == b); 117 return !(a == b);
111 } 118 }
112 #endif // defined(UNIT_TEST) 119 #endif // defined(UNIT_TEST)
113 120
114 } // namespace webkit_base 121 } // namespace webkit_base
115 122
116 #endif // WEBKIT_BASE_DATA_ELEMENT_H_ 123 #endif // WEBKIT_BASE_DATA_ELEMENT_H_
OLDNEW
« no previous file with comments | « content/public/common/common_param_traits.cc ('k') | webkit/base/data_element.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698