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"
19 class ClientSocketFactory
;
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
{
30 typedef WebSocketTransportConnectJob::SubJobType SubJobType
;
32 WebSocketTransportConnectSubJob(const AddressList
& addresses
,
33 WebSocketTransportConnectJob
* parent_job
,
36 ~WebSocketTransportConnectSubJob() override
;
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
;
56 STATE_OBTAIN_LOCK_COMPLETE
,
57 STATE_TRANSPORT_CONNECT
,
58 STATE_TRANSPORT_CONNECT_COMPLETE
,
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
);
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_
;
81 const SubJobType type_
;
83 scoped_ptr
<StreamSocket
> transport_socket_
;
85 DISALLOW_COPY_AND_ASSIGN(WebSocketTransportConnectSubJob
);
90 #endif // NET_SOCKET_WEBSOCKET_TRANSPORT_CONNECT_SUB_JOB_H_