Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / socket_stream / socket_stream_job.h
blob9fc27d94e6b832c1b017c5696cfe9a8502f296fa
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_
8 #include <string>
10 #include "base/memory/ref_counted.h"
11 #include "net/base/net_export.h"
12 #include "net/socket_stream/socket_stream.h"
14 class GURL;
16 namespace net {
18 class CookieStore;
19 class SSLConfigService;
20 class SSLInfo;
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> {
31 public:
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(
42 const GURL& url,
43 SocketStream::Delegate* delegate,
44 TransportSecurityState* sts,
45 SSLConfigService* ssl,
46 URLRequestContext* context,
47 CookieStore* cookie_store);
49 SocketStreamJob();
50 void InitSocketStream(SocketStream* socket) {
51 socket_ = 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);
68 virtual void Close();
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();
82 protected:
83 friend class WebSocketJobTest;
84 friend class base::RefCountedThreadSafe<SocketStreamJob>;
85 virtual ~SocketStreamJob();
87 scoped_refptr<SocketStream> socket_;
89 DISALLOW_COPY_AND_ASSIGN(SocketStreamJob);
92 } // namespace net
94 #endif // NET_SOCKET_STREAM_SOCKET_STREAM_JOB_H_