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

Side by Side Diff: content/browser/renderer_host/websocket_dispatcher_host.h

Issue 1568523002: Implement content::WebSocketBlobSender (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@websocket_blob_send_ipcs
Patch Set: Rebase. 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_RENDERER_HOST_WEBSOCKET_DISPATCHER_HOST_H_ 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_DISPATCHER_HOST_H_ 6 #define CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_DISPATCHER_HOST_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/compiler_specific.h" 13 #include "base/compiler_specific.h"
14 #include "base/containers/hash_tables.h" 14 #include "base/containers/hash_tables.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/ref_counted.h"
16 #include "base/time/time.h" 17 #include "base/time/time.h"
17 #include "base/timer/timer.h" 18 #include "base/timer/timer.h"
18 #include "content/common/content_export.h" 19 #include "content/common/content_export.h"
19 #include "content/common/websocket.h" 20 #include "content/common/websocket.h"
20 #include "content/public/browser/browser_message_filter.h" 21 #include "content/public/browser/browser_message_filter.h"
21 22
22 namespace net { 23 namespace net {
23 class URLRequestContext; 24 class URLRequestContext;
24 } // namespace net 25 } // namespace net
25 26
27 namespace storage {
28 class BlobStorageContext;
29 }
30
26 namespace content { 31 namespace content {
27 32
33 class ChromeBlobStorageContext;
34 class StoragePartition;
28 struct WebSocketHandshakeRequest; 35 struct WebSocketHandshakeRequest;
29 struct WebSocketHandshakeResponse; 36 struct WebSocketHandshakeResponse;
30 class WebSocketHost; 37 class WebSocketHost;
31 38
32 // Creates a WebSocketHost object for each WebSocket channel, and dispatches 39 // Creates a WebSocketHost object for each WebSocket channel, and dispatches
33 // WebSocketMsg_* messages sent from renderer to the appropriate WebSocketHost. 40 // WebSocketMsg_* messages sent from renderer to the appropriate WebSocketHost.
34 class CONTENT_EXPORT WebSocketDispatcherHost : public BrowserMessageFilter { 41 class CONTENT_EXPORT WebSocketDispatcherHost : public BrowserMessageFilter {
35 public: 42 public:
36 typedef base::Callback<net::URLRequestContext*()> GetRequestContextCallback; 43 typedef base::Callback<net::URLRequestContext*()> GetRequestContextCallback;
37 44
38 // Given a routing_id and delay, WebSocketHostFactory returns a new 45 // Given a routing_id and delay, WebSocketHostFactory returns a new
39 // instance of WebSocketHost or its subclass. 46 // instance of WebSocketHost or its subclass.
40 typedef base::Callback<WebSocketHost*(int, base::TimeDelta)> 47 typedef base::Callback<WebSocketHost*(int, base::TimeDelta)>
41 WebSocketHostFactory; 48 WebSocketHostFactory;
42 49
43 // Return value for methods that may delete the WebSocketHost. This enum is 50 // Return value for methods that may delete the WebSocketHost. This enum is
44 // binary-compatible with net::WebSocketEventInterface::ChannelState, to make 51 // binary-compatible with net::WebSocketEventInterface::ChannelState, to make
45 // conversion cheap. By using a separate enum including net/ header files can 52 // conversion cheap. By using a separate enum including net/ header files can
46 // be avoided. 53 // be avoided.
47 enum WebSocketHostState { 54 enum WebSocketHostState {
48 WEBSOCKET_HOST_ALIVE, 55 WEBSOCKET_HOST_ALIVE,
49 WEBSOCKET_HOST_DELETED 56 WEBSOCKET_HOST_DELETED
50 }; 57 };
51 58
52 WebSocketDispatcherHost( 59 WebSocketDispatcherHost(int process_id,
53 int process_id, 60 const GetRequestContextCallback& get_context_callback,
54 const GetRequestContextCallback& get_context_callback); 61 ChromeBlobStorageContext* blob_storage_context,
62 StoragePartition* storage_partition);
55 63
56 // BrowserMessageFilter: 64 // BrowserMessageFilter:
57 bool OnMessageReceived(const IPC::Message& message) override; 65 bool OnMessageReceived(const IPC::Message& message) override;
58 66
59 // The following methods are used by WebSocketHost::EventInterface to send 67 // The following methods are used by WebSocketHost::EventInterface to send
60 // IPCs from the browser to the renderer or child process. Any of them may 68 // IPCs from the browser to the renderer or child process. Any of them may
61 // return WEBSOCKET_HOST_DELETED and delete the WebSocketHost on failure, 69 // return WEBSOCKET_HOST_DELETED and delete the WebSocketHost on failure,
62 // leading to the WebSocketChannel and EventInterface also being deleted. 70 // leading to the WebSocketChannel and EventInterface also being deleted.
63 71
64 // Sends a WebSocketMsg_AddChannelResponse IPC. 72 // Sends a WebSocketMsg_AddChannelResponse IPC.
(...skipping 24 matching lines...) Expand all
89 WebSocketHostState NotifyFinishOpeningHandshake( 97 WebSocketHostState NotifyFinishOpeningHandshake(
90 int routing_id, 98 int routing_id,
91 const WebSocketHandshakeResponse& response) WARN_UNUSED_RESULT; 99 const WebSocketHandshakeResponse& response) WARN_UNUSED_RESULT;
92 100
93 // Sends a WebSocketMsg_NotifyFailure IPC and deletes and unregisters the 101 // Sends a WebSocketMsg_NotifyFailure IPC and deletes and unregisters the
94 // channel. 102 // channel.
95 WebSocketHostState NotifyFailure( 103 WebSocketHostState NotifyFailure(
96 int routing_id, 104 int routing_id,
97 const std::string& message) WARN_UNUSED_RESULT; 105 const std::string& message) WARN_UNUSED_RESULT;
98 106
107 WebSocketHostState BlobSendComplete(int routing_id);
108
99 // Sends a WebSocketMsg_DropChannel IPC and deletes and unregisters the 109 // Sends a WebSocketMsg_DropChannel IPC and deletes and unregisters the
100 // channel. 110 // channel.
101 WebSocketHostState DoDropChannel(int routing_id, 111 WebSocketHostState DoDropChannel(int routing_id,
102 bool was_clean, 112 bool was_clean,
103 uint16_t code, 113 uint16_t code,
104 const std::string& reason) 114 const std::string& reason)
105 WARN_UNUSED_RESULT; 115 WARN_UNUSED_RESULT;
106 116
107 // Returns whether the associated renderer process can read raw cookies. 117 // Returns whether the associated renderer process can read raw cookies.
108 bool CanReadRawCookies() const; 118 bool CanReadRawCookies() const;
109 119
110 int render_process_id() const { return process_id_; } 120 int render_process_id() const { return process_id_; }
111 121
122 // Returns a BlobStorageContext associated with this object's render process.
123 // The pointer will be valid for as long this object is.
124 storage::BlobStorageContext* blob_storage_context() const;
125
126 // Returns the StoragePartition associated with this render process.
127 StoragePartition* storage_partition() const { return storage_partition_; }
128
112 protected: 129 protected:
113 // For testing. Specify a factory method that creates mock version of 130 // For testing. Specify a factory method that creates mock version of
114 // WebSocketHost. 131 // WebSocketHost.
115 WebSocketDispatcherHost(int process_id, 132 WebSocketDispatcherHost(int process_id,
116 const GetRequestContextCallback& get_context_callback, 133 const GetRequestContextCallback& get_context_callback,
117 const WebSocketHostFactory& websocket_host_factory); 134 const WebSocketHostFactory& websocket_host_factory);
118 135
119 int num_pending_connections() const { return num_pending_connections_; } 136 int num_pending_connections() const { return num_pending_connections_; }
120 137
121 // The number of handshakes that failed/succeeded in the current and 138 // The number of handshakes that failed/succeeded in the current and
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 // The number of handshakes that failed in the current and previous time 191 // The number of handshakes that failed in the current and previous time
175 // period. 192 // period.
176 int64_t num_current_succeeded_connections_; 193 int64_t num_current_succeeded_connections_;
177 int64_t num_previous_succeeded_connections_; 194 int64_t num_previous_succeeded_connections_;
178 195
179 // The number of handshakes that succeeded in the current and previous time 196 // The number of handshakes that succeeded in the current and previous time
180 // period. 197 // period.
181 int64_t num_current_failed_connections_; 198 int64_t num_current_failed_connections_;
182 int64_t num_previous_failed_connections_; 199 int64_t num_previous_failed_connections_;
183 200
201 // Needed to read from blobs for browser-side blob sending.
202 const scoped_refptr<const ChromeBlobStorageContext> blob_storage_context_;
203
204 // Needed to access to the StoragePartition for browser-side blob sending.
205 StoragePartition* const storage_partition_;
206
184 DISALLOW_COPY_AND_ASSIGN(WebSocketDispatcherHost); 207 DISALLOW_COPY_AND_ASSIGN(WebSocketDispatcherHost);
185 }; 208 };
186 209
187 } // namespace content 210 } // namespace content
188 211
189 #endif // CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_DISPATCHER_HOST_H_ 212 #endif // CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_DISPATCHER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698