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 NET_SOCKET_STREAM_SOCKET_STREAM_JOB_H_
6 #define NET_SOCKET_STREAM_SOCKET_STREAM_JOB_H_
10 #include "base/memory/ref_counted.h"
11 #include "net/base/net_export.h"
12 #include "net/socket_stream/socket_stream.h"
18 class SSLConfigService
;
20 class TransportSecurityState
;
22 // SocketStreamJob represents full-duplex communication over SocketStream.
23 // If a protocol (e.g. WebSocket protocol) needs to inspect/modify data
24 // over SocketStream, you can implement protocol specific job (e.g.
25 // WebSocketJob) to do some work on data over SocketStream.
26 // Registers the protocol specific SocketStreamJob by RegisterProtocolFactory
27 // and call CreateSocketStreamJob to create SocketStreamJob for the URL.
28 class NET_EXPORT SocketStreamJob
29 : public base::RefCountedThreadSafe
<SocketStreamJob
> {
31 // Callback function implemented by protocol handlers to create new jobs.
32 typedef SocketStreamJob
* (ProtocolFactory
)(const GURL
& url
,
33 SocketStream::Delegate
* delegate
);
35 static ProtocolFactory
* RegisterProtocolFactory(const std::string
& scheme
,
36 ProtocolFactory
* factory
);
38 static SocketStreamJob
* CreateSocketStreamJob(
40 SocketStream::Delegate
* delegate
,
41 TransportSecurityState
* sts
,
42 SSLConfigService
* ssl
);
45 void InitSocketStream(SocketStream
* socket
) {
49 virtual SocketStream::UserData
* GetUserData(const void* key
) const;
50 virtual void SetUserData(const void* key
, SocketStream::UserData
* data
);
52 const URLRequestContext
* context() const {
53 return socket_
->context();
55 void set_context(const URLRequestContext
* context
) {
56 socket_
->set_context(context
);
59 virtual void Connect();
61 virtual bool SendData(const char* data
, int len
);
65 virtual void RestartWithAuth(const AuthCredentials
& credentials
);
67 virtual void CancelWithError(int error
);
69 virtual void CancelWithSSLError(const net::SSLInfo
& ssl_info
);
71 virtual void ContinueDespiteError();
73 virtual void DetachDelegate();
76 friend class WebSocketJobSpdy2Test
;
77 friend class WebSocketJobSpdy3Test
;
78 friend class base::RefCountedThreadSafe
<SocketStreamJob
>;
79 virtual ~SocketStreamJob();
81 scoped_refptr
<SocketStream
> socket_
;
83 DISALLOW_COPY_AND_ASSIGN(SocketStreamJob
);
88 #endif // NET_SOCKET_STREAM_SOCKET_STREAM_JOB_H_