Show Pages in chrome://md-settings
[chromium-blink-merge.git] / net / socket / websocket_transport_connect_sub_job.h
blob5709a461cafef3ba6dba6a19e4b68f7abe6432d8
1 // Copyright 2014 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 NET_SOCKET_WEBSOCKET_TRANSPORT_CONNECT_SUB_JOB_H_
6 #define NET_SOCKET_WEBSOCKET_TRANSPORT_CONNECT_SUB_JOB_H_
8 #include "base/compiler_specific.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "net/base/address_list.h"
12 #include "net/base/load_states.h"
13 #include "net/socket/websocket_endpoint_lock_manager.h"
14 #include "net/socket/websocket_transport_client_socket_pool.h"
16 namespace net {
18 class BoundNetLog;
19 class ClientSocketFactory;
20 class IPEndPoint;
21 class StreamSocket;
23 // Attempts to connect to a subset of the addresses required by a
24 // WebSocketTransportConnectJob, specifically either the IPv4 or IPv6
25 // addresses. Each address is tried in turn, and parent_job->OnSubJobComplete()
26 // is called when the first address succeeds or the last address fails.
27 class WebSocketTransportConnectSubJob
28 : public WebSocketEndpointLockManager::Waiter {
29 public:
30 typedef WebSocketTransportConnectJob::SubJobType SubJobType;
32 WebSocketTransportConnectSubJob(const AddressList& addresses,
33 WebSocketTransportConnectJob* parent_job,
34 SubJobType type);
36 ~WebSocketTransportConnectSubJob() override;
38 // Start connecting.
39 int Start();
41 bool started() { return next_state_ != STATE_NONE; }
43 LoadState GetLoadState() const;
45 SubJobType type() const { return type_; }
47 scoped_ptr<StreamSocket> PassSocket() { return transport_socket_.Pass(); }
49 // Implementation of WebSocketEndpointLockManager::EndpointWaiter.
50 void GotEndpointLock() override;
52 private:
53 enum State {
54 STATE_NONE,
55 STATE_OBTAIN_LOCK,
56 STATE_OBTAIN_LOCK_COMPLETE,
57 STATE_TRANSPORT_CONNECT,
58 STATE_TRANSPORT_CONNECT_COMPLETE,
59 STATE_DONE,
62 ClientSocketFactory* client_socket_factory() const;
64 const BoundNetLog& net_log() const;
66 const IPEndPoint& CurrentAddress() const;
68 void OnIOComplete(int result);
69 int DoLoop(int result);
70 int DoEndpointLock();
71 int DoEndpointLockComplete();
72 int DoTransportConnect();
73 int DoTransportConnectComplete(int result);
75 WebSocketTransportConnectJob* const parent_job_;
77 const AddressList addresses_;
78 size_t current_address_index_;
80 State next_state_;
81 const SubJobType type_;
83 scoped_ptr<StreamSocket> transport_socket_;
85 DISALLOW_COPY_AND_ASSIGN(WebSocketTransportConnectSubJob);
88 } // namespace net
90 #endif // NET_SOCKET_WEBSOCKET_TRANSPORT_CONNECT_SUB_JOB_H_