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