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

Unified Diff: storage/common/blob/blob_data.cc

Issue 810403004: [Storage] Blob Storage Refactoring pt 1 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Snapshots now created by the Handle, one more rename 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 side-by-side diff with in-line comments
Download patch
« storage/common/blob/blob_data.h ('K') | « storage/common/blob/blob_data.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: storage/common/blob/blob_data.cc
diff --git a/storage/common/blob/blob_data.cc b/storage/common/blob/blob_data.cc
index 23f73e3f0ffcb4c26fc38be3588528e245128886..abbb0bbf979d0d89c070e6ce1cd3a4647e71e788 100644
--- a/storage/common/blob/blob_data.cc
+++ b/storage/common/blob/blob_data.cc
@@ -2,60 +2,121 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "storage/common/blob/blob_data.h"
-
#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
+#include "storage/common/blob/blob_data.h"
namespace storage {
-BlobData::BlobData() {}
-BlobData::BlobData(const std::string& uuid)
- : uuid_(uuid) {
+BlobDataItem::BlobDataItem(scoped_ptr<DataElement> item,
+ scoped_refptr<ShareableFileReference> file_handle)
+ : item_(item.Pass()), file_handle_(file_handle) {
+}
+BlobDataItem::BlobDataItem(scoped_ptr<DataElement> item) : item_(item.Pass()) {
+}
+BlobDataItem::~BlobDataItem() {
}
-BlobData::~BlobData() {}
+BlobDataBuilder::BlobDataBuilder(const std::string& uuid) : uuid_(uuid) {
+}
+BlobDataBuilder::~BlobDataBuilder() {
+}
-void BlobData::AppendData(const char* data, size_t length) {
+void BlobDataBuilder::AppendData(const char* data, size_t length) {
DCHECK(length > 0);
- items_.push_back(Item());
- items_.back().SetToBytes(data, length);
+ scoped_ptr<DataElement> element(new DataElement());
+ element->SetToBytes(data, length);
+ items_.push_back(new BlobDataItem(element.Pass()));
}
-void BlobData::AppendFile(const base::FilePath& file_path,
- uint64 offset, uint64 length,
- const base::Time& expected_modification_time) {
+void BlobDataBuilder::AppendFile(const base::FilePath& file_path,
+ uint64 offset,
+ uint64 length,
+ const base::Time& expected_modification_time) {
DCHECK(length > 0);
- items_.push_back(Item());
- items_.back().SetToFilePathRange(file_path, offset, length,
- expected_modification_time);
+ scoped_ptr<DataElement> element(new DataElement());
+ element->SetToFilePathRange(file_path, offset, length,
+ expected_modification_time);
+ items_.push_back(new BlobDataItem(element.Pass()));
+}
+
+void BlobDataBuilder::AppendFile(
+ const base::FilePath& file_path,
+ uint64 offset,
+ uint64 length,
+ const base::Time& expected_modification_time,
+ scoped_refptr<ShareableFileReference> shareable_file) {
+ DCHECK(length > 0);
+ scoped_ptr<DataElement> element(new DataElement());
+ element->SetToFilePathRange(file_path, offset, length,
+ expected_modification_time);
+ items_.push_back(new BlobDataItem(element.Pass(), shareable_file));
}
-void BlobData::AppendBlob(const std::string& uuid,
- uint64 offset, uint64 length) {
+void BlobDataBuilder::AppendBlob(const std::string& uuid,
+ uint64 offset,
+ uint64 length) {
DCHECK_GT(length, 0ul);
- items_.push_back(Item());
- items_.back().SetToBlobRange(uuid, offset, length);
+ scoped_ptr<DataElement> element(new DataElement());
+ element->SetToBlobRange(uuid, offset, length);
+ items_.push_back(new BlobDataItem(element.Pass()));
}
-void BlobData::AppendFileSystemFile(
- const GURL& url, uint64 offset,
+void BlobDataBuilder::AppendFileSystemFile(
+ const GURL& url,
+ uint64 offset,
uint64 length,
const base::Time& expected_modification_time) {
DCHECK(length > 0);
- items_.push_back(Item());
- items_.back().SetToFileSystemUrlRange(url, offset, length,
- expected_modification_time);
+ scoped_ptr<DataElement> element(new DataElement());
+ element->SetToFileSystemUrlRange(url, offset, length,
+ expected_modification_time);
+ items_.push_back(new BlobDataItem(element.Pass()));
+}
+
+size_t BlobDataBuilder::GetMemoryUsage() const {
+ int64 memory = 0;
+ for (const auto& data_item : items_) {
+ if (data_item->type() == DataElement::TYPE_BYTES)
+ memory += data_item->length();
+ }
+ return memory;
+}
+
+scoped_ptr<BlobDataSnapshot> BlobDataBuilder::Build() {
+ return scoped_ptr<BlobDataSnapshot>(new BlobDataSnapshot(uuid_, content_type_,
+ content_disposition_,
+ items_)).Pass();
+}
+
+BlobDataSnapshot::BlobDataSnapshot(
+ const std::string& uuid,
+ const std::string& content_type,
+ const std::string& content_disposition,
+ const std::vector<scoped_refptr<BlobDataItem>>& items)
+ : uuid_(uuid),
+ content_type_(content_type),
+ content_disposition_(content_disposition),
+ items_(items) {
+}
+
+BlobDataSnapshot::BlobDataSnapshot(const BlobDataSnapshot& other)
+ : uuid_(other.uuid_),
+ content_type_(other.content_type_),
+ content_disposition_(other.content_disposition_),
+ items_(other.items_) {
+}
+
+BlobDataSnapshot::~BlobDataSnapshot() {
}
-int64 BlobData::GetMemoryUsage() const {
+size_t BlobDataSnapshot::GetMemoryUsage() const {
int64 memory = 0;
- for (std::vector<Item>::const_iterator iter = items_.begin();
- iter != items_.end(); ++iter) {
- if (iter->type() == Item::TYPE_BYTES)
- memory += iter->length();
+ for (const auto& data_item : items_) {
+ if (data_item->type() == DataElement::TYPE_BYTES)
+ memory += data_item->length();
}
return memory;
}
« storage/common/blob/blob_data.h ('K') | « storage/common/blob/blob_data.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698