| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 NET_SOCKET_STREAM_SOCKET_STREAM_JOB_H_ | 5 #ifndef NET_SOCKET_STREAM_SOCKET_STREAM_JOB_H_ |
| 6 #define NET_SOCKET_STREAM_SOCKET_STREAM_JOB_H_ | 6 #define NET_SOCKET_STREAM_SOCKET_STREAM_JOB_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/memory/ref_counted.h" | 10 #include "base/memory/ref_counted.h" |
| 11 #include "net/base/net_export.h" | 11 #include "net/base/net_export.h" |
| 12 #include "net/socket_stream/socket_stream.h" | 12 #include "net/socket_stream/socket_stream.h" |
| 13 | 13 |
| 14 class GURL; | 14 class GURL; |
| 15 | 15 |
| 16 namespace net { | 16 namespace net { |
| 17 | 17 |
| 18 class CookieStore; |
| 18 class SSLConfigService; | 19 class SSLConfigService; |
| 19 class SSLInfo; | 20 class SSLInfo; |
| 20 class TransportSecurityState; | 21 class TransportSecurityState; |
| 21 | 22 |
| 22 // SocketStreamJob represents full-duplex communication over SocketStream. | 23 // SocketStreamJob represents full-duplex communication over SocketStream. |
| 23 // If a protocol (e.g. WebSocket protocol) needs to inspect/modify data | 24 // If a protocol (e.g. WebSocket protocol) needs to inspect/modify data |
| 24 // over SocketStream, you can implement protocol specific job (e.g. | 25 // over SocketStream, you can implement protocol specific job (e.g. |
| 25 // WebSocketJob) to do some work on data over SocketStream. | 26 // WebSocketJob) to do some work on data over SocketStream. |
| 26 // Registers the protocol specific SocketStreamJob by RegisterProtocolFactory | 27 // Registers the protocol specific SocketStreamJob by RegisterProtocolFactory |
| 27 // and call CreateSocketStreamJob to create SocketStreamJob for the URL. | 28 // and call CreateSocketStreamJob to create SocketStreamJob for the URL. |
| 28 class NET_EXPORT SocketStreamJob | 29 class NET_EXPORT SocketStreamJob |
| 29 : public base::RefCountedThreadSafe<SocketStreamJob> { | 30 : public base::RefCountedThreadSafe<SocketStreamJob> { |
| 30 public: | 31 public: |
| 31 // Callback function implemented by protocol handlers to create new jobs. | 32 // Callback function implemented by protocol handlers to create new jobs. |
| 32 typedef SocketStreamJob* (ProtocolFactory)(const GURL& url, | 33 typedef SocketStreamJob* (ProtocolFactory)(const GURL& url, |
| 33 SocketStream::Delegate* delegate); | 34 SocketStream::Delegate* delegate, |
| 35 URLRequestContext* context, |
| 36 CookieStore* cookie_store); |
| 34 | 37 |
| 35 static ProtocolFactory* RegisterProtocolFactory(const std::string& scheme, | 38 static ProtocolFactory* RegisterProtocolFactory(const std::string& scheme, |
| 36 ProtocolFactory* factory); | 39 ProtocolFactory* factory); |
| 37 | 40 |
| 38 static SocketStreamJob* CreateSocketStreamJob( | 41 static SocketStreamJob* CreateSocketStreamJob( |
| 39 const GURL& url, | 42 const GURL& url, |
| 40 SocketStream::Delegate* delegate, | 43 SocketStream::Delegate* delegate, |
| 41 TransportSecurityState* sts, | 44 TransportSecurityState* sts, |
| 42 SSLConfigService* ssl); | 45 SSLConfigService* ssl, |
| 46 URLRequestContext* context, |
| 47 CookieStore* cookie_store); |
| 43 | 48 |
| 44 SocketStreamJob(); | 49 SocketStreamJob(); |
| 45 void InitSocketStream(SocketStream* socket) { | 50 void InitSocketStream(SocketStream* socket) { |
| 46 socket_ = socket; | 51 socket_ = socket; |
| 47 } | 52 } |
| 48 | 53 |
| 49 virtual SocketStream::UserData* GetUserData(const void* key) const; | 54 virtual SocketStream::UserData* GetUserData(const void* key) const; |
| 50 virtual void SetUserData(const void* key, SocketStream::UserData* data); | 55 virtual void SetUserData(const void* key, SocketStream::UserData* data); |
| 51 | 56 |
| 52 URLRequestContext* context() const { | 57 URLRequestContext* context() const { |
| 53 return socket_.get() ? socket_->context() : 0; | 58 return socket_.get() ? socket_->context() : 0; |
| 54 } | 59 } |
| 55 void set_context(URLRequestContext* context) { | 60 CookieStore* cookie_store() const { |
| 56 if (socket_.get()) | 61 return socket_.get() ? socket_->cookie_store() : 0; |
| 57 socket_->set_context(context); | |
| 58 } | 62 } |
| 59 | 63 |
| 60 virtual void Connect(); | 64 virtual void Connect(); |
| 61 | 65 |
| 62 virtual bool SendData(const char* data, int len); | 66 virtual bool SendData(const char* data, int len); |
| 63 | 67 |
| 64 virtual void Close(); | 68 virtual void Close(); |
| 65 | 69 |
| 66 virtual void RestartWithAuth(const AuthCredentials& credentials); | 70 virtual void RestartWithAuth(const AuthCredentials& credentials); |
| 67 | 71 |
| 68 virtual void CancelWithError(int error); | 72 virtual void CancelWithError(int error); |
| 69 | 73 |
| 70 virtual void CancelWithSSLError(const net::SSLInfo& ssl_info); | 74 virtual void CancelWithSSLError(const net::SSLInfo& ssl_info); |
| 71 | 75 |
| 72 virtual void ContinueDespiteError(); | 76 virtual void ContinueDespiteError(); |
| 73 | 77 |
| 74 virtual void DetachDelegate(); | 78 virtual void DetachDelegate(); |
| 75 | 79 |
| 80 virtual void DetachContext(); |
| 81 |
| 76 protected: | 82 protected: |
| 77 friend class WebSocketJobTest; | 83 friend class WebSocketJobTest; |
| 78 friend class base::RefCountedThreadSafe<SocketStreamJob>; | 84 friend class base::RefCountedThreadSafe<SocketStreamJob>; |
| 79 virtual ~SocketStreamJob(); | 85 virtual ~SocketStreamJob(); |
| 80 | 86 |
| 81 scoped_refptr<SocketStream> socket_; | 87 scoped_refptr<SocketStream> socket_; |
| 82 | 88 |
| 83 DISALLOW_COPY_AND_ASSIGN(SocketStreamJob); | 89 DISALLOW_COPY_AND_ASSIGN(SocketStreamJob); |
| 84 }; | 90 }; |
| 85 | 91 |
| 86 } // namespace net | 92 } // namespace net |
| 87 | 93 |
| 88 #endif // NET_SOCKET_STREAM_SOCKET_STREAM_JOB_H_ | 94 #endif // NET_SOCKET_STREAM_SOCKET_STREAM_JOB_H_ |
| OLD | NEW |