Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 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 #ifndef CONTENT_CHILD_BLOB_STORAGE_BLOB_CONSOLIDATION_H_ | |
| 6 #define CONTENT_CHILD_BLOB_STORAGE_BLOB_CONSOLIDATION_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/logging.h" | |
| 12 #include "base/macros.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "content/common/content_export.h" | |
| 15 #include "storage/common/data_element.h" | |
| 16 #include "third_party/WebKit/public/platform/WebBlobData.h" | |
| 17 #include "third_party/WebKit/public/platform/WebString.h" | |
| 18 #include "third_party/WebKit/public/platform/WebThreadSafeData.h" | |
| 19 #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.
| |
| 20 | |
| 21 namespace content { | |
| 22 | |
| 23 // This class facilitates the consolidation of memory items in blobs. No memory | |
| 24 // is copied to store items in this object. Instead, the memory is copied into | |
| 25 // the external char* array given to the ReadMemory method. | |
| 26 // Features: | |
| 27 // * Add_Item methods for building the blob. | |
| 28 // * consolidated_items for getting the consolidated items. This is | |
| 29 // used to describe the blob to the browser. | |
| 30 // * total_memory to get the total memory size of the blob. | |
| 31 // * ReadMemory for reading arbitrary memory from any consolidated item. | |
| 32 // | |
| 33 // 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.
| |
| 34 // memory for the blob sticks around until this class is destructed. | |
| 35 class CONTENT_EXPORT BlobConsolidation { | |
| 36 public: | |
| 37 enum class ReadStatus { | |
| 38 ERROR = 0, | |
| 39 ERROR_WRONG_TYPE, | |
| 40 ERROR_OUT_OF_BOUNDS, | |
| 41 DONE | |
| 42 }; | |
| 43 struct ConsolidatedItem { | |
| 44 ConsolidatedItem(); | |
| 45 ConsolidatedItem(storage::DataElement::Type type, uint64_t offset, | |
| 46 uint64_t length); | |
| 47 ~ConsolidatedItem(); | |
| 48 | |
| 49 // 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.
| |
| 50 // mutate the length property for the data entries. | |
| 51 storage::DataElement::Type type; | |
| 52 uint64_t offset; | |
| 53 uint64_t length; | |
| 54 | |
| 55 base::FilePath path; // For TYPE_FILE. | |
| 56 GURL filesystem_url; // For TYPE_FILE_FILESYSTEM. | |
| 57 double expected_modification_time; // For TYPE_FILE, TYPE_FILE_FILESYSTEM. | |
| 58 std::string blob_uuid; // For TYPE_BLOB. | |
| 59 // Only populated if len(items) > 1. Used for binary search. | |
| 60 // Since the offset of the first item is always 0, we exclude this. | |
| 61 std::vector<size_t> offsets; // For TYPE_BYTES. | |
| 62 std::vector<blink::WebThreadSafeData> data; // For TYPE_BYTES. | |
| 63 }; | |
| 64 | |
| 65 BlobConsolidation(); | |
| 66 ~BlobConsolidation(); | |
| 67 | |
| 68 void AddDataItem(const blink::WebThreadSafeData& data); | |
| 69 void AddFileItem(const base::FilePath& path, uint64_t offset, uint64_t length, | |
| 70 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.
| |
| 71 void AddBlobItem(const std::string& uuid, uint64_t offset, uint64_t length); | |
| 72 void AddFileSystemItem(const GURL& url, uint64_t offset, uint64_t length, | |
| 73 double expected_modification_time); | |
| 74 | |
| 75 // This gets the consolidated items constructed from the WebBlobData. This | |
| 76 // is used to describe the blob to the browser. | |
| 77 const std::vector<ConsolidatedItem>& consolidated_items() const { | |
| 78 return consolidated_items_; | |
| 79 } | |
| 80 | |
| 81 size_t total_memory() const { return total_memory_; } | |
| 82 | |
| 83 // Reads memory from the given item into the given buffer. Returns: | |
| 84 // * ReadStatus::ERROR if the state or arguments are invalid (see error log), | |
| 85 // * ReadStatus::ERROR_WRONG_TYPE if the item at the index isn't memory, | |
| 86 // * ReadStatus::ERROR_OUT_OF_BOUNDS if index, offset, or size are invalid, | |
| 87 // * ReadStatus::DONE if the memory has been successfully read. | |
| 88 ReadStatus ReadMemory(size_t consolidated_item_index, | |
| 89 size_t consolidated_offset, size_t consolidated_size, | |
| 90 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
| |
| 91 | |
| 92 private: | |
| 93 size_t total_memory_; | |
| 94 std::vector<ConsolidatedItem> consolidated_items_; | |
| 95 | |
| 96 DISALLOW_COPY_AND_ASSIGN(BlobConsolidation); | |
| 97 }; | |
| 98 | |
| 99 } // namespace content | |
| 100 #endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_CONSOLIDATION_H_ | |
| OLD | NEW |