Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / content / browser / renderer_host / socket_stream_host.h
blob237e915e64cd4a67b331107e9669a461b3b76e1f
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.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_SOCKET_STREAM_HOST_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_SOCKET_STREAM_HOST_H_
8 #include <vector>
10 #include "base/memory/ref_counted.h"
11 #include "net/socket_stream/socket_stream.h"
13 class GURL;
15 namespace net {
16 class SocketStreamJob;
17 class URLRequestContext;
18 class SSLInfo;
19 } // namespace net
21 namespace content {
23 // Host of SocketStreamHandle. Each SocketStreamHandle will have an unique
24 // socket_id assigned by SocketStreamHost constructor. If socket id is
25 // kNoSocketId, there is no SocketStreamHost. Each SocketStreamHost has
26 // SocketStream to manage bi-directional communication over socket stream. The
27 // lifetime of an instance of this class is completely controlled by the
28 // SocketStreamDispatcherHost.
29 class SocketStreamHost {
30 public:
31 SocketStreamHost(net::SocketStream::Delegate* delegate,
32 int render_view_id,
33 int socket_id);
34 ~SocketStreamHost();
36 // Gets socket_id associated with |socket|.
37 static int SocketIdFromSocketStream(const net::SocketStream* socket);
39 int render_view_id() const { return render_view_id_; }
40 int socket_id() const { return socket_id_; }
42 // Starts to open connection to |url|.
43 void Connect(const GURL& url, net::URLRequestContext* request_context);
45 // Sends |data| over the socket stream.
46 // socket stream must be open to send data.
47 // Returns true if the data is put in transmit buffer in socket stream.
48 // Returns false otherwise (transmit buffer exceeds limit, or socket
49 // stream is closed).
50 bool SendData(const std::vector<char>& data);
52 // Closes the socket stream.
53 void Close();
55 // Following CancelWithError, CancelWithSSLError, and ContinueDespiteError
56 // will be called by net::SocketStream::Delegate in OnSSLCertificateError.
57 // CancelWithError Cancels the connection because of an error.
58 // |error| is net::Error which represents the error.
59 void CancelWithError(int error);
61 // Cancels the connection because of receiving a certificate with an error.
62 void CancelWithSSLError(const net::SSLInfo& ssl_info);
64 // Continue to establish the connection in spite of an error.
65 void ContinueDespiteError();
67 private:
68 net::SocketStream::Delegate* delegate_;
69 int render_view_id_;
70 int socket_id_;
72 scoped_refptr<net::SocketStreamJob> job_;
74 DISALLOW_COPY_AND_ASSIGN(SocketStreamHost);
77 } // namespace content
79 #endif // CONTENT_BROWSER_RENDERER_HOST_SOCKET_STREAM_HOST_H_