Index: content/child/blob_storage/blob_transport_controller.h |
diff --git a/content/child/blob_storage/blob_transport_controller.h b/content/child/blob_storage/blob_transport_controller.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1766c147831788f477db58d4e791114895610517 |
--- /dev/null |
+++ b/content/child/blob_storage/blob_transport_controller.h |
@@ -0,0 +1,128 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ |
+#define CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ |
+ |
+#include <map> |
+#include <string> |
+#include <vector> |
+ |
+#include "base/gtest_prod_util.h" |
+#include "base/macros.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_ptr.h" |
+#include "base/memory/shared_memory_handle.h" |
+#include "content/common/content_export.h" |
+#include "ipc/ipc_platform_file.h" |
+#include "storage/common/blob_storage/blob_storage_constants.h" |
+ |
+namespace base { |
+template <typename T> |
+struct DefaultLazyInstanceTraits; |
+} |
+ |
+namespace storage { |
+class DataElement; |
+struct BlobItemBytesRequest; |
+struct BlobItemBytesResponse; |
+} |
+ |
+namespace IPC { |
+class Sender; |
+} |
+ |
+namespace content { |
+ |
+class BlobConsolidation; |
+ |
+// This class is used to manage all the asynchronous transporation of blobs from |
+// the Renderer to the Browser process, where it's handling the Renderer side. |
+// This function of this class is to: |
michaeln
2015/10/22 21:12:42
This s/b The
dmurph
2015/10/22 23:43:04
Done.
|
+// * Be a lazy singleton, |
+// * delegate calls to the BlobTransportTemporaryHolder, and |
michaeln
2015/10/22 21:12:42
comment is stale
dmurph
2015/10/22 23:43:04
Fixed.
|
+// * send IPC responses. |
+// Must be used on the IO thread. |
+class CONTENT_EXPORT BlobTransportController { |
michaeln
2015/10/22 21:10:22
thnx for smushing the classes together!
|
+ public: |
+ static BlobTransportController* GetInstance(); |
+ |
+ // This kicks off a blob transfer to the browser thread, which involves |
+ // sending an IPC message and storing the blob consolidation object. |
+ void InitiateBlobTransfer(const std::string& uuid, |
+ const std::string& type, |
+ scoped_ptr<BlobConsolidation> consolidation, |
+ IPC::Sender* sender); |
+ |
+ // This responds to the request using the sender. |
+ void OnMemoryRequest( |
+ const std::string& uuid, |
+ const std::vector<storage::BlobItemBytesRequest>& requests, |
+ std::vector<base::SharedMemoryHandle>* memory_handles, |
+ const std::vector<IPC::PlatformFileForTransit>& file_handles, |
+ IPC::Sender* sender); |
+ |
+ void OnCancel(const std::string& uuid, |
+ storage::IPCBlobCreationCancelCode code); |
+ |
+ void OnDone(const std::string& uuid); |
+ |
+ // Clears all internal state for testing and such. |
+ void Clear(); |
+ |
+ ~BlobTransportController(); |
+ |
+ private: |
+ FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Descriptions); |
+ FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Responses); |
+ FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, SharedMemory); |
+ FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, ResponsesErrors); |
+ |
+ enum class ResponsesStatus { |
+ BLOB_NOT_FOUND, |
+ INVALID_ITEM_INDEX, |
+ INVALID_DATA_RANGE, |
+ INVALID_ITEM, |
+ INVALID_HANDLE_INDEX, |
+ SHARED_MEMORY_MAP_FAILED, |
+ SUCCESS |
+ }; |
+ friend struct base::DefaultLazyInstanceTraits<BlobTransportController>; |
+ |
+ BlobTransportController(); |
+ |
+ // Sends the IPC to cancel the blob transfer, and releases the blob from |
+ // internal storage. |
+ void CancelBlobTransfer(const std::string& uuid, |
+ storage::IPCBlobCreationCancelCode code, |
+ IPC::Sender* sender); |
+ |
+ // Gives the blob data to this class to hold. |
+ // Returns false if there already exists a blob with that uuid. If that is |
+ // the case, then the consolidation is destroyed. |
+ bool HoldBlobConsolidation(const std::string& uuid, |
+ scoped_ptr<BlobConsolidation> consolidation); |
+ |
+ void GetDescriptions(const std::string& uuid, |
+ size_t max_data_population, |
+ std::vector<storage::DataElement>* out); |
+ |
+ ResponsesStatus GetResponses( |
+ const std::string& uuid, |
+ const std::vector<storage::BlobItemBytesRequest>& requests, |
+ std::vector<base::SharedMemoryHandle>* memory_handles, |
+ const std::vector<IPC::PlatformFileForTransit>& file_handles, |
+ std::vector<storage::BlobItemBytesResponse>* output); |
+ |
+ void ReleaseBlob(const std::string& uuid); |
michaeln
2015/10/22 21:10:22
naming nit: Releaseonsolidation to harmonize with
dmurph
2015/10/22 23:43:04
Done.
|
+ |
+ BlobConsolidation* GetConsolidation(const std::string& uuid); |
+ |
+ std::map<std::string, BlobConsolidation*> blob_storage_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(BlobTransportController); |
+}; |
+ |
+} // namespace content |
+#endif // CONTENT_CHILD_BLOB_STORAGE_BLOB_TRANSPORT_CONTROLLER_H_ |