| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_SOCKET_STREAM_HOST_H_ | |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_SOCKET_STREAM_HOST_H_ | |
| 7 | |
| 8 #include <vector> | |
| 9 | |
| 10 #include "base/memory/ref_counted.h" | |
| 11 #include "base/memory/weak_ptr.h" | |
| 12 #include "content/browser/ssl/ssl_error_handler.h" | |
| 13 #include "net/socket_stream/socket_stream.h" | |
| 14 | |
| 15 class GURL; | |
| 16 | |
| 17 namespace net { | |
| 18 class SocketStreamJob; | |
| 19 class URLRequestContext; | |
| 20 class SSLInfo; | |
| 21 } // namespace net | |
| 22 | |
| 23 namespace content { | |
| 24 | |
| 25 // Host of SocketStreamHandle. Each SocketStreamHandle will have an unique | |
| 26 // socket_id assigned by SocketStreamHost constructor. If socket id is | |
| 27 // kNoSocketId, there is no SocketStreamHost. Each SocketStreamHost has | |
| 28 // SocketStream to manage bi-directional communication over socket stream. The | |
| 29 // lifetime of an instance of this class is completely controlled by the | |
| 30 // SocketStreamDispatcherHost. | |
| 31 class SocketStreamHost : public SSLErrorHandler::Delegate { | |
| 32 public: | |
| 33 SocketStreamHost(net::SocketStream::Delegate* delegate, | |
| 34 int child_id, | |
| 35 int render_frame_id, | |
| 36 int socket_id); | |
| 37 ~SocketStreamHost() override; | |
| 38 | |
| 39 // Gets socket_id associated with |socket|. | |
| 40 static int SocketIdFromSocketStream(const net::SocketStream* socket); | |
| 41 | |
| 42 int render_frame_id() const { return render_frame_id_; } | |
| 43 int socket_id() const { return socket_id_; } | |
| 44 | |
| 45 // Starts to open connection to |url|. | |
| 46 void Connect(const GURL& url, net::URLRequestContext* request_context); | |
| 47 | |
| 48 // Sends |data| over the socket stream. | |
| 49 // socket stream must be open to send data. | |
| 50 // Returns true if the data is put in transmit buffer in socket stream. | |
| 51 // Returns false otherwise (transmit buffer exceeds limit, or socket | |
| 52 // stream is closed). | |
| 53 bool SendData(const std::vector<char>& data); | |
| 54 | |
| 55 // Closes the socket stream. | |
| 56 void Close(); | |
| 57 | |
| 58 base::WeakPtr<SSLErrorHandler::Delegate> AsSSLErrorHandlerDelegate(); | |
| 59 | |
| 60 // SSLErrorHandler::Delegate methods: | |
| 61 void CancelSSLRequest(int error, const net::SSLInfo* ssl_info) override; | |
| 62 void ContinueSSLRequest() override; | |
| 63 | |
| 64 private: | |
| 65 net::SocketStream::Delegate* delegate_; | |
| 66 int child_id_; | |
| 67 int render_frame_id_; | |
| 68 int socket_id_; | |
| 69 | |
| 70 scoped_refptr<net::SocketStreamJob> job_; | |
| 71 | |
| 72 base::WeakPtrFactory<SocketStreamHost> weak_ptr_factory_; | |
| 73 | |
| 74 DISALLOW_COPY_AND_ASSIGN(SocketStreamHost); | |
| 75 }; | |
| 76 | |
| 77 } // namespace content | |
| 78 | |
| 79 #endif // CONTENT_BROWSER_RENDERER_HOST_SOCKET_STREAM_HOST_H_ | |
| OLD | NEW |