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

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

Issue 29513003: Cleanup deprecated and no longer needed blob revamp stuff, deadcode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 1 month 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 | « webkit/common/blob/blob_data.cc ('k') | webkit/common/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 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
(...skipping 18 matching lines...) Expand all
29 TYPE_FILE_FILESYSTEM, 29 TYPE_FILE_FILESYSTEM,
30 }; 30 };
31 31
32 DataElement(); 32 DataElement();
33 ~DataElement(); 33 ~DataElement();
34 34
35 Type type() const { return type_; } 35 Type type() const { return type_; }
36 const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; } 36 const char* bytes() const { return bytes_ ? bytes_ : &buf_[0]; }
37 const base::FilePath& path() const { return path_; } 37 const base::FilePath& path() const { return path_; }
38 const GURL& filesystem_url() const { return filesystem_url_; } 38 const GURL& filesystem_url() const { return filesystem_url_; }
39
40 // TODO(michaeln): crbug/174200, fully switch to using string uuids.
41 // Note: Identifying blobs by url is being deprecated, but while
42 // transitioning, there's a little of both going on in the project.
43 const std::string& blob_uuid() const { return blob_uuid_; } 39 const std::string& blob_uuid() const { return blob_uuid_; }
44 const GURL& blob_url() const { return blob_url_; }
45 uint64 offset() const { return offset_; } 40 uint64 offset() const { return offset_; }
46 uint64 length() const { return length_; } 41 uint64 length() const { return length_; }
47 const base::Time& expected_modification_time() const { 42 const base::Time& expected_modification_time() const {
48 return expected_modification_time_; 43 return expected_modification_time_;
49 } 44 }
50 45
51 // 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.
52 void SetToBytes(const char* bytes, int bytes_len) { 47 void SetToBytes(const char* bytes, int bytes_len) {
53 type_ = TYPE_BYTES; 48 type_ = TYPE_BYTES;
54 buf_.assign(bytes, bytes + bytes_len); 49 buf_.assign(bytes, bytes + bytes_len);
55 length_ = buf_.size(); 50 length_ = buf_.size();
56 } 51 }
57 52
58 // 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
59 // 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.
60 void SetToSharedBytes(const char* bytes, int bytes_len) { 55 void SetToSharedBytes(const char* bytes, int bytes_len) {
61 type_ = TYPE_BYTES; 56 type_ = TYPE_BYTES;
62 bytes_ = bytes; 57 bytes_ = bytes;
63 length_ = bytes_len; 58 length_ = bytes_len;
64 } 59 }
65 60
66 // Sets TYPE_FILE data. 61 // Sets TYPE_FILE data.
67 void SetToFilePath(const base::FilePath& path) { 62 void SetToFilePath(const base::FilePath& path) {
68 SetToFilePathRange(path, 0, kuint64max, base::Time()); 63 SetToFilePathRange(path, 0, kuint64max, base::Time());
69 } 64 }
70 65
71 // Sets TYPE_BLOB data. 66 // Sets TYPE_BLOB data.
72 void SetToBlobUrl(const GURL& blob_url) {
73 SetToBlobUrlRange(blob_url, 0, kuint64max);
74 }
75 void SetToBlob(const std::string& uuid) { 67 void SetToBlob(const std::string& uuid) {
76 SetToBlobRange(uuid, 0, kuint64max); 68 SetToBlobRange(uuid, 0, kuint64max);
77 } 69 }
78 70
79 // Sets TYPE_FILE data with range. 71 // Sets TYPE_FILE data with range.
80 void SetToFilePathRange(const base::FilePath& path, 72 void SetToFilePathRange(const base::FilePath& path,
81 uint64 offset, uint64 length, 73 uint64 offset, uint64 length,
82 const base::Time& expected_modification_time); 74 const base::Time& expected_modification_time);
83 75
84 // Sets TYPE_BLOB data with range. 76 // Sets TYPE_BLOB data with range.
85 void SetToBlobUrlRange(const GURL& blob_url,
86 uint64 offset, uint64 length);
87 void SetToBlobRange(const std::string& blob_uuid, 77 void SetToBlobRange(const std::string& blob_uuid,
88 uint64 offset, uint64 length); 78 uint64 offset, uint64 length);
89 79
90 // Sets TYPE_FILE_FILESYSTEM with range. 80 // Sets TYPE_FILE_FILESYSTEM with range.
91 void SetToFileSystemUrlRange(const GURL& filesystem_url, 81 void SetToFileSystemUrlRange(const GURL& filesystem_url,
92 uint64 offset, uint64 length, 82 uint64 offset, uint64 length,
93 const base::Time& expected_modification_time); 83 const base::Time& expected_modification_time);
94 84
95 private: 85 private:
96 Type type_; 86 Type type_;
97 std::vector<char> buf_; // For TYPE_BYTES. 87 std::vector<char> buf_; // For TYPE_BYTES.
98 const char* bytes_; // For TYPE_BYTES. 88 const char* bytes_; // For TYPE_BYTES.
99 base::FilePath path_; // For TYPE_FILE. 89 base::FilePath path_; // For TYPE_FILE.
100 GURL filesystem_url_; // For TYPE_FILE_FILESYSTEM. 90 GURL filesystem_url_; // For TYPE_FILE_FILESYSTEM.
101 GURL blob_url_;
102 std::string blob_uuid_; 91 std::string blob_uuid_;
103 uint64 offset_; 92 uint64 offset_;
104 uint64 length_; 93 uint64 length_;
105 base::Time expected_modification_time_; 94 base::Time expected_modification_time_;
106 }; 95 };
107 96
108 #if defined(UNIT_TEST) 97 #if defined(UNIT_TEST)
109 inline bool operator==(const DataElement& a, const DataElement& b) { 98 inline bool operator==(const DataElement& a, const DataElement& b) {
110 if (a.type() != b.type() || 99 if (a.type() != b.type() ||
111 a.offset() != b.offset() || 100 a.offset() != b.offset() ||
112 a.length() != b.length()) 101 a.length() != b.length())
113 return false; 102 return false;
114 switch (a.type()) { 103 switch (a.type()) {
115 case DataElement::TYPE_BYTES: 104 case DataElement::TYPE_BYTES:
116 return memcmp(a.bytes(), b.bytes(), b.length()) == 0; 105 return memcmp(a.bytes(), b.bytes(), b.length()) == 0;
117 case DataElement::TYPE_FILE: 106 case DataElement::TYPE_FILE:
118 return a.path() == b.path() && 107 return a.path() == b.path() &&
119 a.expected_modification_time() == b.expected_modification_time(); 108 a.expected_modification_time() == b.expected_modification_time();
120 case DataElement::TYPE_BLOB: 109 case DataElement::TYPE_BLOB:
121 return a.blob_uuid().empty() ? (a.blob_url() == b.blob_url()) 110 return a.blob_uuid() == b.blob_uuid();
122 : (a.blob_uuid() == b.blob_uuid());
123 case DataElement::TYPE_FILE_FILESYSTEM: 111 case DataElement::TYPE_FILE_FILESYSTEM:
124 return a.filesystem_url() == b.filesystem_url(); 112 return a.filesystem_url() == b.filesystem_url();
125 case DataElement::TYPE_UNKNOWN: 113 case DataElement::TYPE_UNKNOWN:
126 NOTREACHED(); 114 NOTREACHED();
127 return false; 115 return false;
128 } 116 }
129 return false; 117 return false;
130 } 118 }
131 119
132 inline bool operator!=(const DataElement& a, const DataElement& b) { 120 inline bool operator!=(const DataElement& a, const DataElement& b) {
133 return !(a == b); 121 return !(a == b);
134 } 122 }
135 #endif // defined(UNIT_TEST) 123 #endif // defined(UNIT_TEST)
136 124
137 } // namespace webkit_common 125 } // namespace webkit_common
138 126
139 #endif // WEBKIT_COMMON_DATA_ELEMENT_H_ 127 #endif // WEBKIT_COMMON_DATA_ELEMENT_H_
OLDNEW
« no previous file with comments | « webkit/common/blob/blob_data.cc ('k') | webkit/common/data_element.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698