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 #include "storage/browser/blob/blob_data_builder.h"
7 #include "base/time/time.h"
8 #include "net/disk_cache/disk_cache.h"
9 #include "storage/browser/blob/shareable_file_reference.h"
13 BlobDataBuilder::BlobDataBuilder(const std::string
& uuid
) : uuid_(uuid
) {
15 BlobDataBuilder::~BlobDataBuilder() {
18 void BlobDataBuilder::AppendData(const char* data
, size_t length
) {
21 scoped_ptr
<DataElement
> element(new DataElement());
22 element
->SetToBytes(data
, length
);
23 items_
.push_back(new BlobDataItem(element
.Pass()));
26 void BlobDataBuilder::AppendFile(const base::FilePath
& file_path
,
29 const base::Time
& expected_modification_time
) {
30 scoped_ptr
<DataElement
> element(new DataElement());
31 element
->SetToFilePathRange(file_path
, offset
, length
,
32 expected_modification_time
);
34 new BlobDataItem(element
.Pass(), ShareableFileReference::Get(file_path
)));
37 void BlobDataBuilder::AppendBlob(const std::string
& uuid
,
40 DCHECK_GT(length
, 0ul);
41 scoped_ptr
<DataElement
> element(new DataElement());
42 element
->SetToBlobRange(uuid
, offset
, length
);
43 items_
.push_back(new BlobDataItem(element
.Pass()));
46 void BlobDataBuilder::AppendBlob(const std::string
& uuid
) {
47 scoped_ptr
<DataElement
> element(new DataElement());
48 element
->SetToBlob(uuid
);
49 items_
.push_back(new BlobDataItem(element
.Pass()));
52 void BlobDataBuilder::AppendFileSystemFile(
56 const base::Time
& expected_modification_time
) {
58 scoped_ptr
<DataElement
> element(new DataElement());
59 element
->SetToFileSystemUrlRange(url
, offset
, length
,
60 expected_modification_time
);
61 items_
.push_back(new BlobDataItem(element
.Pass()));
64 void BlobDataBuilder::AppendDiskCacheEntry(
65 const scoped_refptr
<DataHandle
>& data_handle
,
66 disk_cache::Entry
* disk_cache_entry
,
67 int disk_cache_stream_index
) {
68 scoped_ptr
<DataElement
> element(new DataElement());
69 element
->SetToDiskCacheEntryRange(
70 0U, disk_cache_entry
->GetDataSize(disk_cache_stream_index
));
72 new BlobDataItem(element
.Pass(), data_handle
, disk_cache_entry
,
73 disk_cache_stream_index
));
76 } // namespace storage