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

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

Issue 26544003: Make net::WebSocketChannel deletion safe and enable new IPCs (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add missing OVERRIDE annotation. Created 7 years, 2 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 <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 10 matching lines...) Expand all
21 namespace content { 21 namespace content {
22 22
23 class WebSocketHost; 23 class WebSocketHost;
24 24
25 // Creates a WebSocketHost object for each WebSocket channel, and dispatches 25 // Creates a WebSocketHost object for each WebSocket channel, and dispatches
26 // WebSocketMsg_* messages sent from renderer to the appropriate WebSocketHost. 26 // WebSocketMsg_* messages sent from renderer to the appropriate WebSocketHost.
27 class WebSocketDispatcherHost : public BrowserMessageFilter { 27 class WebSocketDispatcherHost : public BrowserMessageFilter {
28 public: 28 public:
29 typedef base::Callback<net::URLRequestContext*()> GetRequestContextCallback; 29 typedef base::Callback<net::URLRequestContext*()> GetRequestContextCallback;
30 30
31 // Return value for methods that may delete the WebSocketHost. This enum is
32 // binary-compatible with net::WebSocketEventInterface::ChannelState, to make
33 // conversion cheap. By using a separate enum including net/ header files can
34 // be avoided.
35 enum WebSocketHostState {
36 WEBSOCKET_HOST_ALIVE,
37 WEBSOCKET_HOST_DELETED
38 };
39
31 explicit WebSocketDispatcherHost( 40 explicit WebSocketDispatcherHost(
32 const GetRequestContextCallback& get_context_callback); 41 const GetRequestContextCallback& get_context_callback);
33 42
34 // BrowserMessageFilter: 43 // BrowserMessageFilter:
35 virtual bool OnMessageReceived(const IPC::Message& message, 44 virtual bool OnMessageReceived(const IPC::Message& message,
36 bool* message_was_ok) OVERRIDE; 45 bool* message_was_ok) OVERRIDE;
37 46
38 // The following methods are used by WebSocketHost::EventInterface to send 47 // The following methods are used by WebSocketHost::EventInterface to send
39 // IPCs from the browser to the renderer or child process. Any of them may 48 // IPCs from the browser to the renderer or child process. Any of them may
40 // delete the WebSocketHost on failure, leading to the WebSocketChannel and 49 // return WEBSOCKET_HOST_DELETED and delete the WebSocketHost on failure,
41 // EventInterface also being deleted. 50 // leading to the WebSocketChannel and EventInterface also being deleted.
42 51
43 // Sends a WebSocketMsg_AddChannelResponse IPC, and then deletes and 52 // Sends a WebSocketMsg_AddChannelResponse IPC, and then deletes and
44 // unregisters the WebSocketHost if |fail| is true. 53 // unregisters the WebSocketHost if |fail| is true.
45 void SendAddChannelResponse(int routing_id, 54 WebSocketHostState SendAddChannelResponse(
yhirano 2013/10/10 09:22:27 Should we have WARN_UNUSED_RESULT here?
Adam Rice 2013/10/11 05:42:54 Done.
46 bool fail, 55 int routing_id,
47 const std::string& selected_protocol, 56 bool fail,
48 const std::string& extensions); 57 const std::string& selected_protocol,
58 const std::string& extensions);
49 59
50 // Sends a WebSocketMsg_SendFrame IPC. 60 // Sends a WebSocketMsg_SendFrame IPC.
51 void SendFrame(int routing_id, 61 WebSocketHostState SendFrame(int routing_id,
yhirano 2013/10/10 09:22:27 ditto
Adam Rice 2013/10/11 05:42:54 Done.
52 bool fin, 62 bool fin,
53 WebSocketMessageType type, 63 WebSocketMessageType type,
54 const std::vector<char>& data); 64 const std::vector<char>& data);
55 65
56 // Sends a WebSocketMsg_FlowControl IPC. 66 // Sends a WebSocketMsg_FlowControl IPC.
57 void SendFlowControl(int routing_id, int64 quota); 67 WebSocketHostState SendFlowControl(int routing_id, int64 quota);
yhirano 2013/10/10 09:22:27 ditto
Adam Rice 2013/10/11 05:42:54 Done.
58 68
59 // Sends a WebSocketMsg_SendClosing IPC 69 // Sends a WebSocketMsg_SendClosing IPC
60 void SendClosing(int routing_id); 70 WebSocketHostState SendClosing(int routing_id);
yhirano 2013/10/10 09:22:27 ditto
Adam Rice 2013/10/11 05:42:54 Done.
61 71
62 // Sends a WebSocketMsg_DropChannel IPC and delete and unregister the channel. 72 // Sends a WebSocketMsg_DropChannel IPC and deletes and unregisters the
63 void DoDropChannel(int routing_id, uint16 code, const std::string& reason); 73 // channel.
74 WebSocketHostState DoDropChannel(int routing_id,
yhirano 2013/10/10 09:22:27 ditto
Adam Rice 2013/10/11 05:42:54 Done.
75 uint16 code,
76 const std::string& reason);
64 77
65 private: 78 private:
66 typedef base::hash_map<int, WebSocketHost*> WebSocketHostTable; 79 typedef base::hash_map<int, WebSocketHost*> WebSocketHostTable;
67 80
68 virtual ~WebSocketDispatcherHost(); 81 virtual ~WebSocketDispatcherHost();
69 82
70 // Looks up a WebSocketHost object by |routing_id|. Returns the object if one 83 // Looks up a WebSocketHost object by |routing_id|. Returns the object if one
71 // is found, or NULL otherwise. 84 // is found, or NULL otherwise.
72 WebSocketHost* GetHost(int routing_id) const; 85 WebSocketHost* GetHost(int routing_id) const;
73 86
74 // Sends the passed in IPC::Message via the BrowserMessageFilter::Send() 87 // Sends the passed in IPC::Message via the BrowserMessageFilter::Send()
75 // method. If the Send() fails, logs it and deletes the corresponding 88 // method. If the Send() fails, logs it and deletes the corresponding
76 // WebSocketHost object (the client is probably dead). 89 // WebSocketHost object (the client is probably dead).
77 void SendOrDrop(IPC::Message* message); 90 WebSocketHostState SendOrDrop(IPC::Message* message);
78 91
79 // Deletes the WebSocketHost object associated with the given |routing_id| and 92 // Deletes the WebSocketHost object associated with the given |routing_id| and
80 // removes it from the |hosts_| table. Does nothing if the |routing_id| is 93 // removes it from the |hosts_| table.
81 // unknown, since SendAddChannelResponse() may call this method twice.
82 void DeleteWebSocketHost(int routing_id); 94 void DeleteWebSocketHost(int routing_id);
83 95
84 // Table of WebSocketHost objects, owned by this object, indexed by 96 // Table of WebSocketHost objects, owned by this object, indexed by
85 // routing_id. 97 // routing_id.
86 WebSocketHostTable hosts_; 98 WebSocketHostTable hosts_;
87 99
88 // A callback which returns the appropriate net::URLRequestContext for us to 100 // A callback which returns the appropriate net::URLRequestContext for us to
89 // use. 101 // use.
90 GetRequestContextCallback get_context_callback_; 102 GetRequestContextCallback get_context_callback_;
91 103
92 DISALLOW_COPY_AND_ASSIGN(WebSocketDispatcherHost); 104 DISALLOW_COPY_AND_ASSIGN(WebSocketDispatcherHost);
93 }; 105 };
94 106
95 } // namespace content 107 } // namespace content
96 108
97 #endif // CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_DISPATCHER_HOST_H_ 109 #endif // CONTENT_BROWSER_RENDERER_HOST_WEBSOCKET_DISPATCHER_HOST_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698