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

Side by Side Diff: storage/browser/blob/blob_data_builder.h

Issue 1288373002: [BlobAsync] Patch 2: Common Constants (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@async1
Patch Set: removed messages Created 5 years, 2 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
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 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 STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_
6 #define STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ 6 #define STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <ostream>
9 #include <string> 10 #include <string>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/basictypes.h" 13 #include "base/basictypes.h"
13 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
15 #include "storage/browser/blob/blob_data_item.h" 16 #include "storage/browser/blob/blob_data_item.h"
16 #include "storage/browser/blob/blob_data_snapshot.h" 17 #include "storage/browser/blob/blob_data_snapshot.h"
17 #include "storage/browser/storage_browser_export.h" 18 #include "storage/browser/storage_browser_export.h"
18 19
19 namespace disk_cache { 20 namespace disk_cache {
20 class Entry; 21 class Entry;
21 } 22 }
22 23
23 namespace storage { 24 namespace storage {
24 class BlobStorageContext; 25 class BlobStorageContext;
25 26
26 class STORAGE_EXPORT BlobDataBuilder { 27 class STORAGE_EXPORT BlobDataBuilder {
27 public: 28 public:
28 using DataHandle = BlobDataItem::DataHandle; 29 using DataHandle = BlobDataItem::DataHandle;
29 30
30 explicit BlobDataBuilder(const std::string& uuid); 31 explicit BlobDataBuilder(const std::string& uuid);
31 ~BlobDataBuilder(); 32 ~BlobDataBuilder();
32 33
33 const std::string& uuid() const { return uuid_; } 34 const std::string& uuid() const { return uuid_; }
34 35
36 // Validates the data element, and copies the data if it's a 'bytes' element.
37 // Cannot append elements of BYTES_DESCRIPTION or DISK_CACHE_ENTRY types.
38 void AppendDataElement(const DataElement& element);
michaeln 2015/10/20 01:16:14 Is this new method needed given the type specific
dmurph 2015/10/20 18:28:27 I renamed it to be mores specific for IPC data. I
39
35 void AppendData(const std::string& data) { 40 void AppendData(const std::string& data) {
36 AppendData(data.c_str(), data.size()); 41 AppendData(data.c_str(), data.size());
37 } 42 }
38 43
39 void AppendData(const char* data, size_t length); 44 void AppendData(const char* data, size_t length);
40 45
46 // ***** Async construction methods *****
47 void AppendFutureData(size_t length);
48 bool PopulateFutureData(size_t index,
kinuko 2015/10/20 10:06:22 Could we add a comment when this returns true/fals
dmurph 2015/10/20 18:28:27 Done.
49 const char* data,
50 size_t offset,
51 size_t length);
52 // **************************************
michaeln 2015/10/20 01:16:14 style nit: the asterisk heavy comments look out of
dmurph 2015/10/20 18:28:27 Done.
53
41 // You must know the length of the file, you cannot use kuint64max to specify 54 // You must know the length of the file, you cannot use kuint64max to specify
42 // the whole file. This method creates a ShareableFileReference to the given 55 // the whole file. This method creates a ShareableFileReference to the given
43 // file, which is stored in this builder. 56 // file, which is stored in this builder.
44 void AppendFile(const base::FilePath& file_path, 57 void AppendFile(const base::FilePath& file_path,
45 uint64_t offset, 58 uint64_t offset,
46 uint64_t length, 59 uint64_t length,
47 const base::Time& expected_modification_time); 60 const base::Time& expected_modification_time);
48 61
49 void AppendBlob(const std::string& uuid, uint64_t offset, uint64_t length); 62 void AppendBlob(const std::string& uuid, uint64_t offset, uint64_t length);
50 63
51 void AppendBlob(const std::string& uuid); 64 void AppendBlob(const std::string& uuid);
52 65
53 void AppendFileSystemFile(const GURL& url, 66 void AppendFileSystemFile(const GURL& url,
54 uint64_t offset, 67 uint64_t offset,
55 uint64_t length, 68 uint64_t length,
56 const base::Time& expected_modification_time); 69 const base::Time& expected_modification_time);
57 70
58 void AppendDiskCacheEntry(const scoped_refptr<DataHandle>& data_handle, 71 void AppendDiskCacheEntry(const scoped_refptr<DataHandle>& data_handle,
59 disk_cache::Entry* disk_cache_entry, 72 disk_cache::Entry* disk_cache_entry,
60 int disk_cache_stream_index); 73 int disk_cache_stream_index);
61 74
62 void set_content_type(const std::string& content_type) { 75 void set_content_type(const std::string& content_type) {
63 content_type_ = content_type; 76 content_type_ = content_type;
64 } 77 }
65 78
66 void set_content_disposition(const std::string& content_disposition) { 79 void set_content_disposition(const std::string& content_disposition) {
67 content_disposition_ = content_disposition; 80 content_disposition_ = content_disposition;
68 } 81 }
69 82
83 void Clear();
84
70 private: 85 private:
71 friend class BlobStorageContext; 86 friend class BlobStorageContext;
87 friend class BlobAsyncBuilderHostTest;
72 friend bool operator==(const BlobDataBuilder& a, const BlobDataBuilder& b); 88 friend bool operator==(const BlobDataBuilder& a, const BlobDataBuilder& b);
73 friend bool operator==(const BlobDataSnapshot& a, const BlobDataBuilder& b); 89 friend bool operator==(const BlobDataSnapshot& a, const BlobDataBuilder& b);
90 friend STORAGE_EXPORT void PrintTo(const BlobDataBuilder& x,
91 ::std::ostream* os);
74 92
75 std::string uuid_; 93 std::string uuid_;
76 std::string content_type_; 94 std::string content_type_;
77 std::string content_disposition_; 95 std::string content_disposition_;
78 std::vector<scoped_refptr<BlobDataItem>> items_; 96 std::vector<scoped_refptr<BlobDataItem>> items_;
79 97
80 DISALLOW_COPY_AND_ASSIGN(BlobDataBuilder); 98 DISALLOW_COPY_AND_ASSIGN(BlobDataBuilder);
81 }; 99 };
82 100
83 #if defined(UNIT_TEST) 101 #if defined(UNIT_TEST)
84 inline bool operator==(const BlobDataBuilder& a, const BlobDataBuilder& b) { 102 inline bool operator==(const BlobDataBuilder& a, const BlobDataBuilder& b) {
85 if (a.content_type_ != b.content_type_) 103 if (a.content_type_ != b.content_type_)
86 return false; 104 return false;
87 if (a.content_disposition_ != b.content_disposition_) 105 if (a.content_disposition_ != b.content_disposition_)
88 return false; 106 return false;
89 if (a.items_.size() != b.items_.size()) 107 if (a.items_.size() != b.items_.size())
90 return false; 108 return false;
91 for (size_t i = 0; i < a.items_.size(); ++i) { 109 for (size_t i = 0; i < a.items_.size(); ++i) {
92 if (a.items_[i] != b.items_[i]) 110 if (*(a.items_[i]) != *(b.items_[i]))
93 return false; 111 return false;
94 } 112 }
95 return true; 113 return true;
96 } 114 }
97 115
98 inline bool operator==(const BlobDataSnapshot& a, const BlobDataBuilder& b) { 116 inline bool operator==(const BlobDataSnapshot& a, const BlobDataBuilder& b) {
99 if (a.content_type() != b.content_type_) { 117 if (a.content_type() != b.content_type_) {
100 return false; 118 return false;
101 } 119 }
102 if (a.content_disposition() != b.content_disposition_) { 120 if (a.content_disposition() != b.content_disposition_) {
103 return false; 121 return false;
104 } 122 }
105 if (a.items().size() != b.items_.size()) { 123 if (a.items().size() != b.items_.size()) {
106 return false; 124 return false;
107 } 125 }
108 for (size_t i = 0; i < a.items().size(); ++i) { 126 for (size_t i = 0; i < a.items().size(); ++i) {
109 if (*(a.items()[i]) != *(b.items_[i])) 127 if (*(a.items()[i]) != *(b.items_[i]))
110 return false; 128 return false;
111 } 129 }
112 return true; 130 return true;
113 } 131 }
114 132
115 inline bool operator!=(const BlobDataSnapshot& a, const BlobDataBuilder& b) { 133 inline bool operator!=(const BlobDataSnapshot& a, const BlobDataBuilder& b) {
116 return !(a == b); 134 return !(a == b);
117 } 135 }
118 136
119 inline bool operator!=(const BlobDataBuilder& a, const BlobDataBuilder& b) { 137 inline bool operator!=(const BlobDataBuilder& a, const BlobDataBuilder& b) {
120 return !(a == b); 138 return !(a == b);
121 } 139 }
140
122 #endif // defined(UNIT_TEST) 141 #endif // defined(UNIT_TEST)
123 142
124 } // namespace storage 143 } // namespace storage
125 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_ 144 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698