| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 CHROME_BROWSER_RENDERER_HOST_SOCKET_STREAM_DISPATCHER_HOST_H_ | 5 #ifndef CHROME_BROWSER_RENDERER_HOST_SOCKET_STREAM_DISPATCHER_HOST_H_ |
| 6 #define CHROME_BROWSER_RENDERER_HOST_SOCKET_STREAM_DISPATCHER_HOST_H_ | 6 #define CHROME_BROWSER_RENDERER_HOST_SOCKET_STREAM_DISPATCHER_HOST_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/id_map.h" | 11 #include "base/id_map.h" |
| 12 #include "chrome/browser/renderer_host/resource_dispatcher_host.h" | 12 #include "chrome/browser/browser_message_filter.h" |
| 13 #include "ipc/ipc_message.h" | |
| 14 #include "net/socket_stream/socket_stream.h" | 13 #include "net/socket_stream/socket_stream.h" |
| 15 | 14 |
| 16 class GURL; | 15 class GURL; |
| 17 class SocketStreamHost; | 16 class SocketStreamHost; |
| 18 | 17 |
| 19 // Dispatches ViewHostMsg_SocketStream_* messages sent from renderer. | 18 // Dispatches ViewHostMsg_SocketStream_* messages sent from renderer. |
| 20 // It also acts as SocketStream::Delegate so that it sends | 19 // It also acts as SocketStream::Delegate so that it sends |
| 21 // ViewMsg_SocketStream_* messages back to renderer. | 20 // ViewMsg_SocketStream_* messages back to renderer. |
| 22 class SocketStreamDispatcherHost : public net::SocketStream::Delegate { | 21 class SocketStreamDispatcherHost : public BrowserMessageFilter, |
| 22 public net::SocketStream::Delegate { |
| 23 public: | 23 public: |
| 24 SocketStreamDispatcherHost(); | 24 SocketStreamDispatcherHost(); |
| 25 virtual ~SocketStreamDispatcherHost(); | 25 virtual ~SocketStreamDispatcherHost(); |
| 26 | 26 |
| 27 bool OnMessageReceived(const IPC::Message& msg, | 27 // BrowserMessageFilter methods. |
| 28 ResourceDispatcherHost::Receiver* receiver, | 28 virtual bool OnMessageReceived(const IPC::Message& message, |
| 29 bool* msg_ok); | 29 bool* message_was_ok); |
| 30 |
| 30 // The object died, so cancel and detach all requests associated with it. | 31 // The object died, so cancel and detach all requests associated with it. |
| 31 void CancelRequestsForProcess(int host_id); | 32 void CancelRequestsForProcess(int host_id); |
| 32 | 33 |
| 33 // SocketStream::Delegate methods. | 34 // SocketStream::Delegate methods. |
| 34 virtual void OnConnected(net::SocketStream* socket, | 35 virtual void OnConnected(net::SocketStream* socket, |
| 35 int max_pending_send_allowed); | 36 int max_pending_send_allowed); |
| 36 virtual void OnSentData(net::SocketStream* socket, int amount_sent); | 37 virtual void OnSentData(net::SocketStream* socket, int amount_sent); |
| 37 virtual void OnReceivedData(net::SocketStream* socket, | 38 virtual void OnReceivedData(net::SocketStream* socket, |
| 38 const char* data, int len); | 39 const char* data, int len); |
| 39 virtual void OnClose(net::SocketStream* socket); | 40 virtual void OnClose(net::SocketStream* socket); |
| 40 | 41 |
| 41 private: | 42 private: |
| 42 // Message handlers called by OnMessageReceived. | 43 // Message handlers called by OnMessageReceived. |
| 43 void OnConnect(const GURL& url, int socket_id); | 44 void OnConnect(const GURL& url, int socket_id); |
| 44 void OnSendData(int socket_id, const std::vector<char>& data); | 45 void OnSendData(int socket_id, const std::vector<char>& data); |
| 45 void OnCloseReq(int socket_id); | 46 void OnCloseReq(int socket_id); |
| 46 | 47 |
| 47 void DeleteSocketStreamHost(int host_id, int socket_id); | 48 void DeleteSocketStreamHost(int socket_id); |
| 48 | 49 |
| 49 void AddHostMap(int host_id, int socket_id, | 50 IDMap<SocketStreamHost> hosts_; |
| 50 SocketStreamHost* socket_stream_host); | |
| 51 SocketStreamHost* LookupHostMap(int host_id, int socket_id); | |
| 52 | |
| 53 // Returns true if the message passed in is a SocketStream related message. | |
| 54 static bool IsSocketStreamDispatcherHostMessage(const IPC::Message& message); | |
| 55 | |
| 56 // key: host_id -> { key: socket_id -> value: SocketStreamHost } | |
| 57 IDMap< IDMap<SocketStreamHost> > hostmap_; | |
| 58 | |
| 59 // valid while OnMessageReceived processing. | |
| 60 ResourceDispatcherHost::Receiver* receiver_; | |
| 61 | 51 |
| 62 DISALLOW_COPY_AND_ASSIGN(SocketStreamDispatcherHost); | 52 DISALLOW_COPY_AND_ASSIGN(SocketStreamDispatcherHost); |
| 63 }; | 53 }; |
| 64 | 54 |
| 65 #endif // CHROME_BROWSER_RENDERER_HOST_SOCKET_STREAM_DISPATCHER_HOST_H_ | 55 #endif // CHROME_BROWSER_RENDERER_HOST_SOCKET_STREAM_DISPATCHER_HOST_H_ |
| OLD | NEW |