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

Side by Side Diff: content/browser/blob_storage/blob_dispatcher_host.h

Issue 1234813004: [BlobAsync] Asynchronous Blob Construction Final Patch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@blob-protocol-change
Patch Set: comments/fixes Created 4 years, 10 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_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_
7
8 #include <set>
9 #include <string>
10 #include <vector>
11
12 #include "base/files/file.h"
13 #include "base/gtest_prod_util.h"
14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h"
16 #include "base/memory/shared_memory_handle.h"
17 #include "content/common/content_export.h"
18 #include "content/public/browser/browser_message_filter.h"
19 #include "storage/browser/blob/blob_async_builder_host.h"
20 #include "storage/browser/blob/blob_transport_result.h"
21 #include "storage/common/blob_storage/blob_storage_constants.h"
22
23 class GURL;
24
25 namespace IPC {
26 class Sender;
27 }
28
29 namespace storage {
30 class DataElement;
31 class BlobDataBuilder;
32 struct BlobItemBytesRequest;
33 struct BlobItemBytesResponse;
34 class BlobStorageContext;
35 }
36
37 namespace content {
38 class ChromeBlobStorageContext;
39
40 // This class's responsibility is to listen for and dispatch blob storage
41 // messages and handle logistics of blob storage for a single child process.
42 // When the child process terminates all blob references attributable to
43 // that process go away upon destruction of the instance.
44 // This lives in the browser process, is single threaded (IO thread), and there
45 // is one per child process.
46 class CONTENT_EXPORT BlobDispatcherHost : public BrowserMessageFilter {
47 public:
48 explicit BlobDispatcherHost(ChromeBlobStorageContext* blob_storage_context);
49
50 // BrowserMessageFilter implementation.
51 void OnChannelClosing() override;
52 bool OnMessageReceived(const IPC::Message& message) override;
53
54 protected:
55 ~BlobDispatcherHost() override;
56
57 private:
58 friend class base::RefCountedThreadSafe<BlobDispatcherHost>;
59 friend class BlobDispatcherHostTest;
60 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, EmptyUUIDs);
61 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, OnCancelBuildingBlob);
62 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest,
63 BlobReferenceWhileConstructing);
64 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest,
65 BlobReferenceWhileShortcutConstructing);
66 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest,
67 BlobReferenceWhileConstructingCancelled);
68 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, BlobDestructionEdgeCases);
69
70 typedef std::map<std::string, int> BlobReferenceMap;
71
72 void OnRegisterBlobUUID(const std::string& uuid,
73 const std::string& content_type,
74 const std::string& content_disposition);
75 void OnStartBuildingBlob(
76 const std::string& uuid,
77 const std::vector<storage::DataElement>& descriptions);
78 void OnMemoryItemResponse(
79 const std::string& uuid,
80 const std::vector<storage::BlobItemBytesResponse>& response);
81 void OnCancelBuildingBlob(const std::string& uuid,
82 const storage::IPCBlobCreationCancelCode code);
83
84 void OnIncrementBlobRefCount(const std::string& uuid);
85 void OnDecrementBlobRefCount(const std::string& uuid);
86 void OnRegisterPublicBlobURL(const GURL& public_url, const std::string& uuid);
87 void OnRevokePublicBlobURL(const GURL& public_url);
88
89 storage::BlobStorageContext* context();
90
91 // We split this from OnStartBuildingBlob so we can share the code in the
92 // SendIPCResponse method.
93 storage::BlobTransportResult StartBuildingBlob(
94 const std::string& uuid,
95 const std::vector<storage::DataElement>& descriptions);
96
97 // We split this from OnMemoryItemResponse so we can share the code in the
98 // SendIPCResponse method.
99 storage::BlobTransportResult MemoryItemResponse(
100 const std::string& uuid,
101 const std::vector<storage::BlobItemBytesResponse>& response);
102
103 void SendMemoryRequest(
104 const std::string& uuid,
105 const std::vector<storage::BlobItemBytesRequest>& requests,
106 const std::vector<base::SharedMemoryHandle>& memory_handles,
107 std::vector<base::File>* files);
108
109 // Send the appropriate IPC response to the renderer for the given result.
110 void SendIPCResponse(const std::string& uuid,
111 storage::BlobTransportResult result);
112
113 bool IsInUseInHost(const std::string& uuid);
114 bool IsBeingBuiltInHost(const std::string& uuid);
115 bool IsUrlRegisteredInHost(const GURL& blob_url);
116
117 // Unregisters all blobs and urls that were registered in this host.
118 void ClearHostFromBlobStorageContext();
119
120 // Collection of blob ids and a count of how many usages
121 // of that id are attributable to this consumer.
122 BlobReferenceMap blobs_inuse_map_;
123
124 // The set of public blob urls coined by this consumer.
125 std::set<GURL> public_blob_urls_;
126
127 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_;
128 storage::BlobAsyncBuilderHost async_builder_;
129
130 DISALLOW_COPY_AND_ASSIGN(BlobDispatcherHost);
131 };
132 } // namespace content
133 #endif // CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698