OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_CHILD_WEBSOCKET_DISPATCHER_H_ |
| 6 #define CONTENT_CHILD_WEBSOCKET_DISPATCHER_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 #include <vector> |
| 11 |
| 12 #include "base/basictypes.h" |
| 13 #include "base/compiler_specific.h" |
| 14 #include "content/common/websocket.h" |
| 15 #include "ipc/ipc_listener.h" |
| 16 |
| 17 namespace content { |
| 18 |
| 19 class WebSocketBridge; |
| 20 |
| 21 // Dispatches WebSocket related messages sent to a child process from the |
| 22 // main browser process. There is one instance per child process. Messages |
| 23 // are dispatched on the main child thread. The ChildThread class |
| 24 // creates an instance of WebSocketDispatcher and delegates calls to it. |
| 25 class WebSocketDispatcher : public IPC::Listener { |
| 26 public: |
| 27 WebSocketDispatcher(); |
| 28 virtual ~WebSocketDispatcher(); |
| 29 |
| 30 // Returns a unique channel id |
| 31 int AddBridge(WebSocketBridge* bridge); |
| 32 void RemoveBridge(int channel_id); |
| 33 |
| 34 // IPC::Listener implementation. |
| 35 virtual bool OnMessageReceived(const IPC::Message& msg) OVERRIDE; |
| 36 |
| 37 private: |
| 38 void OnConnected(int channel_id, |
| 39 bool fail, |
| 40 const std::string& selected_protocol, |
| 41 const std::string& extensions); |
| 42 void OnReceivedData(int channel_id, |
| 43 bool fin, |
| 44 WebSocketMessageType type, |
| 45 const std::vector<char>& data); |
| 46 void OnReceivedFlowControl(int channel_id, int64 quota); |
| 47 void OnClosed(int channel_id, unsigned short code, const std::string& reason); |
| 48 |
| 49 WebSocketBridge* GetBridge(int channel_id); |
| 50 |
| 51 std::map<int, WebSocketBridge*> bridges_; |
| 52 int channel_id_max_; |
| 53 |
| 54 DISALLOW_COPY_AND_ASSIGN(WebSocketDispatcher); |
| 55 }; |
| 56 |
| 57 } // namespace content |
| 58 |
| 59 #endif // CONTENT_CHILD_WEBSOCKET_DISPATCHER_H_ |
OLD | NEW |