| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_ASYNC_TRANSPORT_STRATEGY_H_ | 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_ASYNC_TRANSPORT_STRATEGY_H_ |
| 6 #define STORAGE_BROWSER_BLOB_BLOB_ASYNC_TRANSPORT_STRATEGY_H_ | 6 #define STORAGE_BROWSER_BLOB_BLOB_ASYNC_TRANSPORT_STRATEGY_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 struct RendererMemoryItemRequest { | 41 struct RendererMemoryItemRequest { |
| 42 RendererMemoryItemRequest(); | 42 RendererMemoryItemRequest(); |
| 43 // This is the index of the item in the builder on the browser side. | 43 // This is the index of the item in the builder on the browser side. |
| 44 size_t browser_item_index; | 44 size_t browser_item_index; |
| 45 // Note: For files this offset should always be 0, as the file offset in | 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 | 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 | 47 // offset is used for populating a chunk when the data comes back to |
| 48 // the browser. | 48 // the browser. |
| 49 size_t browser_item_offset; | 49 size_t browser_item_offset; |
| 50 BlobItemBytesRequest message; | 50 BlobItemBytesRequest message; |
| 51 bool received; | |
| 52 }; | 51 }; |
| 53 | 52 |
| 54 BlobAsyncTransportStrategy(); | 53 BlobAsyncTransportStrategy(); |
| 55 virtual ~BlobAsyncTransportStrategy(); | 54 virtual ~BlobAsyncTransportStrategy(); |
| 56 | 55 |
| 57 // This call does the computation to create the requests and builder for the | 56 // Initializes the transport strategy for file requests. |
| 58 // blob given the memory constraints and blob description. |memory_available| | 57 void InitializeForFileRequests( |
| 59 // is the total amount of memory we can offer for storing blobs. | 58 size_t max_file_size, |
| 60 // This method can only be called once. | 59 const std::string& uuid, |
| 61 void Initialize(size_t max_ipc_memory_size, | 60 uint64_t blob_total_size, |
| 62 size_t max_shared_memory_size, | 61 const std::vector<DataElement>& blob_item_infos, |
| 63 size_t max_file_size, | 62 BlobDataBuilder* builder); |
| 64 uint64_t disk_space_left, | 63 |
| 65 size_t memory_available, | 64 void InitializeForSharedMemoryRequests( |
| 66 const std::string& uuid, | 65 size_t max_shared_memory_size, |
| 67 const std::vector<DataElement>& blob_item_infos); | 66 const std::string& uuid, |
| 67 uint64_t blob_total_size, |
| 68 const std::vector<DataElement>& blob_item_infos, |
| 69 BlobDataBuilder* builder); |
| 70 |
| 71 void InitializeForIPCTransportation( |
| 72 size_t max_ipc_memory_size, |
| 73 const std::string& uuid, |
| 74 uint64_t blob_total_size, |
| 75 const std::vector<DataElement>& blob_item_infos, |
| 76 BlobDataBuilder* builder); |
| 68 | 77 |
| 69 // The sizes of the handles being used (by handle index) in the async | 78 // The sizes of the handles being used (by handle index) in the async |
| 70 // operation. This is used for both files or shared memory, as their use is | 79 // operation. |
| 71 // mutually exclusive. | 80 const std::vector<size_t>& shared_memory_handle_sizes() const { |
| 72 const std::vector<size_t>& handle_sizes() const { return handle_sizes_; } | 81 return shared_memory_handle_sizes_; |
| 82 } |
| 83 |
| 84 const std::vector<size_t>& file_handle_sizes() const { |
| 85 return file_handle_sizes_; |
| 86 } |
| 73 | 87 |
| 74 // The requests for memory, segmented as described above, along with their | 88 // The requests for memory, segmented as described above, along with their |
| 75 // destination browser indexes and offsets. | 89 // destination browser indexes and offsets. |
| 76 const std::vector<RendererMemoryItemRequest>& requests() const { | 90 const std::vector<RendererMemoryItemRequest>& requests() const { |
| 77 return requests_; | 91 return requests_; |
| 78 } | 92 } |
| 79 | 93 |
| 80 // Marks the request at the given request number as recieved. | |
| 81 void MarkRequestAsReceived(size_t request_num) { | |
| 82 DCHECK_LT(request_num, requests_.size()); | |
| 83 requests_[request_num].received = true; | |
| 84 } | |
| 85 | |
| 86 // A BlobDataBuilder which can be used to construct the Blob in the | |
| 87 // BlobStorageContext object after: | |
| 88 // * The bytes items from AppendFutureData are populated by | |
| 89 // PopulateFutureData. | |
| 90 // * The temporary files from AppendFutureFile are populated by | |
| 91 // PopulateFutureFile. | |
| 92 BlobDataBuilder* blob_builder() { return builder_.get(); } | |
| 93 | |
| 94 // The total bytes size of memory items in the blob. | 94 // The total bytes size of memory items in the blob. |
| 95 uint64_t total_bytes_size() const { return total_bytes_size_; } | 95 uint64_t total_bytes_size() const { return total_bytes_size_; } |
| 96 | 96 |
| 97 Error error() const { return error_; } | 97 Error error() const { return error_; } |
| 98 | 98 |
| 99 static bool ShouldBeShortcut(const std::vector<DataElement>& items, | 99 static bool ShouldBeShortcut(const std::vector<DataElement>& items, |
| 100 size_t memory_available); | 100 size_t memory_available); |
| 101 | 101 |
| 102 private: | 102 private: |
| 103 static void ComputeHandleSizes(uint64_t total_memory_size, | 103 static void ComputeHandleSizes(uint64_t total_memory_size, |
| 104 size_t max_segment_size, | 104 size_t max_segment_size, |
| 105 std::vector<size_t>* segment_sizes); | 105 std::vector<size_t>* segment_sizes); |
| 106 | 106 |
| 107 Error error_; | 107 Error error_; |
| 108 | 108 |
| 109 // We use the same vector for shared memory handle sizes and file handle sizes | 109 // We use the same vector for shared memory handle sizes and file handle sizes |
| 110 // because we only use one for any strategy. The size of the handles is capped | 110 // because we only use one for any strategy. T |
| 111 // by the |max_file_size| argument in Initialize, so we can just use size_t. | 111 std::vector<size_t> shared_memory_handle_sizes_; |
| 112 std::vector<size_t> handle_sizes_; | 112 // The size of the handles is capped by the |max_file_size| argument in |
| 113 // InitializeForFileRequests, so we can just use size_t. |
| 114 std::vector<size_t> file_handle_sizes_; |
| 113 | 115 |
| 114 uint64_t total_bytes_size_; | 116 uint64_t total_bytes_size_; |
| 115 std::vector<RendererMemoryItemRequest> requests_; | 117 std::vector<RendererMemoryItemRequest> requests_; |
| 116 scoped_ptr<BlobDataBuilder> builder_; | |
| 117 | 118 |
| 118 DISALLOW_COPY_AND_ASSIGN(BlobAsyncTransportStrategy); | 119 DISALLOW_COPY_AND_ASSIGN(BlobAsyncTransportStrategy); |
| 119 }; | 120 }; |
| 120 | 121 |
| 121 } // namespace storage | 122 } // namespace storage |
| 122 | 123 |
| 123 #endif // STORAGE_BROWSER_BLOB_BLOB_ASYNC_TRANSPORT_STRATEGY_H_ | 124 #endif // STORAGE_BROWSER_BLOB_BLOB_ASYNC_TRANSPORT_STRATEGY_H_ |
| OLD | NEW |