OLD | NEW |
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_CHILD_WEBSOCKET_DISPATCHER_H_ | 5 #ifndef CONTENT_CHILD_WEBSOCKET_DISPATCHER_H_ |
6 #define CONTENT_CHILD_WEBSOCKET_DISPATCHER_H_ | 6 #define CONTENT_CHILD_WEBSOCKET_DISPATCHER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" |
15 #include "ipc/ipc_listener.h" | 16 #include "ipc/ipc_listener.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 class WebSocketBridge; | 20 class WebSocketBridge; |
20 | 21 |
21 // Dispatches WebSocket related messages sent to a child process from the | 22 // Dispatches WebSocket related messages sent to a child process from the |
22 // main browser process. There is one instance per child process. Messages | 23 // main browser process. There is one instance per child process. Messages |
23 // are dispatched on the main child thread. The ChildThread class | 24 // are dispatched on the main child thread. The ChildThread class |
24 // creates an instance of WebSocketDispatcher and delegates calls to it. | 25 // creates an instance of WebSocketDispatcher and delegates calls to it. |
25 class WebSocketDispatcher : public IPC::Listener { | 26 class WebSocketDispatcher : public IPC::Listener { |
26 public: | 27 public: |
27 WebSocketDispatcher(); | 28 WebSocketDispatcher(); |
28 ~WebSocketDispatcher() override; | 29 ~WebSocketDispatcher() override; |
29 | 30 |
| 31 static bool CanHandleMessage(const IPC::Message& msg); |
| 32 |
30 // Returns a unique channel id | 33 // Returns a unique channel id |
31 int AddBridge(WebSocketBridge* bridge); | 34 int AddBridge(WebSocketBridge* bridge); |
32 void RemoveBridge(int channel_id); | 35 void RemoveBridge(int channel_id); |
33 | 36 |
34 // IPC::Listener implementation. | 37 // IPC::Listener implementation. |
35 bool OnMessageReceived(const IPC::Message& msg) override; | 38 bool OnMessageReceived(const IPC::Message& msg) override; |
36 | 39 |
| 40 base::WeakPtr<WebSocketDispatcher> GetWeakPtr() { |
| 41 return weak_ptr_factory_.GetWeakPtr(); |
| 42 } |
| 43 |
37 private: | 44 private: |
38 WebSocketBridge* GetBridge(int channel_id, uint32_t type); | 45 WebSocketBridge* GetBridge(int channel_id, uint32_t type); |
39 | 46 |
40 std::map<int, WebSocketBridge*> bridges_; | 47 std::map<int, WebSocketBridge*> bridges_; |
41 int channel_id_max_; | 48 int channel_id_max_; |
| 49 base::WeakPtrFactory<WebSocketDispatcher> weak_ptr_factory_; |
42 | 50 |
43 DISALLOW_COPY_AND_ASSIGN(WebSocketDispatcher); | 51 DISALLOW_COPY_AND_ASSIGN(WebSocketDispatcher); |
44 }; | 52 }; |
45 | 53 |
46 } // namespace content | 54 } // namespace content |
47 | 55 |
48 #endif // CONTENT_CHILD_WEBSOCKET_DISPATCHER_H_ | 56 #endif // CONTENT_CHILD_WEBSOCKET_DISPATCHER_H_ |
OLD | NEW |