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

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

Issue 11410019: ********** Chromium Blob hacking (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years 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
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 <string>
8 #include <vector> 9 #include <vector>
9 10
10 #include "base/basictypes.h" 11 #include "base/basictypes.h"
11 #include "base/file_path.h" 12 #include "base/file_path.h"
12 #include "base/logging.h" 13 #include "base/logging.h"
13 #include "base/time.h" 14 #include "base/time.h"
14 #include "googleurl/src/gurl.h" 15 #include "googleurl/src/gurl.h"
15 #include "webkit/base/webkit_base_export.h" 16 #include "webkit/base/webkit_base_export.h"
16 17
17 namespace webkit_base { 18 namespace webkit_base {
18 19
19 // 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
20 // bytes, file or blob data. 21 // bytes, file or blob data.
21 class WEBKIT_BASE_EXPORT DataElement { 22 class WEBKIT_BASE_EXPORT DataElement {
22 public: 23 public:
23 enum Type { 24 enum Type {
24 TYPE_UNKNOWN = -1, 25 TYPE_UNKNOWN = -1,
25 TYPE_BYTES, 26 TYPE_BYTES,
26 TYPE_FILE, 27 TYPE_FILE,
27 TYPE_BLOB, 28 TYPE_BLOB,
28 TYPE_FILE_FILESYSTEM, 29 TYPE_FILE_FILESYSTEM,
29 }; 30 };
30 31
31 DataElement(); 32 DataElement();
32 ~DataElement(); 33 ~DataElement();
33 34
34 Type type() const { return type_; } 35 Type type() const { return type_; }
35 const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; } 36 const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; }
36 const FilePath& path() const { return path_; } 37 const FilePath& path() const { return path_; }
37 const GURL& url() const { return url_; } 38 const GURL& filesystem_url() const { return filesystem_url_; }
39 const std::string& blob_uuid() const { return blob_uuid_; }
38 uint64 offset() const { return offset_; } 40 uint64 offset() const { return offset_; }
39 uint64 length() const { return length_; } 41 uint64 length() const { return length_; }
40 const base::Time& expected_modification_time() const { 42 const base::Time& expected_modification_time() const {
41 return expected_modification_time_; 43 return expected_modification_time_;
42 } 44 }
43 45
44 // Sets TYPE_BYTES data. This copies the given data into the element. 46 // Sets TYPE_BYTES data. This copies the given data into the element.
45 void SetToBytes(const char* bytes, int bytes_len) { 47 void SetToBytes(const char* bytes, int bytes_len) {
46 type_ = TYPE_BYTES; 48 type_ = TYPE_BYTES;
47 buf_.assign(bytes, bytes + bytes_len); 49 buf_.assign(bytes, bytes + bytes_len);
48 length_ = buf_.size(); 50 length_ = buf_.size();
49 } 51 }
50 52
51 // Sets TYPE_BYTES data. This does NOT copy the given data and the caller 53 // 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. 54 // should make sure the data is alive when this element is accessed.
53 void SetToSharedBytes(const char* bytes, int bytes_len) { 55 void SetToSharedBytes(const char* bytes, int bytes_len) {
54 type_ = TYPE_BYTES; 56 type_ = TYPE_BYTES;
55 bytes_ = bytes; 57 bytes_ = bytes;
56 length_ = bytes_len; 58 length_ = bytes_len;
57 } 59 }
58 60
59 // Sets TYPE_FILE data. 61 // Sets TYPE_FILE data.
60 void SetToFilePath(const FilePath& path) { 62 void SetToFilePath(const FilePath& path) {
61 SetToFilePathRange(path, 0, kuint64max, base::Time()); 63 SetToFilePathRange(path, 0, kuint64max, base::Time());
62 } 64 }
63 65
64 // Sets TYPE_BLOB data. 66 // Sets TYPE_BLOB data.
65 void SetToBlobUrl(const GURL& blob_url) { 67 void SetToBlob(const std::string& uuid) {
66 SetToBlobUrlRange(blob_url, 0, kuint64max); 68 SetToBlobRange(uuid, 0, kuint64max);
67 } 69 }
68 70
69 // Sets TYPE_FILE data with range. 71 // Sets TYPE_FILE data with range.
70 void SetToFilePathRange(const FilePath& path, 72 void SetToFilePathRange(const FilePath& path,
71 uint64 offset, uint64 length, 73 uint64 offset, uint64 length,
72 const base::Time& expected_modification_time); 74 const base::Time& expected_modification_time);
73 75
74 // Sets TYPE_BLOB data with range. 76 // Sets TYPE_BLOB data with range.
75 void SetToBlobUrlRange(const GURL& blob_url, 77 void SetToBlobRange(const std::string& uuid,
76 uint64 offset, uint64 length); 78 uint64 offset, uint64 length);
77 79
78 // Sets TYPE_FILE_FILESYSTEM with range. 80 // Sets TYPE_FILE_FILESYSTEM with range.
79 void SetToFileSystemUrlRange(const GURL& filesystem_url, 81 void SetToFileSystemUrlRange(const GURL& filesystem_url,
80 uint64 offset, uint64 length, 82 uint64 offset, uint64 length,
81 const base::Time& expected_modification_time); 83 const base::Time& expected_modification_time);
82 84
83 private: 85 private:
84 Type type_; 86 Type type_;
85 std::vector<char> buf_; // For TYPE_BYTES. 87 std::vector<char> buf_; // For TYPE_BYTES.
86 const char* bytes_; // For TYPE_BYTES. 88 const char* bytes_; // For TYPE_BYTES when we don't own the buffer.
87 FilePath path_; // For TYPE_FILE. 89 FilePath path_; // For TYPE_FILE.
88 GURL url_; // For TYPE_BLOB or TYPE_FILE_FILESYSTEM. 90 GURL filesystem_url_; // For TYPE_FILE_FILESYSTEM.
91 std::string blob_uuid_; // For TYPE_BLOB
89 uint64 offset_; 92 uint64 offset_;
90 uint64 length_; 93 uint64 length_;
91 base::Time expected_modification_time_; 94 base::Time expected_modification_time_;
92 }; 95 };
93 96
94 #if defined(UNIT_TEST) 97 #if defined(UNIT_TEST)
95 inline bool operator==(const DataElement& a, const DataElement& b) { 98 inline bool operator==(const DataElement& a, const DataElement& b) {
96 if (a.type() != b.type() || 99 if (a.type() != b.type() ||
97 a.offset() != b.offset() || 100 a.offset() != b.offset() ||
98 a.length() != b.length()) 101 a.length() != b.length())
99 return false; 102 return false;
100 switch (a.type()) { 103 switch (a.type()) {
101 case DataElement::TYPE_BYTES: 104 case DataElement::TYPE_BYTES:
102 return memcmp(a.bytes(), b.bytes(), b.length()) == 0; 105 return memcmp(a.bytes(), b.bytes(), b.length()) == 0;
103 case DataElement::TYPE_FILE: 106 case DataElement::TYPE_FILE:
104 return a.path() == b.path() && 107 return a.path() == b.path() &&
105 a.expected_modification_time() == b.expected_modification_time(); 108 a.expected_modification_time() == b.expected_modification_time();
106 case DataElement::TYPE_BLOB: 109 case DataElement::TYPE_BLOB:
110 return a.blob_uuid() == b.blob_uuid();
107 case DataElement::TYPE_FILE_FILESYSTEM: 111 case DataElement::TYPE_FILE_FILESYSTEM:
108 return a.url() == b.url(); 112 return a.filesystem_url() == b.filesystem_url();
109 case DataElement::TYPE_UNKNOWN: 113 case DataElement::TYPE_UNKNOWN:
110 NOTREACHED(); 114 NOTREACHED();
111 return false; 115 return false;
112 } 116 }
113 return false; 117 return false;
114 } 118 }
115 119
116 inline bool operator!=(const DataElement& a, const DataElement& b) { 120 inline bool operator!=(const DataElement& a, const DataElement& b) {
117 return !(a == b); 121 return !(a == b);
118 } 122 }
119 #endif // defined(UNIT_TEST) 123 #endif // defined(UNIT_TEST)
120 124
121 } // namespace webkit_base 125 } // namespace webkit_base
122 126
123 #endif // WEBKIT_BASE_DATA_ELEMENT_H_ 127 #endif // WEBKIT_BASE_DATA_ELEMENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698