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
3 // found in the LICENSE file.
5 #ifndef STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_
6 #define STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_
12 #include "base/basictypes.h"
13 #include "base/files/file_path.h"
14 #include "base/memory/ref_counted.h"
15 #include "storage/browser/blob/blob_data_item.h"
16 #include "storage/browser/blob/blob_data_snapshot.h"
17 #include "storage/browser/storage_browser_export.h"
19 namespace disk_cache
{
24 class BlobStorageContext
;
26 class STORAGE_EXPORT BlobDataBuilder
{
28 using DataHandle
= BlobDataItem::DataHandle
;
30 explicit BlobDataBuilder(const std::string
& uuid
);
33 const std::string
& uuid() const { return uuid_
; }
35 void AppendData(const std::string
& data
) {
36 AppendData(data
.c_str(), data
.size());
39 void AppendData(const char* data
, size_t length
);
41 // 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
43 // file, which is stored in this builder.
44 void AppendFile(const base::FilePath
& file_path
,
47 const base::Time
& expected_modification_time
);
49 void AppendBlob(const std::string
& uuid
, uint64_t offset
, uint64_t length
);
51 void AppendBlob(const std::string
& uuid
);
53 void AppendFileSystemFile(const GURL
& url
,
56 const base::Time
& expected_modification_time
);
58 void AppendDiskCacheEntry(const scoped_refptr
<DataHandle
>& data_handle
,
59 disk_cache::Entry
* disk_cache_entry
,
60 int disk_cache_stream_index
);
62 void set_content_type(const std::string
& content_type
) {
63 content_type_
= content_type
;
66 void set_content_disposition(const std::string
& content_disposition
) {
67 content_disposition_
= content_disposition
;
71 friend class BlobStorageContext
;
72 friend bool operator==(const BlobDataBuilder
& a
, const BlobDataBuilder
& b
);
73 friend bool operator==(const BlobDataSnapshot
& a
, const BlobDataBuilder
& b
);
76 std::string content_type_
;
77 std::string content_disposition_
;
78 std::vector
<scoped_refptr
<BlobDataItem
>> items_
;
80 DISALLOW_COPY_AND_ASSIGN(BlobDataBuilder
);
83 #if defined(UNIT_TEST)
84 inline bool operator==(const BlobDataBuilder
& a
, const BlobDataBuilder
& b
) {
85 if (a
.content_type_
!= b
.content_type_
)
87 if (a
.content_disposition_
!= b
.content_disposition_
)
89 if (a
.items_
.size() != b
.items_
.size())
91 for (size_t i
= 0; i
< a
.items_
.size(); ++i
) {
92 if (a
.items_
[i
] != b
.items_
[i
])
98 inline bool operator==(const BlobDataSnapshot
& a
, const BlobDataBuilder
& b
) {
99 if (a
.content_type() != b
.content_type_
) {
102 if (a
.content_disposition() != b
.content_disposition_
) {
105 if (a
.items().size() != b
.items_
.size()) {
108 for (size_t i
= 0; i
< a
.items().size(); ++i
) {
109 if (*(a
.items()[i
]) != *(b
.items_
[i
]))
115 inline bool operator!=(const BlobDataSnapshot
& a
, const BlobDataBuilder
& b
) {
119 inline bool operator!=(const BlobDataBuilder
& a
, const BlobDataBuilder
& b
) {
122 #endif // defined(UNIT_TEST)
124 } // namespace storage
125 #endif // STORAGE_BROWSER_BLOB_BLOB_DATA_BUILDER_H_