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

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

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 (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.
4
5 #include <storage/browser/blob/blob_data_builder.h>
6 #include "base/time/time.h"
7
8 namespace storage {
9
10 BlobDataBuilder::BlobDataBuilder(const std::string& uuid) : uuid_(uuid) {
11 }
12 BlobDataBuilder::~BlobDataBuilder() {
13 }
14
15 void BlobDataBuilder::AppendData(const char* data, size_t length) {
16 DCHECK(length > 0);
17 scoped_ptr<DataElement> element(new DataElement());
18 element->SetToBytes(data, length);
19 items_.push_back(new BlobDataItem(element.Pass()));
20 }
21
22 void BlobDataBuilder::AppendFile(const base::FilePath& file_path,
23 uint64 offset,
24 uint64 length,
25 const base::Time& expected_modification_time) {
26 DCHECK(length > 0);
27 scoped_ptr<DataElement> element(new DataElement());
28 element->SetToFilePathRange(file_path, offset, length,
29 expected_modification_time);
30 items_.push_back(new BlobDataItem(element.Pass()));
31 }
32
33 void BlobDataBuilder::AppendFile(
34 const base::FilePath& file_path,
35 uint64 offset,
36 uint64 length,
37 const base::Time& expected_modification_time,
38 scoped_refptr<ShareableFileReference> shareable_file) {
39 DCHECK(length > 0);
40 scoped_ptr<DataElement> element(new DataElement());
41 element->SetToFilePathRange(file_path, offset, length,
42 expected_modification_time);
43 items_.push_back(new BlobDataItem(element.Pass(), shareable_file));
44 }
45
46 void BlobDataBuilder::AppendBlob(const std::string& uuid,
47 uint64 offset,
48 uint64 length) {
49 DCHECK_GT(length, 0ul);
50 scoped_ptr<DataElement> element(new DataElement());
51 element->SetToBlobRange(uuid, offset, length);
52 items_.push_back(new BlobDataItem(element.Pass()));
53 }
54
55 void BlobDataBuilder::AppendFileSystemFile(
56 const GURL& url,
57 uint64 offset,
58 uint64 length,
59 const base::Time& expected_modification_time) {
60 DCHECK(length > 0);
61 scoped_ptr<DataElement> element(new DataElement());
62 element->SetToFileSystemUrlRange(url, offset, length,
63 expected_modification_time);
64 items_.push_back(new BlobDataItem(element.Pass()));
65 }
66
67 size_t BlobDataBuilder::GetMemoryUsage() const {
68 int64 memory = 0;
69 for (const auto& data_item : items_) {
70 if (data_item->type() == DataElement::TYPE_BYTES)
71 memory += data_item->length();
72 }
73 return memory;
74 }
75
76 scoped_ptr<BlobDataSnapshot> BlobDataBuilder::BuildSnapshot() {
77 return scoped_ptr<BlobDataSnapshot>(new BlobDataSnapshot(uuid_, content_type_,
78 content_disposition_,
79 items_)).Pass();
80 }
81
82 } // namespace storage
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698