Roll src/third_party/skia e66fec2:2bd5d02
[chromium-blink-merge.git] / ppapi / shared_impl / ppb_tcp_socket_shared.cc
blob94fb45ea38146d8d998eed1d8b2fd22a9773731c
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"
9 namespace ppapi {
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_) {
25 case NONE:
26 NOTREACHED();
27 break;
28 case BIND:
29 if (success)
30 state_ = BOUND;
31 break;
32 case CONNECT:
33 state_ = success ? CONNECTED : CLOSED;
34 break;
35 case SSL_CONNECT:
36 state_ = success ? SSL_CONNECTED : CLOSED;
37 break;
38 case LISTEN:
39 if (success)
40 state_ = LISTENING;
41 break;
42 case CLOSE:
43 state_ = CLOSED;
44 break;
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)
56 return false;
58 switch (transition) {
59 case NONE:
60 return false;
61 case BIND:
62 return state_ == INITIAL;
63 case CONNECT:
64 return state_ == INITIAL || state_ == BOUND;
65 case SSL_CONNECT:
66 return state_ == CONNECTED;
67 case LISTEN:
68 return state_ == BOUND;
69 case CLOSE:
70 return true;
72 NOTREACHED();
73 return false;
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;
88 } // namespace ppapi