Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(197)

Side by Side Diff: storage/browser/blob/blob_async_builder_host.h

Issue 1098853003: [BlobAsync] Patch 4: Browser Classes & Logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comments & documentation Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « storage/browser/BUILD.gn ('k') | storage/browser/blob/blob_async_builder_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/callback.h"
13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/shared_memory_handle.h"
16 #include "ipc/ipc_platform_file.h"
17 #include "storage/browser/blob/blob_async_transport_strategy.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
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 // This method begins the construction of the blob given the descriptions.
42 // After this method is called, the following can happen:
43 // * The done callback is triggered immediately because we can shortcut the
44 // construction.
45 // * The request memory callback is called to request memory from the
46 // renderer. This class waits for calls to OnMemoryResponses to continue.
47 // * The cancel callback is triggered if there is an error.
48 // Note: The builder given to the 'done' callback is destructed immediately
49 // after the callback is run.
50 void BuildBlob(
michaeln 2015/11/17 22:16:46 StartBuildingBlob?
51 const std::string& uuid,
52 const std::string& type,
53 const std::vector<DataElement>& descriptions,
54 size_t memory_available,
55 base::Callback<void(const std::vector<storage::BlobItemBytesRequest>&,
56 const std::vector<base::SharedMemoryHandle>&,
57 const std::vector<IPC::PlatformFileForTransit>&)>
58 request_memory,
59 base::Callback<void(BlobDataBuilder*)> done,
60 base::Callback<void(IPCBlobCreationCancelCode)> cancel);
61
62 // This is called when we have responses from the Renderer to our calls to
63 // the request_memory callback above.
64 void OnMemoryResponses(const std::string& uuid,
65 const std::vector<BlobItemBytesResponse>& responses);
66
67 // This erases the blob building state.
68 void StopBuildingBlob(const std::string& uuid);
69
70 size_t blob_building_count() const { return async_blob_map_.size(); }
71
72 // For testing use only. Must be called before BuildBlobAsync.
73 void SetMemoryConstantsForTesting(size_t max_ipc_memory_size,
74 size_t max_shared_memory_size,
75 uint64_t max_file_size,
76 size_t max_blob_in_memory_size) {
77 max_ipc_memory_size_ = max_ipc_memory_size;
78 max_shared_memory_size_ = max_shared_memory_size;
79 max_file_size_ = max_file_size;
80 max_blob_in_memory_size_ = max_blob_in_memory_size;
81 }
82
83 private:
84 struct BlobBuildingState {
85 BlobBuildingState();
86 ~BlobBuildingState();
87
88 std::string type;
89 BlobAsyncTransportStrategy transport_strategy;
90 size_t next_request;
91 size_t num_fulfilled_requests;
92 scoped_ptr<base::SharedMemory> shared_memory_block;
93 // This is the number of requests that have been sent to populate the above
94 // shared data. We won't ask for more data in shared memory until all
95 // requests have been responded to.
96 size_t num_shared_memory_requests;
97 // Only relevant if num_shared_memory_requests is > 0
98 size_t current_shared_memory_handle_index;
99
100 base::Callback<void(const std::vector<storage::BlobItemBytesRequest>&,
101 const std::vector<base::SharedMemoryHandle>&,
102 const std::vector<IPC::PlatformFileForTransit>&)>
103 request_memory;
104 base::Callback<void(BlobDataBuilder*)> done;
105 base::Callback<void(IPCBlobCreationCancelCode)> cancel;
106 };
107
108 typedef std::map<std::string, BlobBuildingState*> AsyncBlobMap;
109
110 // This is the 'main loop' of our memory requests to the renderer.
111 void ContinueBlobMemoryRequests(const std::string& uuid);
112
113 void CancelAndCleanup(const std::string& uuid,
114 IPCBlobCreationCancelCode code);
115 void DoneAndCleanup(const std::string& uuid);
116
117 AsyncBlobMap async_blob_map_;
118
119 // Here for testing.
120 size_t max_ipc_memory_size_ = kBlobStorageIPCThresholdBytes;
121 size_t max_shared_memory_size_ = kBlobStorageMaxSharedMemoryBytes;
122 uint64_t max_file_size_ = kBlobStorageMaxFileSizeBytes;
123 size_t max_blob_in_memory_size_ = kBlobStorageMaxBlobMemorySize;
124
125 DISALLOW_COPY_AND_ASSIGN(BlobAsyncBuilderHost);
126 };
127
128 } // namespace storage
129 #endif // STORAGE_BROWSER_BLOB_BLOB_ASYNC_BUILDER_HOST_H_
OLDNEW
« no previous file with comments | « storage/browser/BUILD.gn ('k') | storage/browser/blob/blob_async_builder_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698