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