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_BUILDER_HOST_H_ | |
6 #define STORAGE_BROWSER_BLOB_BLOB_ASYNC_BUILDER_HOST_H_ | |
7 | |
8 #include <storage/browser/blob/blob_async_transport_strategy.h> | |
kinuko
2015/11/17 14:51:41
Looking a bit unusual?
Use "" instead of <> and h
dmurph
2015/11/17 20:40:19
Whoops, eclipse artifact.
michaeln
2015/11/17 21:55:28
should this include be listed below?
| |
9 #include <map> | |
10 #include <string> | |
11 #include <vector> | |
12 | |
13 #include "base/callback.h" | |
14 #include "base/macros.h" | |
15 #include "base/memory/ref_counted.h" | |
16 #include "base/memory/shared_memory_handle.h" | |
17 #include "ipc/ipc_platform_file.h" | |
18 #include "storage/browser/blob/blob_data_builder.h" | |
19 #include "storage/browser/storage_browser_export.h" | |
20 #include "storage/common/blob_storage/blob_item_bytes_request.h" | |
21 #include "storage/common/blob_storage/blob_item_bytes_response.h" | |
22 #include "storage/common/blob_storage/blob_storage_constants.h" | |
23 #include "storage/common/data_element.h" | |
24 | |
25 namespace base { | |
26 class SharedMemory; | |
27 } | |
28 | |
29 namespace storage { | |
30 | |
31 // This class holds all blobs that are currently being built asynchronously, and | |
michaeln
2015/11/17 21:55:28
Is the intent to have one-per child process or one
dmurph
2015/11/19 02:06:17
One per child process.
| |
32 // sends memory request, cancel, and done messages through the given callbacks. | |
33 // This also includes handling 'shortcut' logic, where the host will use the | |
34 // initial data in the description instead of requesting for data if we have | |
35 // enough immediate space. | |
36 class STORAGE_EXPORT BlobAsyncBuilderHost { | |
37 public: | |
38 BlobAsyncBuilderHost(); | |
39 virtual ~BlobAsyncBuilderHost(); | |
40 | |
41 // Note: The builder given to the 'done' callback is destructed immediately | |
42 // after the callback is run. | |
43 void BuildBlobAsync( | |
44 const std::string& uuid, | |
45 const std::string& type, | |
46 const std::vector<DataElement>& descriptions, | |
47 size_t memory_available, | |
48 base::Callback<void(const std::vector<storage::BlobItemBytesRequest>&, | |
49 const std::vector<base::SharedMemoryHandle>&, | |
50 const std::vector<IPC::PlatformFileForTransit>&)> | |
51 request_memory, | |
52 base::Callback<void(BlobDataBuilder*)> done, | |
53 base::Callback<void(IPCBlobCreationCancelCode)> cancel); | |
54 | |
55 void OnMemoryResponses(const std::string& uuid, | |
56 const std::vector<BlobItemBytesResponse> responses); | |
kinuko
2015/11/17 14:51:42
const ref
dmurph
2015/11/17 20:40:19
Done.
| |
57 | |
58 // This erases the blob building state. | |
59 void StopBuildingBlob(const std::string& uuid); | |
60 | |
61 size_t blob_building_count() { return async_blob_map_.size(); } | |
kinuko
2015/11/17 14:51:41
nit: could be a const method
dmurph
2015/11/17 20:40:19
Done.
| |
62 | |
63 // For testing use only. Must be called before BuildBlobAsync. | |
64 void SetMemoryConstants(size_t max_ipc_memory_size, | |
kinuko
2015/11/17 14:51:41
nit: add 'ForTesting' for test-only methods (so th
dmurph
2015/11/17 20:40:19
Done.
| |
65 size_t max_shared_memory_size, | |
66 uint64_t max_file_size, | |
67 size_t max_blob_in_memory_size) { | |
68 max_ipc_memory_size_ = max_ipc_memory_size; | |
69 max_shared_memory_size_ = max_shared_memory_size; | |
70 max_file_size_ = max_file_size; | |
71 max_blob_in_memory_size_ = max_blob_in_memory_size; | |
72 } | |
73 | |
74 private: | |
75 struct BlobBuildingState { | |
76 BlobBuildingState(); | |
77 ~BlobBuildingState(); | |
78 | |
79 std::string type; | |
80 BlobAsyncTransportStrategy transport_strategy; | |
81 size_t next_request; | |
82 size_t num_fulfilled_requests; | |
83 scoped_ptr<base::SharedMemory> shared_memory_block; | |
84 // This is the number of requests that have been sent to populate the above | |
85 // shared data. We won't ask for more data in shared memory until all | |
86 // requests have been responded to. | |
87 size_t num_shared_memory_requests; | |
88 // Only relevant if num_shared_memory_requests is > 0 | |
89 size_t current_shared_memory_handle_index; | |
90 | |
91 base::Callback<void(const std::vector<storage::BlobItemBytesRequest>&, | |
92 const std::vector<base::SharedMemoryHandle>&, | |
93 const std::vector<IPC::PlatformFileForTransit>&)> | |
94 request_memory; | |
95 base::Callback<void(IPCBlobCreationCancelCode)> cancel; | |
96 base::Callback<void(BlobDataBuilder*)> done; | |
kinuko
2015/11/17 14:51:41
nit: would be nice if these are in the same order
dmurph
2015/11/17 20:40:19
Done.
| |
97 }; | |
98 | |
99 typedef std::map<std::string, BlobBuildingState*> AsyncBlobMap; | |
100 | |
101 void ContinueBlobMemoryRequests(const std::string& uuid); | |
102 | |
103 void CancelAndCleanup(const std::string& uuid, | |
104 IPCBlobCreationCancelCode code); | |
105 void DoneAndCleanup(const std::string& uuid); | |
106 | |
107 AsyncBlobMap async_blob_map_; | |
108 | |
109 // Here for testing. | |
110 size_t max_ipc_memory_size_; | |
111 size_t max_shared_memory_size_; | |
112 uint64_t max_file_size_; | |
113 size_t max_blob_in_memory_size_; | |
114 | |
115 DISALLOW_COPY_AND_ASSIGN(BlobAsyncBuilderHost); | |
116 }; | |
117 | |
118 } // namespace storage | |
119 #endif // STORAGE_BROWSER_BLOB_BLOB_ASYNC_BUILDER_HOST_H_ | |
OLD | NEW |