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

Side by Side Diff: content/child/blob_storage/blob_transport_controller.h

Issue 1292523002: [BlobAsync] Patch 3: Renderer Classes & Logic (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@async2
Patch Set: comments Created 5 years, 2 months 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
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 CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_
6 #define CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/gtest_prod_util.h"
13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/shared_memory_handle.h"
17 #include "content/common/content_export.h"
18 #include "ipc/ipc_platform_file.h"
19 #include "storage/common/blob_storage/blob_storage_constants.h"
20
21 namespace base {
22 template <typename T>
23 struct DefaultLazyInstanceTraits;
24 }
25
26 namespace storage {
27 class DataElement;
28 struct BlobItemBytesRequest;
29 struct BlobItemBytesResponse;
30 }
31
32 namespace IPC {
33 class Sender;
34 }
35
36 namespace content {
37
38 class BlobConsolidation;
39
40 // This class is used to manage all the asynchronous transporation of blobs from
41 // the Renderer to the Browser process, where it's handling the Renderer side.
42 // The function of this class is to:
43 // * Be a lazy singleton,
44 // * hold all of the blob data that is being transported to the Browser process,
45 // * create the blob item 'descriptions' for the browser,
46 // * include shortcut data in the descriptions,
47 // * generate responses to blob memory requests, and
48 // * send IPC responses.
49 // Must be used on the IO thread.
50 class CONTENT_EXPORT BlobTransportController {
51 public:
52 static BlobTransportController* GetInstance();
53
54 // This kicks off a blob transfer to the browser thread, which involves
55 // sending an IPC message and storing the blob consolidation object.
56 void InitiateBlobTransfer(const std::string& uuid,
57 const std::string& type,
58 scoped_ptr<BlobConsolidation> consolidation,
59 IPC::Sender* sender);
60
61 // This responds to the request using the sender.
62 void OnMemoryRequest(
63 const std::string& uuid,
64 const std::vector<storage::BlobItemBytesRequest>& requests,
65 std::vector<base::SharedMemoryHandle>* memory_handles,
66 const std::vector<IPC::PlatformFileForTransit>& file_handles,
67 IPC::Sender* sender);
68
69 void OnCancel(const std::string& uuid,
70 storage::IPCBlobCreationCancelCode code);
71
72 void OnDone(const std::string& uuid);
73
74 // Clears all internal state for testing and such.
75 void Clear();
76
77 ~BlobTransportController();
78
79 private:
80 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Descriptions);
81 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Responses);
82 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, SharedMemory);
83 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, ResponsesErrors);
84
85 enum class ResponsesStatus {
86 BLOB_NOT_FOUND,
87 INVALID_ITEM_INDEX,
88 INVALID_DATA_RANGE,
89 INVALID_ITEM,
90 INVALID_HANDLE_INDEX,
91 SHARED_MEMORY_MAP_FAILED,
92 SUCCESS
93 };
94 friend struct base::DefaultLazyInstanceTraits<BlobTransportController>;
95
96 BlobTransportController();
97
98 // Sends the IPC to cancel the blob transfer, and releases the blob from
99 // internal storage.
100 void CancelBlobTransfer(const std::string& uuid,
101 storage::IPCBlobCreationCancelCode code,
102 IPC::Sender* sender);
103
104 // Gives the blob data to this class to hold.
105 // Returns false if there already exists a blob with that uuid. If that is
106 // the case, then the consolidation is destroyed.
107 bool HoldBlobConsolidation(const std::string& uuid,
108 scoped_ptr<BlobConsolidation> consolidation);
109
110 void GetDescriptions(const std::string& uuid,
111 size_t max_data_population,
112 std::vector<storage::DataElement>* out);
113
114 ResponsesStatus GetResponses(
115 const std::string& uuid,
116 const std::vector<storage::BlobItemBytesRequest>& requests,
117 std::vector<base::SharedMemoryHandle>* memory_handles,
118 const std::vector<IPC::PlatformFileForTransit>& file_handles,
119 std::vector<storage::BlobItemBytesResponse>* output);
120
121 void ReleaseBlobConsolidation(const std::string& uuid);
122
123 BlobConsolidation* GetConsolidation(const std::string& uuid);
124
125 std::map<std::string, BlobConsolidation*> blob_storage_;
kinuko 2015/10/26 06:44:22 nit: can we have a comment to note that this owns
kinuko 2015/10/26 06:44:22 Well, or maybe use ScopedPtrHashMap.
michaeln 2015/10/26 20:25:48 or ScopedPtrMap
dmurph 2015/10/28 01:00:52 Done.
126
127 DISALLOW_COPY_AND_ASSIGN(BlobTransportController);
128 };
129
130 } // namespace content
131 #endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698