OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2009 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 CHROME_BROWSER_RENDERER_HOST_SOCKET_STREAM_HOST_H_ |
| 6 #define CHROME_BROWSER_RENDERER_HOST_SOCKET_STREAM_HOST_H_ |
| 7 |
| 8 #include <vector> |
| 9 |
| 10 #include "base/ref_counted.h" |
| 11 #include "net/socket_stream/socket_stream.h" |
| 12 |
| 13 class GURL; |
| 14 |
| 15 // Host of SocketStreamHandle. |
| 16 // Each SocketStreamHandle will have an unique socket_id assigned by |
| 17 // SocketStreamHost constructor. If socket id is chrome_common_net::kNoSocketId, |
| 18 // there is no SocketStreamHost. |
| 19 // Each SocketStreamHost has SocketStream to manage bi-directional |
| 20 // communication over socket stream. |
| 21 // The lifetime of an instance of this class is completely controlled by the |
| 22 // SocketStreamDispatcherHost. |
| 23 class SocketStreamHost { |
| 24 public: |
| 25 SocketStreamHost(net::SocketStream::Delegate* delegate, int socket_id); |
| 26 ~SocketStreamHost(); |
| 27 |
| 28 // Gets socket_id associated with |socket|. |
| 29 static int SocketIdFromSocketStream(net::SocketStream* socket); |
| 30 |
| 31 int socket_id() const { return socket_id_; } |
| 32 |
| 33 // Starts to open connection to |url|. |
| 34 void Connect(const GURL& url); |
| 35 |
| 36 // Sends |data| over the socket stream. |
| 37 // socket stream must be open to send data. |
| 38 // Returns true if the data is put in transmit buffer in socket stream. |
| 39 // Returns false otherwise (transmit buffer exceeds limit, or socket |
| 40 // stream is closed). |
| 41 bool SendData(const std::vector<char>& data); |
| 42 |
| 43 // Closes the socket stream. |
| 44 void Close(); |
| 45 |
| 46 private: |
| 47 net::SocketStream::Delegate* delegate_; |
| 48 int socket_id_; |
| 49 |
| 50 scoped_refptr<net::SocketStream> socket_; |
| 51 |
| 52 DISALLOW_COPY_AND_ASSIGN(SocketStreamHost); |
| 53 }; |
| 54 |
| 55 #endif // CHROME_BROWSER_RENDERER_HOST_SOCKET_STREAM_HOST_H_ |
OLD | NEW |