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_REQUEST_BUILDER_H_ | 5 #ifndef STORAGE_BROWSER_BLOB_BLOB_TRANSPORT_REQUEST_BUILDER_H_ |
6 #define STORAGE_BROWSER_BLOB_BLOB_ASYNC_TRANSPORT_REQUEST_BUILDER_H_ | 6 #define STORAGE_BROWSER_BLOB_BLOB_TRANSPORT_REQUEST_BUILDER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <memory> | 12 #include <memory> |
13 #include <vector> | 13 #include <vector> |
14 | 14 |
15 #include "base/macros.h" | 15 #include "base/macros.h" |
16 #include "storage/browser/blob/blob_data_builder.h" | 16 #include "storage/browser/blob/blob_data_builder.h" |
17 #include "storage/browser/storage_browser_export.h" | 17 #include "storage/browser/storage_browser_export.h" |
18 #include "storage/common/blob_storage/blob_item_bytes_request.h" | 18 #include "storage/common/blob_storage/blob_item_bytes_request.h" |
19 #include "storage/common/data_element.h" | 19 #include "storage/common/data_element.h" |
20 | 20 |
21 namespace storage { | 21 namespace storage { |
22 | 22 |
23 // This class generates the requests needed to asynchronously transport the | 23 // This class generates the requests needed to asynchronously transport the |
24 // given blob items from the renderer to the browser. The main job of this class | 24 // given blob items from the renderer to the browser. The main job of this class |
25 // is to segment the memory being transfered to efficiently use shared memory, | 25 // is to segment the memory being transfered to efficiently use shared memory, |
26 // file, and IPC max sizes. | 26 // file, and IPC max sizes. |
27 // Note: This class does not compute requests by using the 'shortcut' method, | 27 // Note: This class does not compute requests by using the 'shortcut' method, |
28 // where the data is already present in the blob description, and will | 28 // where the data is already present in the blob description, and will |
29 // always give the caller requests for requesting all data from the | 29 // always give the caller requests for requesting all data from the |
30 // renderer. | 30 // renderer. |
31 class STORAGE_EXPORT BlobAsyncTransportRequestBuilder { | 31 class STORAGE_EXPORT BlobTransportRequestBuilder { |
32 public: | 32 public: |
33 struct RendererMemoryItemRequest { | 33 struct RendererMemoryItemRequest { |
34 RendererMemoryItemRequest(); | 34 RendererMemoryItemRequest(); |
35 // This is the index of the item in the builder on the browser side. | 35 // This is the index of the item in the builder on the browser side. |
36 size_t browser_item_index; | 36 size_t browser_item_index; |
37 // Note: For files this offset should always be 0, as the file offset in | 37 // Note: For files this offset should always be 0, as the file offset in |
38 // segmentation is handled by the handle_offset in the message. This | 38 // segmentation is handled by the handle_offset in the message. This |
39 // offset is used for populating a chunk when the data comes back to | 39 // offset is used for populating a chunk when the data comes back to |
40 // the browser. | 40 // the browser. |
41 size_t browser_item_offset; | 41 size_t browser_item_offset; |
42 BlobItemBytesRequest message; | 42 BlobItemBytesRequest message; |
43 }; | 43 }; |
44 | 44 |
45 BlobAsyncTransportRequestBuilder(); | 45 BlobTransportRequestBuilder(); |
46 virtual ~BlobAsyncTransportRequestBuilder(); | 46 BlobTransportRequestBuilder(BlobTransportRequestBuilder&&); |
| 47 BlobTransportRequestBuilder& operator=(BlobTransportRequestBuilder&&); |
| 48 virtual ~BlobTransportRequestBuilder(); |
47 | 49 |
48 // Initializes the request builder for file requests. One or more files are | 50 // Initializes the request builder for file requests. One or more files are |
49 // created to hold the given data. Each file can hold data from multiple | 51 // created to hold the given data. Each file can hold data from multiple |
50 // items, and the data from each item can be in multiple files. | 52 // items, and the data from each item can be in multiple files. |
51 // See file_handle_sizes() for the generated file sizes. | 53 // See file_handle_sizes() for the generated file sizes. |
52 // max_file_size: This is the maximum size for a file to back a blob. | 54 // max_file_size: This is the maximum size for a file to back a blob. |
53 // blob_total_size: This is the total in-memory size of the blob. | 55 // blob_total_size: This is the total in-memory size of the blob. |
54 // elements: These are the descriptions of the blob items being sent from the | 56 // elements: These are the descriptions of the blob items being sent from the |
55 // renderer. | 57 // renderer. |
56 // builder: This is the builder that is populated with the 'future' versions | 58 // builder: This is the builder that is populated with the 'future' versions |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 109 |
108 // The requests for memory, segmented as described above, along with their | 110 // The requests for memory, segmented as described above, along with their |
109 // destination browser indexes and offsets. | 111 // destination browser indexes and offsets. |
110 const std::vector<RendererMemoryItemRequest>& requests() const { | 112 const std::vector<RendererMemoryItemRequest>& requests() const { |
111 return requests_; | 113 return requests_; |
112 } | 114 } |
113 | 115 |
114 // The total bytes size of memory items in the blob. | 116 // The total bytes size of memory items in the blob. |
115 uint64_t total_bytes_size() const { return total_bytes_size_; } | 117 uint64_t total_bytes_size() const { return total_bytes_size_; } |
116 | 118 |
117 static bool ShouldBeShortcut(const std::vector<DataElement>& items, | |
118 size_t memory_available); | |
119 | |
120 private: | 119 private: |
121 static void ComputeHandleSizes(uint64_t total_memory_size, | 120 static void ComputeHandleSizes(uint64_t total_memory_size, |
122 size_t max_segment_size, | 121 size_t max_segment_size, |
123 std::vector<size_t>* segment_sizes); | 122 std::vector<size_t>* segment_sizes); |
124 | 123 |
125 std::vector<size_t> shared_memory_sizes_; | 124 std::vector<size_t> shared_memory_sizes_; |
126 // The size of the files is capped by the |max_file_size| argument in | 125 // The size of the files is capped by the |max_file_size| argument in |
127 // InitializeForFileRequests, so we can just use size_t. | 126 // InitializeForFileRequests, so we can just use size_t. |
128 std::vector<size_t> file_sizes_; | 127 std::vector<size_t> file_sizes_; |
129 | 128 |
130 uint64_t total_bytes_size_; | 129 uint64_t total_bytes_size_; |
131 std::vector<RendererMemoryItemRequest> requests_; | 130 std::vector<RendererMemoryItemRequest> requests_; |
132 | 131 |
133 DISALLOW_COPY_AND_ASSIGN(BlobAsyncTransportRequestBuilder); | 132 DISALLOW_COPY_AND_ASSIGN(BlobTransportRequestBuilder); |
134 }; | 133 }; |
135 | 134 |
136 } // namespace storage | 135 } // namespace storage |
137 | 136 |
138 #endif // STORAGE_BROWSER_BLOB_BLOB_ASYNC_TRANSPORT_REQUEST_BUILDER_H_ | 137 #endif // STORAGE_BROWSER_BLOB_BLOB_TRANSPORT_REQUEST_BUILDER_H_ |
OLD | NEW |