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