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 SocketStramHandle 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, |
| 26 int socket_id); |
| 27 ~SocketStreamHost(); |
| 28 |
| 29 // Get socket_id associated with |socket|. |
| 30 static int SocketIdFromSocketStream(net::SocketStream* socket); |
| 31 |
| 32 int socket_id() const { return socket_id_; } |
| 33 |
| 34 // Start to open connection to |url|. |
| 35 void Connect(const GURL& url); |
| 36 |
| 37 // Send |data| over the socket stream. |
| 38 // socket stream must be open to send data. |
| 39 // Returns true if the data is put in transmit buffer in socket stream. |
| 40 // Returns false otherwise (transmit buffer exceeds limit, or socket |
| 41 // stream is closed). |
| 42 bool SendData(const std::vector<char>& data); |
| 43 |
| 44 // Close the socket stream. |
| 45 void Close(); |
| 46 |
| 47 private: |
| 48 net::SocketStream::Delegate* delegate_; |
| 49 int socket_id_; |
| 50 |
| 51 scoped_refptr<net::SocketStream> socket_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(SocketStreamHost); |
| 54 }; |
| 55 |
| 56 #endif // CHROME_BROWSER_RENDERER_HOST_SOCKET_STREAM_HOST_H_ |
OLD | NEW |