1 // Copyright 2013 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 #include "ppapi/shared_impl/ppb_tcp_socket_shared.h"
7 #include "base/logging.h"
11 TCPSocketState::TCPSocketState(StateType state
)
12 : state_(state
), pending_transition_(NONE
) {
13 DCHECK(state_
== INITIAL
|| state_
== CONNECTED
);
16 TCPSocketState::~TCPSocketState() {}
18 void TCPSocketState::SetPendingTransition(TransitionType pending_transition
) {
19 DCHECK(IsValidTransition(pending_transition
));
20 pending_transition_
= pending_transition
;
23 void TCPSocketState::CompletePendingTransition(bool success
) {
24 switch (pending_transition_
) {
33 state_
= success
? CONNECTED
: CLOSED
;
36 state_
= success
? SSL_CONNECTED
: CLOSED
;
46 pending_transition_
= NONE
;
49 void TCPSocketState::DoTransition(TransitionType transition
, bool success
) {
50 SetPendingTransition(transition
);
51 CompletePendingTransition(success
);
54 bool TCPSocketState::IsValidTransition(TransitionType transition
) const {
55 if (pending_transition_
!= NONE
&& transition
!= CLOSE
)
62 return state_
== INITIAL
;
64 return state_
== INITIAL
|| state_
== BOUND
;
66 return state_
== CONNECTED
;
68 return state_
== BOUND
;
76 bool TCPSocketState::IsPending(TransitionType transition
) const {
77 return pending_transition_
== transition
;
80 bool TCPSocketState::IsConnected() const {
81 return state_
== CONNECTED
|| state_
== SSL_CONNECTED
;
84 bool TCPSocketState::IsBound() const {
85 return state_
!= INITIAL
&& state_
!= CLOSED
;