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

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

Issue 810403004: [Storage] Blob Storage Refactoring pt 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed copyright Created 5 years, 11 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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_
6 #define STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_
7
8 #include <string>
9 #include <vector>
10
11 #include "base/basictypes.h"
12 #include "base/files/file_path.h"
13 #include "storage/browser/blob/blob_data_item.h"
14 #include "storage/browser/blob/blob_data_snapshot.h"
15 #include "storage/browser/storage_browser_export.h"
16
17 namespace storage {
18 class BlobStorageContext;
19
20 class STORAGE_EXPORT BlobDataBuilder {
21 public:
22 explicit BlobDataBuilder(const std::string& uuid);
23 virtual ~BlobDataBuilder();
24
25 const std::string& uuid() const { return uuid_; }
26
27 void AppendData(const std::string& data) {
28 AppendData(data.c_str(), data.size());
29 }
30
31 void AppendData(const char* data, size_t length);
32
33 void AppendFile(const base::FilePath& file_path,
34 uint64 offset,
35 uint64 length,
36 const base::Time& expected_modification_time);
37
38 void AppendFile(const base::FilePath& file_path,
39 uint64 offset,
40 uint64 length,
41 const base::Time& expected_modification_time,
42 scoped_refptr<ShareableFileReference> shareable_file);
43
44 void AppendBlob(const std::string& uuid, uint64 offset, uint64 length);
45 void AppendFileSystemFile(const GURL& url,
46 uint64 offset,
47 uint64 length,
48 const base::Time& expected_modification_time);
49
50 void set_content_type(const std::string& content_type) {
51 content_type_ = content_type;
52 }
53
54 void set_content_disposition(const std::string& content_disposition) {
55 content_disposition_ = content_disposition;
56 }
57
58 size_t GetMemoryUsage() const;
59
60 scoped_ptr<BlobDataSnapshot> BuildSnapshot();
61
62 private:
63 friend class BlobStorageContext;
64 friend bool operator==(const BlobDataBuilder& a, const BlobDataBuilder& b);
65 friend bool operator==(const BlobDataSnapshot& a, const BlobDataBuilder& b);
66
67 std::string uuid_;
68 std::string content_type_;
69 std::string content_disposition_;
70 std::vector<scoped_refptr<BlobDataItem>> items_;
71
72 DISALLOW_COPY_AND_ASSIGN(BlobDataBuilder);
73 };
74
75 #if defined(UNIT_TEST)
76 inline bool operator==(const BlobDataBuilder& a, const BlobDataBuilder& b) {
77 if (a.content_type_ != b.content_type_)
78 return false;
79 if (a.content_disposition_ != b.content_disposition_)
80 return false;
81 if (a.items_.size() != b.items_.size())
82 return false;
83 for (size_t i = 0; i < a.items_.size(); ++i) {
84 if (a.items_[i] != b.items_[i])
85 return false;
86 }
87 return true;
88 }
89
90 inline bool operator==(const BlobDataSnapshot& a, const BlobDataBuilder& b) {
91 if (a.content_type() != b.content_type_) {
92 return false;
93 }
94 if (a.content_disposition() != b.content_disposition_) {
95 return false;
96 }
97 if (a.items().size() != b.items_.size()) {
98 return false;
99 }
100 for (size_t i = 0; i < a.items().size(); ++i) {
101 if (*(a.items()[i]) != *(b.items_[i])) {
102 return false;
103 }
104 }
105 return true;
106 }
107
108 inline bool operator!=(const BlobDataSnapshot& a, const BlobDataBuilder& b) {
109 return !(a == b);
110 }
111
112 inline bool operator!=(const BlobDataBuilder& a, const BlobDataBuilder& b) {
113 return !(a == b);
114 }
115 #endif // defined(UNIT_TEST)
116
117 } // namespace storage
118 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698