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"
19 class SSLConfigService
;
21 class TransportSecurityState
;
23 // SocketStreamJob represents full-duplex communication over SocketStream.
24 // If a protocol (e.g. WebSocket protocol) needs to inspect/modify data
25 // over SocketStream, you can implement protocol specific job (e.g.
26 // WebSocketJob) to do some work on data over SocketStream.
27 // Registers the protocol specific SocketStreamJob by RegisterProtocolFactory
28 // and call CreateSocketStreamJob to create SocketStreamJob for the URL.
29 class NET_EXPORT SocketStreamJob
30 : public base::RefCountedThreadSafe
<SocketStreamJob
> {
32 // Callback function implemented by protocol handlers to create new jobs.
33 typedef SocketStreamJob
* (ProtocolFactory
)(const GURL
& url
,
34 SocketStream::Delegate
* delegate
,
35 URLRequestContext
* context
,
36 CookieStore
* cookie_store
);
38 static ProtocolFactory
* RegisterProtocolFactory(const std::string
& scheme
,
39 ProtocolFactory
* factory
);
41 static SocketStreamJob
* CreateSocketStreamJob(
43 SocketStream::Delegate
* delegate
,
44 TransportSecurityState
* sts
,
45 SSLConfigService
* ssl
,
46 URLRequestContext
* context
,
47 CookieStore
* cookie_store
);
50 void InitSocketStream(SocketStream
* socket
) {
54 virtual SocketStream::UserData
* GetUserData(const void* key
) const;
55 virtual void SetUserData(const void* key
, SocketStream::UserData
* data
);
57 URLRequestContext
* context() const {
58 return socket_
.get() ? socket_
->context() : 0;
60 CookieStore
* cookie_store() const {
61 return socket_
.get() ? socket_
->cookie_store() : 0;
64 virtual void Connect();
66 virtual bool SendData(const char* data
, int len
);
70 virtual void RestartWithAuth(const AuthCredentials
& credentials
);
72 virtual void CancelWithError(int error
);
74 virtual void CancelWithSSLError(const net::SSLInfo
& ssl_info
);
76 virtual void ContinueDespiteError();
78 virtual void DetachDelegate();
80 virtual void DetachContext();
83 friend class WebSocketJobTest
;
84 friend class base::RefCountedThreadSafe
<SocketStreamJob
>;
85 virtual ~SocketStreamJob();
87 scoped_refptr
<SocketStream
> socket_
;
89 DISALLOW_COPY_AND_ASSIGN(SocketStreamJob
);
94 #endif // NET_SOCKET_STREAM_SOCKET_STREAM_JOB_H_