Added documentation to web_view.js/web_view_experimental.js regarding the webview...
[chromium-blink-merge.git] / ppapi / shared_impl / ppb_tcp_socket_shared.cc
blob934c573d16d09f26f43eb5b63cd40bdd7e63677f
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),
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_) {
27 case NONE:
28 NOTREACHED();
29 break;
30 case BIND:
31 if (success)
32 state_ = BOUND;
33 break;
34 case CONNECT:
35 state_ = success ? CONNECTED : CLOSED;
36 break;
37 case SSL_CONNECT:
38 state_ = success ? SSL_CONNECTED : CLOSED;
39 break;
40 case LISTEN:
41 if (success)
42 state_ = LISTENING;
43 break;
44 case CLOSE:
45 state_ = CLOSED;
46 break;
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)
58 return false;
60 switch (transition) {
61 case NONE:
62 return false;
63 case BIND:
64 return state_ == INITIAL;
65 case CONNECT:
66 return state_ == INITIAL || state_ == BOUND;
67 case SSL_CONNECT:
68 return state_ == CONNECTED;
69 case LISTEN:
70 return state_ == BOUND;
71 case CLOSE:
72 return true;
74 NOTREACHED();
75 return false;
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;
90 } // namespace ppapi