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

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

Issue 1414123002: [BlobAsync] Renderer support for blob file writing. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blob-hookup
Patch Set: linker fix Created 4 years, 8 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
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 CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ 5 #ifndef CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_
6 #define CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ 6 #define CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 9
10 #include <map> 10 #include <map>
11 #include <memory> 11 #include <memory>
12 #include <string> 12 #include <string>
13 #include <utility>
13 #include <vector> 14 #include <vector>
14 15
16 #include "base/callback_forward.h"
15 #include "base/gtest_prod_util.h" 17 #include "base/gtest_prod_util.h"
16 #include "base/macros.h" 18 #include "base/macros.h"
17 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
18 #include "base/memory/shared_memory_handle.h" 20 #include "base/memory/shared_memory_handle.h"
21 #include "base/memory/weak_ptr.h"
19 #include "content/common/content_export.h" 22 #include "content/common/content_export.h"
20 #include "ipc/ipc_platform_file.h" 23 #include "ipc/ipc_platform_file.h"
21 #include "storage/common/blob_storage/blob_storage_constants.h" 24 #include "storage/common/blob_storage/blob_storage_constants.h"
22 25
23 namespace base { 26 namespace base {
24 template <typename T> 27 template <typename T>
25 struct DefaultLazyInstanceTraits; 28 struct DefaultLazyInstanceTraits;
26 class SingleThreadTaskRunner; 29 class SingleThreadTaskRunner;
30 class TaskRunner;
27 } 31 }
28 32
29 namespace storage { 33 namespace storage {
30 class DataElement; 34 class DataElement;
31 struct BlobItemBytesRequest; 35 struct BlobItemBytesRequest;
32 struct BlobItemBytesResponse; 36 struct BlobItemBytesResponse;
33 } 37 }
34 38
35 namespace IPC { 39 namespace IPC {
40 class Message;
36 class Sender; 41 class Sender;
37 } 42 }
38 43
39 namespace content { 44 namespace content {
40 45
41 class BlobConsolidation; 46 class BlobConsolidation;
42 class ThreadSafeSender; 47 class ThreadSafeSender;
43 48
44 // This class is used to manage all the asynchronous transporation of blobs from 49 // This class is used to manage all the asynchronous transporation of blobs from
45 // the Renderer to the Browser process, where it's handling the Renderer side. 50 // the Renderer to the Browser process, where it's handling the Renderer side.
(...skipping 10 matching lines...) Expand all
56 static BlobTransportController* GetInstance(); 61 static BlobTransportController* GetInstance();
57 62
58 // This kicks off a blob transfer to the browser thread, which involves 63 // This kicks off a blob transfer to the browser thread, which involves
59 // sending an IPC message and storing the blob consolidation object. Designed 64 // sending an IPC message and storing the blob consolidation object. Designed
60 // to be called by the main thread or a worker thread. 65 // to be called by the main thread or a worker thread.
61 // This also calls ChildProcess::AddRefProcess to keep our process around 66 // This also calls ChildProcess::AddRefProcess to keep our process around
62 // while we transfer. 67 // while we transfer.
63 static void InitiateBlobTransfer( 68 static void InitiateBlobTransfer(
64 const std::string& uuid, 69 const std::string& uuid,
65 const std::string& content_type, 70 const std::string& content_type,
66 std::unique_ptr<BlobConsolidation> consolidation, 71 scoped_refptr<BlobConsolidation> consolidation,
67 scoped_refptr<ThreadSafeSender> sender, 72 scoped_refptr<ThreadSafeSender> sender,
68 base::SingleThreadTaskRunner* io_runner, 73 base::SingleThreadTaskRunner* io_runner,
69 scoped_refptr<base::SingleThreadTaskRunner> main_runner); 74 scoped_refptr<base::SingleThreadTaskRunner> main_runner);
70 75
71 // This responds to the request using the sender. 76 // This responds to the request using the |sender|. If we need to save files
77 // then we we hold onto the sender to send the (possibly multiple) reponses
78 // asynchronously. Use CancelAllBlobTransfers to stop usage of the |sender|.
72 void OnMemoryRequest( 79 void OnMemoryRequest(
73 const std::string& uuid, 80 const std::string& uuid,
74 const std::vector<storage::BlobItemBytesRequest>& requests, 81 const std::vector<storage::BlobItemBytesRequest>& requests,
75 std::vector<base::SharedMemoryHandle>* memory_handles, 82 std::vector<base::SharedMemoryHandle>* memory_handles,
76 const std::vector<IPC::PlatformFileForTransit>& file_handles, 83 const std::vector<IPC::PlatformFileForTransit>& file_handles,
84 base::TaskRunner* file_runner,
77 IPC::Sender* sender); 85 IPC::Sender* sender);
78 86
79 void OnCancel(const std::string& uuid, 87 void OnCancel(const std::string& uuid,
80 storage::IPCBlobCreationCancelCode code); 88 storage::IPCBlobCreationCancelCode code);
81 89
82 void OnDone(const std::string& uuid); 90 void OnDone(const std::string& uuid);
83 91
84 bool IsTransporting(const std::string& uuid) { 92 bool IsTransporting(const std::string& uuid) {
85 return blob_storage_.find(uuid) != blob_storage_.end(); 93 return blob_storage_.find(uuid) != blob_storage_.end();
86 } 94 }
87 95
96 // Invalidates all asynchronously running memory request handlers and clears
97 // the internal state. If our map wasn't previously empty, then we call
98 // ChildProcess::ReleaseProcess to release our previous reference.
99 void CancelAllBlobTransfers();
100
88 private: 101 private:
102 friend struct base::DefaultLazyInstanceTraits<BlobTransportController>;
89 friend class BlobTransportControllerTest; 103 friend class BlobTransportControllerTest;
90 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Descriptions); 104 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Descriptions);
91 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Responses); 105 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Responses);
92 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, SharedMemory); 106 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, SharedMemory);
107 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Disk);
93 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, ResponsesErrors); 108 FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, ResponsesErrors);
94 109
110 using ResponseCallback = base::Callback<void(
111 const std::vector<storage::BlobItemBytesResponse>& /* responses */)>;
112 using CancelCallback =
113 base::Callback<void(storage::IPCBlobCreationCancelCode /* reason */)>;
michaeln 2016/04/26 22:50:08 these callback tyhpes are no longer needed since t
dmurph 2016/04/27 19:14:04 Done.
114
115 enum class ResponsesStatus {
116 BLOB_NOT_FOUND,
117 SHARED_MEMORY_MAP_FAILED,
118 PENDING_IO,
119 SUCCESS
120 };
121
95 static void GetDescriptions(BlobConsolidation* consolidation, 122 static void GetDescriptions(BlobConsolidation* consolidation,
96 size_t max_data_population, 123 size_t max_data_population,
97 std::vector<storage::DataElement>* out); 124 std::vector<storage::DataElement>* out);
98 125
99 BlobTransportController(); 126 BlobTransportController();
100 ~BlobTransportController(); 127 ~BlobTransportController();
101 128
102 // Clears all internal state. If our map wasn't previously empty, then we call 129 void OnFileWriteComplete(
103 // ChildProcess::ReleaseProcess to release our previous reference. 130 IPC::Sender* sender,
104 void ClearForTesting(); 131 const std::string& uuid,
105 132 const std::pair<std::vector<storage::BlobItemBytesResponse>,
106 enum class ResponsesStatus { 133 storage::IPCBlobCreationCancelCode>& result);
107 BLOB_NOT_FOUND,
108 SHARED_MEMORY_MAP_FAILED,
109 SUCCESS
110 };
111 friend struct base::DefaultLazyInstanceTraits<BlobTransportController>;
112 134
113 void StoreBlobDataForRequests( 135 void StoreBlobDataForRequests(
114 const std::string& uuid, 136 const std::string& uuid,
115 std::unique_ptr<BlobConsolidation> consolidation, 137 scoped_refptr<BlobConsolidation> consolidation,
116 scoped_refptr<base::SingleThreadTaskRunner> main_runner); 138 scoped_refptr<base::SingleThreadTaskRunner> main_runner);
117 139
118 ResponsesStatus GetResponses(
119 const std::string& uuid,
120 const std::vector<storage::BlobItemBytesRequest>& requests,
121 std::vector<base::SharedMemoryHandle>* memory_handles,
122 const std::vector<IPC::PlatformFileForTransit>& file_handles,
123 std::vector<storage::BlobItemBytesResponse>* output);
124
125 // Deletes the consolidation, and if we removed the last consolidation from 140 // Deletes the consolidation, and if we removed the last consolidation from
126 // our map, we call ChildProcess::ReleaseProcess to release our previous 141 // our map, we call ChildProcess::ReleaseProcess to release our previous
127 // reference. 142 // reference.
128 void ReleaseBlobConsolidation(const std::string& uuid); 143 void ReleaseBlobConsolidation(const std::string& uuid);
129 144
130 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_; 145 scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_;
131 std::map<std::string, std::unique_ptr<BlobConsolidation>> blob_storage_; 146 std::map<std::string, scoped_refptr<BlobConsolidation>> blob_storage_;
147 base::WeakPtrFactory<BlobTransportController> ptr_factory_;
michaeln 2016/04/26 22:50:08 nit: this is typically named something like weak_f
dmurph 2016/04/27 19:14:04 done.
132 148
133 DISALLOW_COPY_AND_ASSIGN(BlobTransportController); 149 DISALLOW_COPY_AND_ASSIGN(BlobTransportController);
134 }; 150 };
135 151
136 } // namespace content 152 } // namespace content
137 #endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ 153 #endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698