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

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

Issue 1853333003: [BlobAsync] Faster shortcuttin, make renderer controller leaky & alive. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Disabling fast shutdown when transfering blobs 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_ 5 #ifndef CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_ 6 #define CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_
7 7
8 #include <set> 8 #include <set>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback_forward.h"
12 #include "base/files/file.h" 13 #include "base/files/file.h"
13 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
14 #include "base/macros.h" 15 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 16 #include "base/memory/ref_counted.h"
16 #include "base/memory/shared_memory_handle.h" 17 #include "base/memory/shared_memory_handle.h"
17 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
18 #include "content/public/browser/browser_message_filter.h" 19 #include "content/public/browser/browser_message_filter.h"
19 #include "storage/browser/blob/blob_async_builder_host.h" 20 #include "storage/browser/blob/blob_async_builder_host.h"
20 #include "storage/browser/blob/blob_transport_result.h" 21 #include "storage/browser/blob/blob_transport_result.h"
21 #include "storage/common/blob_storage/blob_storage_constants.h" 22 #include "storage/common/blob_storage/blob_storage_constants.h"
(...skipping 10 matching lines...) Expand all
32 struct BlobItemBytesRequest; 33 struct BlobItemBytesRequest;
33 struct BlobItemBytesResponse; 34 struct BlobItemBytesResponse;
34 class BlobStorageContext; 35 class BlobStorageContext;
35 } 36 }
36 37
37 namespace content { 38 namespace content {
38 class ChromeBlobStorageContext; 39 class ChromeBlobStorageContext;
39 40
40 // This class's responsibility is to listen for and dispatch blob storage 41 // 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 // messages and handle logistics of blob storage for a single child process.
43 // It also makes sure the renderer process sticks around while we transfer
44 // blobs.
42 // When the child process terminates all blob references attributable to 45 // When the child process terminates all blob references attributable to
43 // that process go away upon destruction of the instance. 46 // that process go away upon destruction of the instance.
44 // This lives in the browser process, is single threaded (IO thread), and there 47 // This lives in the browser process, is single threaded (IO thread), and there
45 // is one per child process. 48 // is one per child process.
46 class CONTENT_EXPORT BlobDispatcherHost : public BrowserMessageFilter { 49 class CONTENT_EXPORT BlobDispatcherHost : public BrowserMessageFilter {
47 public: 50 public:
48 explicit BlobDispatcherHost(ChromeBlobStorageContext* blob_storage_context); 51 using SetSuddenTerminationAllowedCallback = base::Callback<void(bool)>;
52
53 explicit BlobDispatcherHost(
54 ChromeBlobStorageContext* blob_storage_context,
55 SetSuddenTerminationAllowedCallback set_sudden_termination_allowed);
49 56
50 // BrowserMessageFilter implementation. 57 // BrowserMessageFilter implementation.
51 void OnChannelClosing() override; 58 void OnChannelClosing() override;
52 bool OnMessageReceived(const IPC::Message& message) override; 59 bool OnMessageReceived(const IPC::Message& message) override;
53 60
54 protected: 61 protected:
55 ~BlobDispatcherHost() override; 62 ~BlobDispatcherHost() override;
56 63
57 // For testing use only. 64 // For testing use only.
58 void SetMemoryConstantsForTesting(size_t max_ipc_memory_size, 65 void SetMemoryConstantsForTesting(size_t max_ipc_memory_size,
59 size_t max_shared_memory_size, 66 size_t max_shared_memory_size,
60 uint64_t max_file_size) { 67 uint64_t max_file_size) {
61 async_builder_.SetMemoryConstantsForTesting( 68 async_builder_.SetMemoryConstantsForTesting(
62 max_ipc_memory_size, max_shared_memory_size, max_file_size); 69 max_ipc_memory_size, max_shared_memory_size, max_file_size);
63 } 70 }
64 71
65 private: 72 private:
66 friend class base::RefCountedThreadSafe<BlobDispatcherHost>; 73 friend class base::RefCountedThreadSafe<BlobDispatcherHost>;
67 friend class BlobDispatcherHostTest; 74 friend class BlobDispatcherHostTest;
68 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, EmptyUUIDs); 75 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, EmptyUUIDs);
76 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, MultipleTransfers);
69 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, SharedMemoryTransfer); 77 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, SharedMemoryTransfer);
70 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, OnCancelBuildingBlob); 78 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, OnCancelBuildingBlob);
71 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, 79 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest,
72 BlobReferenceWhileConstructing); 80 BlobReferenceWhileConstructing);
73 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, 81 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest,
74 BlobReferenceWhileShortcutConstructing); 82 BlobReferenceWhileShortcutConstructing);
75 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, 83 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest,
76 BlobReferenceWhileConstructingCancelled); 84 BlobReferenceWhileConstructingCancelled);
77 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, DecrementRefAfterRegister); 85 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, DecrementRefAfterRegister);
78 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, DecrementRefAfterOnStart); 86 FRIEND_TEST_ALL_PREFIXES(BlobDispatcherHostTest, DecrementRefAfterOnStart);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 // Send the appropriate IPC response to the renderer for the given result. 127 // Send the appropriate IPC response to the renderer for the given result.
120 void SendIPCResponse(const std::string& uuid, 128 void SendIPCResponse(const std::string& uuid,
121 storage::BlobTransportResult result); 129 storage::BlobTransportResult result);
122 130
123 bool IsInUseInHost(const std::string& uuid); 131 bool IsInUseInHost(const std::string& uuid);
124 bool IsUrlRegisteredInHost(const GURL& blob_url); 132 bool IsUrlRegisteredInHost(const GURL& blob_url);
125 133
126 // Unregisters all blobs and urls that were registered in this host. 134 // Unregisters all blobs and urls that were registered in this host.
127 void ClearHostFromBlobStorageContext(); 135 void ClearHostFromBlobStorageContext();
128 136
137 void AllowSuddenTerminationIfBuilderEmpty();
138
139 // Calling this should disable or enable sudden renderer termination. We use
140 // this to keep the renderer alive while blobs are being transferred.
141 SetSuddenTerminationAllowedCallback set_sudden_termination_allowed_;
142
129 // Collection of blob ids and a count of how many usages 143 // Collection of blob ids and a count of how many usages
130 // of that id are attributable to this consumer. 144 // of that id are attributable to this consumer.
131 BlobReferenceMap blobs_inuse_map_; 145 BlobReferenceMap blobs_inuse_map_;
132 146
133 // The set of public blob urls coined by this consumer. 147 // The set of public blob urls coined by this consumer.
134 std::set<GURL> public_blob_urls_; 148 std::set<GURL> public_blob_urls_;
135 149
136 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_; 150 scoped_refptr<ChromeBlobStorageContext> blob_storage_context_;
137 storage::BlobAsyncBuilderHost async_builder_; 151 storage::BlobAsyncBuilderHost async_builder_;
138 152
139 DISALLOW_COPY_AND_ASSIGN(BlobDispatcherHost); 153 DISALLOW_COPY_AND_ASSIGN(BlobDispatcherHost);
140 }; 154 };
141 } // namespace content 155 } // namespace content
142 #endif // CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_ 156 #endif // CONTENT_BROWSER_BLOB_STORAGE_BLOB_DISPATCHER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698