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