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 STORAGE_BROWSER_BLOB_BLOB_ASYNC_TRANSPORT_STRATEGY_H_ | |
| 6 #define STORAGE_BROWSER_BLOB_BLOB_ASYNC_TRANSPORT_STRATEGY_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/macros.h" | |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "storage/browser/blob/blob_data_builder.h" | |
| 14 #include "storage/browser/storage_browser_export.h" | |
| 15 #include "storage/common/blob_storage/blob_item_bytes_request.h" | |
| 16 #include "storage/common/data_element.h" | |
| 17 | |
| 18 namespace storage { | |
| 19 | |
| 20 // This class computes and stores the strategy for asynchronously transporting | |
| 21 // memory from the renderer to the browser. We take memory constraints of our | |
| 22 // system and the description of a blob, and figure out: | |
| 23 // 1) How to store the blob data in the browser process: in memory or on disk. | |
| 24 // 2) How to transport the data from the renderer: ipc payload, shared memory, | |
| 25 // or file handles. | |
| 26 // We then generate data requests for that blob's memory and seed a | |
| 27 // BlobDataBuilder for storing that data. | |
| 28 // | |
| 29 // Note: This class does not compute requests by using the 'shortcut' method, | |
| 30 // where the data is already present in the blob description, and will | |
| 31 // always give the caller the full strategy for requesting all data from | |
| 32 // the renderer. | |
| 33 class STORAGE_EXPORT BlobAsyncTransportStrategy { | |
| 34 public: | |
| 35 enum Error { | |
| 36 ERROR_NONE = 0, | |
| 37 ERROR_TOO_LARGE, // This item can't fit in disk or memory | |
| 38 ERROR_INVALID_PARAMS | |
| 39 }; | |
| 40 | |
| 41 struct RendererMemoryItemRequest { | |
| 42 RendererMemoryItemRequest(); | |
| 43 // This is the index of the item in the builder on the browser side. | |
| 44 size_t browser_item_index; | |
| 45 // Note: For files this offset should always be 0, as the file offset in | |
| 46 // segmentation is handled by the handle_offset in the message. This | |
| 47 // offset is used for populating a chunk when the data comes back to | |
| 48 // the browser. | |
| 49 size_t browser_item_offset; | |
| 50 BlobItemBytesRequest message; | |
| 51 bool received; | |
| 52 }; | |
| 53 | |
| 54 BlobAsyncTransportStrategy(); | |
| 55 virtual ~BlobAsyncTransportStrategy(); | |
| 56 | |
| 57 // This call does the computation to create the requests and builder for the | |
| 58 // blob given the memory constraints and blob description. |memory_available| | |
| 59 // is the total amount of memory we can offer for storing blobs. | |
| 60 // This method can only be called once. | |
| 61 void Initialize(size_t max_ipc_memory_size, | |
| 62 size_t max_shared_memory_size, | |
| 63 uint64_t max_file_size, | |
| 64 uint64_t disk_space_left, | |
| 65 size_t memory_available, | |
| 66 const std::string& uuid, | |
| 67 const std::vector<DataElement>& blob_item_infos); | |
| 68 | |
| 69 // The sizes of the file handles being used (by handle index) in the async | |
| 70 // operation. | |
| 71 const std::vector<uint64_t>& file_handle_sizes() const { | |
| 72 return file_handle_sizes_; | |
| 73 } | |
| 74 | |
| 75 // The sizes of the shared memory handles being used (by handle index) in the | |
| 76 // async operation. | |
| 77 const std::vector<size_t>& shared_memory_handle_sizes() const { | |
| 78 return shared_memory_handle_sizes_; | |
| 79 } | |
| 80 | |
| 81 // The requests for memory, segmented as described above, along with their | |
| 82 // destination browser indexes and offsets. | |
| 83 const std::vector<RendererMemoryItemRequest>& requests() const { | |
| 84 return requests_; | |
| 85 } | |
| 86 | |
| 87 // Marks the request at the given request number as recieved. | |
| 88 void MarkRequestAsReceived(size_t request_num) { | |
| 89 DCHECK_LT(request_num, requests_.size()); | |
| 90 requests_[request_num].received = true; | |
| 91 } | |
| 92 | |
| 93 // A BlobDataBuilder which can be used to construct the Blob in the | |
| 94 // BlobStorageContext object after: | |
| 95 // * The bytes items from AppendFutureData are populated by | |
| 96 // PopulateFutureData. | |
| 97 // * The temporary files from AppendFutureFile are populated by | |
| 98 // PopulateFutureFile. | |
| 99 BlobDataBuilder* blob_builder() { return builder_.get(); } | |
| 100 | |
| 101 // The total bytes size of memory items in the blob. | |
| 102 uint64_t total_bytes_size() const { return total_bytes_size_; } | |
| 103 | |
| 104 Error error() const { return error_; } | |
| 105 | |
| 106 static bool ShouldBeShortcut(const std::vector<DataElement>& items, | |
| 107 size_t memory_available); | |
| 108 | |
| 109 private: | |
| 110 template <typename SizeType> | |
| 111 static void ComputeHandleSizes(SizeType total_memory_size, | |
| 112 SizeType max_segment_size, | |
| 113 std::vector<SizeType>* segment_sizes); | |
| 114 | |
| 115 Error error_; | |
| 116 | |
| 117 std::vector<uint64_t> file_handle_sizes_; | |
|
michaeln
2015/11/25 23:34:54
Might be more trouble than its worth to have the t
dmurph
2015/11/26 00:37:07
I don't see why we need to add that restriction, i
michaeln
2015/11/30 21:07:26
Since the source of the data for these files is bl
dmurph
2015/11/30 21:33:28
It was a joke about Bill Gates haha.
I was thinki
michaeln
2015/11/30 21:57:19
I guess its true that crazy api usage can describe
| |
| 118 std::vector<size_t> shared_memory_handle_sizes_; | |
| 119 | |
| 120 uint64_t total_bytes_size_; | |
| 121 std::vector<RendererMemoryItemRequest> requests_; | |
| 122 scoped_ptr<BlobDataBuilder> builder_; | |
| 123 | |
| 124 DISALLOW_COPY_AND_ASSIGN(BlobAsyncTransportStrategy); | |
| 125 }; | |
| 126 | |
| 127 } // namespace storage | |
| 128 | |
| 129 #endif // STORAGE_BROWSER_BLOB_BLOB_ASYNC_TRANSPORT_STRATEGY_H_ | |
| OLD | NEW |