1 // Copyright (c) 2012 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.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_SOCKET_STREAM_DISPATCHER_HOST_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_SOCKET_STREAM_DISPATCHER_HOST_H_
10 #include "base/callback_forward.h"
11 #include "base/id_map.h"
12 #include "content/public/browser/browser_message_filter.h"
13 #include "content/public/common/resource_type.h"
14 #include "net/socket_stream/socket_stream.h"
23 class ResourceContext
;
24 class SocketStreamHost
;
26 // Dispatches ViewHostMsg_SocketStream_* messages sent from renderer.
27 // It also acts as SocketStream::Delegate so that it sends
28 // ViewMsg_SocketStream_* messages back to renderer.
29 class SocketStreamDispatcherHost
: public BrowserMessageFilter
,
30 public net::SocketStream::Delegate
{
32 typedef base::Callback
<net::URLRequestContext
*(ResourceType
)>
33 GetRequestContextCallback
;
34 SocketStreamDispatcherHost(
35 int render_process_id
,
36 const GetRequestContextCallback
& request_context_callback
,
37 ResourceContext
* resource_context
);
39 // BrowserMessageFilter:
40 virtual bool OnMessageReceived(const IPC::Message
& message
) OVERRIDE
;
42 // Make this object inactive.
43 // Remove all active SocketStreamHost objects.
46 // SocketStream::Delegate:
47 virtual void OnConnected(net::SocketStream
* socket
,
48 int max_pending_send_allowed
) OVERRIDE
;
49 virtual void OnSentData(net::SocketStream
* socket
, int amount_sent
) OVERRIDE
;
50 virtual void OnReceivedData(net::SocketStream
* socket
,
51 const char* data
, int len
) OVERRIDE
;
52 virtual void OnClose(net::SocketStream
* socket
) OVERRIDE
;
53 virtual void OnError(const net::SocketStream
* socket
, int error
) OVERRIDE
;
54 virtual void OnSSLCertificateError(net::SocketStream
* socket
,
55 const net::SSLInfo
& ssl_info
,
57 virtual bool CanGetCookies(net::SocketStream
* socket
,
58 const GURL
& url
) OVERRIDE
;
59 virtual bool CanSetCookie(net::SocketStream
* request
,
61 const std::string
& cookie_line
,
62 net::CookieOptions
* options
) OVERRIDE
;
65 virtual ~SocketStreamDispatcherHost();
68 // Message handlers called by OnMessageReceived.
69 void OnConnect(int render_frame_id
, const GURL
& url
, int socket_id
);
70 void OnSendData(int socket_id
, const std::vector
<char>& data
);
71 void OnCloseReq(int socket_id
);
73 void DeleteSocketStreamHost(int socket_id
);
75 net::URLRequestContext
* GetURLRequestContext();
77 IDMap
<SocketStreamHost
> hosts_
;
78 int render_process_id_
;
79 GetRequestContextCallback request_context_callback_
;
80 ResourceContext
* resource_context_
;
84 DISALLOW_COPY_AND_ASSIGN(SocketStreamDispatcherHost
);
87 } // namespace content
89 #endif // CONTENT_BROWSER_RENDERER_HOST_SOCKET_STREAM_DISPATCHER_HOST_H_