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