OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "remoting/protocol/connection_to_client.h" | 5 #include "remoting/protocol/connection_to_client.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "google/protobuf/message.h" | 8 #include "google/protobuf/message.h" |
8 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
9 #include "remoting/protocol/client_control_sender.h" | 10 #include "remoting/protocol/client_control_sender.h" |
10 #include "remoting/protocol/host_message_dispatcher.h" | 11 #include "remoting/protocol/host_message_dispatcher.h" |
11 #include "remoting/protocol/host_stub.h" | 12 #include "remoting/protocol/host_stub.h" |
12 #include "remoting/protocol/input_stub.h" | 13 #include "remoting/protocol/input_stub.h" |
13 | 14 |
14 // TODO(hclam): Remove this header once MessageDispatcher is used. | 15 // TODO(hclam): Remove this header once MessageDispatcher is used. |
15 #include "remoting/base/compound_buffer.h" | 16 #include "remoting/base/compound_buffer.h" |
16 | 17 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 90 |
90 DCHECK(handler_); | 91 DCHECK(handler_); |
91 switch(state) { | 92 switch(state) { |
92 case protocol::Session::CONNECTING: | 93 case protocol::Session::CONNECTING: |
93 break; | 94 break; |
94 // Don't care about this message. | 95 // Don't care about this message. |
95 case protocol::Session::CONNECTED: | 96 case protocol::Session::CONNECTED: |
96 client_control_sender_.reset( | 97 client_control_sender_.reset( |
97 new ClientControlSender(session_->control_channel())); | 98 new ClientControlSender(session_->control_channel())); |
98 video_writer_.reset(VideoWriter::Create(session_->config())); | 99 video_writer_.reset(VideoWriter::Create(session_->config())); |
99 video_writer_->Init(session_.get()); | 100 video_writer_->Init( |
100 | 101 session_.get(), base::Bind(&ConnectionToClient::OnVideoInitialized, |
| 102 base::Unretained(this))); |
101 dispatcher_.reset(new HostMessageDispatcher()); | 103 dispatcher_.reset(new HostMessageDispatcher()); |
102 dispatcher_->Initialize(this, host_stub_, input_stub_); | 104 dispatcher_->Initialize(this, host_stub_, input_stub_); |
103 | |
104 handler_->OnConnectionOpened(this); | |
105 break; | 105 break; |
106 case protocol::Session::CLOSED: | 106 case protocol::Session::CLOSED: |
107 CloseChannels(); | 107 CloseChannels(); |
108 handler_->OnConnectionClosed(this); | 108 handler_->OnConnectionClosed(this); |
109 break; | 109 break; |
110 case protocol::Session::FAILED: | 110 case protocol::Session::FAILED: |
111 CloseChannels(); | 111 CloseOnError(); |
112 handler_->OnConnectionFailed(this); | |
113 break; | 112 break; |
114 default: | 113 default: |
115 // We shouldn't receive other states. | 114 // We shouldn't receive other states. |
116 NOTREACHED(); | 115 NOTREACHED(); |
117 } | 116 } |
118 } | 117 } |
119 | 118 |
| 119 void ConnectionToClient::OnVideoInitialized(bool successful) { |
| 120 if (!successful) { |
| 121 CloseOnError(); |
| 122 return; |
| 123 } |
| 124 |
| 125 handler_->OnConnectionOpened(this); |
| 126 } |
| 127 |
| 128 void ConnectionToClient::CloseOnError() { |
| 129 CloseChannels(); |
| 130 handler_->OnConnectionFailed(this); |
| 131 } |
| 132 |
120 void ConnectionToClient::CloseChannels() { | 133 void ConnectionToClient::CloseChannels() { |
121 if (video_writer_.get()) | 134 if (video_writer_.get()) |
122 video_writer_->Close(); | 135 video_writer_->Close(); |
123 if (client_control_sender_.get()) | 136 if (client_control_sender_.get()) |
124 client_control_sender_->Close(); | 137 client_control_sender_->Close(); |
125 } | 138 } |
126 | 139 |
127 } // namespace protocol | 140 } // namespace protocol |
128 } // namespace remoting | 141 } // namespace remoting |
OLD | NEW |