Upstreaming browser/ui/uikit_ui_util from iOS.
[chromium-blink-merge.git] / storage / browser / blob / blob_data_builder.cc
blob94fb9e50388633ba5bfcff901338603efc5039b6
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"
11 namespace storage {
13 BlobDataBuilder::BlobDataBuilder(const std::string& uuid) : uuid_(uuid) {
15 BlobDataBuilder::~BlobDataBuilder() {
18 void BlobDataBuilder::AppendData(const char* data, size_t length) {
19 if (!length)
20 return;
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,
27 uint64_t offset,
28 uint64_t length,
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);
33 items_.push_back(
34 new BlobDataItem(element.Pass(), ShareableFileReference::Get(file_path)));
37 void BlobDataBuilder::AppendBlob(const std::string& uuid,
38 uint64_t offset,
39 uint64_t length) {
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(
53 const GURL& url,
54 uint64_t offset,
55 uint64_t length,
56 const base::Time& expected_modification_time) {
57 DCHECK(length > 0);
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));
71 items_.push_back(
72 new BlobDataItem(element.Pass(), data_handle, disk_cache_entry,
73 disk_cache_stream_index));
76 } // namespace storage