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

Unified 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: and one more rebase error :/ Created 4 years, 7 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 side-by-side diff with in-line comments
Download patch
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
index c9c62ce55ba69e36a4b5bcd6f7ddcc52c421057e..a0897e7519c52a6a57b49bd04ba0fea7895ef44a 100644
--- a/content/child/blob_storage/blob_transport_controller.h
+++ b/content/child/blob_storage/blob_transport_controller.h
@@ -10,12 +10,15 @@
#include <map>
#include <memory>
#include <string>
+#include <utility>
#include <vector>
+#include "base/callback_forward.h"
#include "base/gtest_prod_util.h"
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/shared_memory_handle.h"
+#include "base/memory/weak_ptr.h"
#include "content/common/content_export.h"
#include "ipc/ipc_platform_file.h"
#include "storage/common/blob_storage/blob_storage_constants.h"
@@ -24,6 +27,7 @@ namespace base {
template <typename T>
struct DefaultLazyInstanceTraits;
class SingleThreadTaskRunner;
+class TaskRunner;
}
namespace storage {
@@ -33,6 +37,7 @@ struct BlobItemBytesResponse;
}
namespace IPC {
+class Message;
class Sender;
}
@@ -50,6 +55,9 @@ class ThreadSafeSender;
// * include shortcut data in the descriptions,
// * generate responses to blob memory requests, and
// * send IPC responses.
+// We try to keep the renderer alive during blob transportation by calling
+// ChildProcess::AddProcessRef and
+// blink::Platform::current()->suddenTerminationChanged.
// Must be used on the IO thread.
class CONTENT_EXPORT BlobTransportController {
public:
@@ -63,17 +71,21 @@ class CONTENT_EXPORT BlobTransportController {
static void InitiateBlobTransfer(
const std::string& uuid,
const std::string& content_type,
- std::unique_ptr<BlobConsolidation> consolidation,
+ scoped_refptr<BlobConsolidation> consolidation,
scoped_refptr<ThreadSafeSender> sender,
base::SingleThreadTaskRunner* io_runner,
scoped_refptr<base::SingleThreadTaskRunner> main_runner);
- // This responds to the request using the sender.
+ // This responds to the request using the |sender|. If we need to save files
+ // then we we hold onto the sender to send the (possibly multiple) reponses
+ // asynchronously. Use CancelAllBlobTransfers to stop usage of the |sender|.
+ // We close the file handles once we're done writing to them.
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,
+ base::TaskRunner* file_runner,
IPC::Sender* sender);
void OnCancel(const std::string& uuid,
@@ -85,13 +97,27 @@ class CONTENT_EXPORT BlobTransportController {
return blob_storage_.find(uuid) != blob_storage_.end();
}
+ // Invalidates all asynchronously running memory request handlers and clears
+ // the internal state. If our map wasn't previously empty, then we call
+ // ChildProcess::ReleaseProcess to release our previous reference.
+ void CancelAllBlobTransfers();
+
private:
+ friend struct base::DefaultLazyInstanceTraits<BlobTransportController>;
friend class BlobTransportControllerTest;
FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Descriptions);
FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Responses);
FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, SharedMemory);
+ FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, Disk);
FRIEND_TEST_ALL_PREFIXES(BlobTransportControllerTest, ResponsesErrors);
+ enum class ResponsesStatus {
+ BLOB_NOT_FOUND,
+ SHARED_MEMORY_MAP_FAILED,
+ PENDING_IO,
+ SUCCESS
+ };
+
static void GetDescriptions(BlobConsolidation* consolidation,
size_t max_data_population,
std::vector<storage::DataElement>* out);
@@ -99,36 +125,23 @@ class CONTENT_EXPORT BlobTransportController {
BlobTransportController();
~BlobTransportController();
- // Clears all internal state. If our map wasn't previously empty, then we call
- // ChildProcess::ReleaseProcess to release our previous reference.
- void ClearForTesting();
-
- enum class ResponsesStatus {
- BLOB_NOT_FOUND,
- SHARED_MEMORY_MAP_FAILED,
- SUCCESS
- };
- friend struct base::DefaultLazyInstanceTraits<BlobTransportController>;
+ void OnFileWriteComplete(
+ IPC::Sender* sender,
+ const std::string& uuid,
+ const std::pair<std::vector<storage::BlobItemBytesResponse>,
+ storage::IPCBlobCreationCancelCode>& result);
void StoreBlobDataForRequests(
const std::string& uuid,
- std::unique_ptr<BlobConsolidation> consolidation,
+ scoped_refptr<BlobConsolidation> consolidation,
scoped_refptr<base::SingleThreadTaskRunner> main_runner);
- 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);
-
- // Deletes the consolidation, and if we removed the last consolidation from
- // our map, we call ChildProcess::ReleaseProcess to release our previous
- // reference.
+ // Deletes the consolidation and calls ChildProcess::ReleaseProcess.
void ReleaseBlobConsolidation(const std::string& uuid);
scoped_refptr<base::SingleThreadTaskRunner> main_thread_runner_;
- std::map<std::string, std::unique_ptr<BlobConsolidation>> blob_storage_;
+ std::map<std::string, scoped_refptr<BlobConsolidation>> blob_storage_;
+ base::WeakPtrFactory<BlobTransportController> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(BlobTransportController);
};
« no previous file with comments | « content/child/blob_storage/blob_message_filter.cc ('k') | content/child/blob_storage/blob_transport_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698