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
)
13 pending_transition_(NONE
) {
14 DCHECK(state_
== INITIAL
|| state_
== CONNECTED
);
17 TCPSocketState::~TCPSocketState() {
20 void TCPSocketState::SetPendingTransition(TransitionType pending_transition
) {
21 DCHECK(IsValidTransition(pending_transition
));
22 pending_transition_
= pending_transition
;
25 void TCPSocketState::CompletePendingTransition(bool success
) {
26 switch (pending_transition_
) {
35 state_
= success
? CONNECTED
: CLOSED
;
38 state_
= success
? SSL_CONNECTED
: CLOSED
;
48 pending_transition_
= NONE
;
51 void TCPSocketState::DoTransition(TransitionType transition
, bool success
) {
52 SetPendingTransition(transition
);
53 CompletePendingTransition(success
);
56 bool TCPSocketState::IsValidTransition(TransitionType transition
) const {
57 if (pending_transition_
!= NONE
&& transition
!= CLOSE
)
64 return state_
== INITIAL
;
66 return state_
== INITIAL
|| state_
== BOUND
;
68 return state_
== CONNECTED
;
70 return state_
== BOUND
;
78 bool TCPSocketState::IsPending(TransitionType transition
) const {
79 return pending_transition_
== transition
;
82 bool TCPSocketState::IsConnected() const {
83 return state_
== CONNECTED
|| state_
== SSL_CONNECTED
;
86 bool TCPSocketState::IsBound() const {
87 return state_
!= INITIAL
&& state_
!= CLOSED
;