Chromium Code Reviews| Index: content/child/blob_storage/blob_consolidation.h |
| diff --git a/content/child/blob_storage/blob_consolidation.h b/content/child/blob_storage/blob_consolidation.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..80348e28ae6fdfa68776b9b40bbec453b57b0a3b |
| --- /dev/null |
| +++ b/content/child/blob_storage/blob_consolidation.h |
| @@ -0,0 +1,100 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_CHILD_BLOB_STORAGE_BLOB_CONSOLIDATION_H_ |
| +#define CONTENT_CHILD_BLOB_STORAGE_BLOB_CONSOLIDATION_H_ |
| + |
| +#include <string> |
| +#include <vector> |
| + |
| +#include "base/logging.h" |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "content/common/content_export.h" |
| +#include "storage/common/data_element.h" |
| +#include "third_party/WebKit/public/platform/WebBlobData.h" |
| +#include "third_party/WebKit/public/platform/WebString.h" |
| +#include "third_party/WebKit/public/platform/WebThreadSafeData.h" |
| +#include "third_party/WebKit/public/platform/WebURL.h" |
|
michaeln
2015/06/22 23:20:21
ditto only WebThreadSafeData
dmurph
2015/06/24 00:36:17
Done.
|
| + |
| +namespace content { |
| + |
| +// This class facilitates the consolidation of memory items in blobs. No memory |
| +// is copied to store items in this object. Instead, the memory is copied into |
| +// the external char* array given to the ReadMemory method. |
| +// Features: |
| +// * Add_Item methods for building the blob. |
| +// * consolidated_items for getting the consolidated items. This is |
| +// used to describe the blob to the browser. |
| +// * total_memory to get the total memory size of the blob. |
| +// * ReadMemory for reading arbitrary memory from any consolidated item. |
| +// |
| +// NOTE: this class does not to memory accounting or garbage collecting. The |
|
kinuko
2015/06/23 14:11:30
nit: does not to -> does not do?
dmurph
2015/06/24 00:36:17
Done.
|
| +// memory for the blob sticks around until this class is destructed. |
| +class CONTENT_EXPORT BlobConsolidation { |
| + public: |
| + enum class ReadStatus { |
| + ERROR = 0, |
| + ERROR_WRONG_TYPE, |
| + ERROR_OUT_OF_BOUNDS, |
| + DONE |
| + }; |
| + struct ConsolidatedItem { |
| + ConsolidatedItem(); |
| + ConsolidatedItem(storage::DataElement::Type type, uint64_t offset, |
| + uint64_t length); |
| + ~ConsolidatedItem(); |
| + |
| + // Store our own variables instead of a DataElement because we need to |
|
michaeln
2015/06/22 23:20:21
i'd leave this comment out, we're trading off righ
dmurph
2015/06/24 00:36:17
Done.
|
| + // mutate the length property for the data entries. |
| + storage::DataElement::Type type; |
| + uint64_t offset; |
| + uint64_t length; |
| + |
| + base::FilePath path; // For TYPE_FILE. |
| + GURL filesystem_url; // For TYPE_FILE_FILESYSTEM. |
| + double expected_modification_time; // For TYPE_FILE, TYPE_FILE_FILESYSTEM. |
| + std::string blob_uuid; // For TYPE_BLOB. |
| + // Only populated if len(items) > 1. Used for binary search. |
| + // Since the offset of the first item is always 0, we exclude this. |
| + std::vector<size_t> offsets; // For TYPE_BYTES. |
| + std::vector<blink::WebThreadSafeData> data; // For TYPE_BYTES. |
| + }; |
| + |
| + BlobConsolidation(); |
| + ~BlobConsolidation(); |
| + |
| + void AddDataItem(const blink::WebThreadSafeData& data); |
| + void AddFileItem(const base::FilePath& path, uint64_t offset, uint64_t length, |
| + double expected_modification_time); |
|
kinuko
2015/06/23 14:11:30
nit: put each argument on a separate line unless t
dmurph
2015/06/24 00:36:17
Done.
|
| + void AddBlobItem(const std::string& uuid, uint64_t offset, uint64_t length); |
| + void AddFileSystemItem(const GURL& url, uint64_t offset, uint64_t length, |
| + double expected_modification_time); |
| + |
| + // This gets the consolidated items constructed from the WebBlobData. This |
| + // is used to describe the blob to the browser. |
| + const std::vector<ConsolidatedItem>& consolidated_items() const { |
| + return consolidated_items_; |
| + } |
| + |
| + size_t total_memory() const { return total_memory_; } |
| + |
| + // Reads memory from the given item into the given buffer. Returns: |
| + // * ReadStatus::ERROR if the state or arguments are invalid (see error log), |
| + // * ReadStatus::ERROR_WRONG_TYPE if the item at the index isn't memory, |
| + // * ReadStatus::ERROR_OUT_OF_BOUNDS if index, offset, or size are invalid, |
| + // * ReadStatus::DONE if the memory has been successfully read. |
| + ReadStatus ReadMemory(size_t consolidated_item_index, |
| + size_t consolidated_offset, size_t consolidated_size, |
| + void* memory_out); |
|
kinuko
2015/06/23 14:11:30
Please explicitly note that |memory_out| must be n
dmurph
2015/06/24 00:36:17
Done. Michael asked to use void* to simplify the
|
| + |
| + private: |
| + size_t total_memory_; |
| + std::vector<ConsolidatedItem> consolidated_items_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BlobConsolidation); |
| +}; |
| + |
| +} // namespace content |
| +#endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_CONSOLIDATION_H_ |