| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/client/host_connection.h" | 5 #include "remoting/client/host_connection.h" |
| 6 | 6 |
| 7 namespace remoting { | 7 namespace remoting { |
| 8 | 8 |
| 9 HostConnection::HostConnection(ProtocolDecoder* decoder, | 9 HostConnection::HostConnection(ProtocolDecoder* decoder, |
| 10 EventHandler* handler) | 10 EventHandler* handler) |
| 11 : decoder_(decoder), handler_(handler) { | 11 : decoder_(decoder), handler_(handler) { |
| 12 } | 12 } |
| 13 | 13 |
| 14 HostConnection::~HostConnection() { | 14 HostConnection::~HostConnection() { |
| 15 Disconnect(); | 15 Disconnect(); |
| 16 } | 16 } |
| 17 | 17 |
| 18 void HostConnection::Connect(const std::string& username, | 18 void HostConnection::Connect(const std::string& username, |
| 19 const std::string& password, | 19 const std::string& password, |
| 20 const std::string& host_jid) { | 20 const std::string& host_jid) { |
| 21 jingle_client_ = new JingleClient(); | 21 jingle_client_ = new JingleClient(); |
| 22 jingle_client_->Init(username, password, this); | 22 jingle_client_->Init(username, password, this); |
| 23 jingle_channel_ = jingle_client_->Connect(host_jid, this); | 23 jingle_channel_ = jingle_client_->Connect(host_jid, this); |
| 24 } | 24 } |
| 25 | 25 |
| 26 void HostConnection::Disconnect() { | 26 void HostConnection::Disconnect() { |
| 27 if (jingle_channel_.get()) | 27 // TODO(hclam): It's not thread safe to read the state. |
| 28 if (jingle_channel_.get() && |
| 29 jingle_channel_->state() != JingleChannel::CLOSED) { |
| 28 jingle_channel_->Close(); | 30 jingle_channel_->Close(); |
| 31 } |
| 29 | 32 |
| 30 if (jingle_client_.get()) | 33 // TODO(hclam): It's not thread safe to read the state. |
| 34 if (jingle_client_.get() && |
| 35 jingle_client_->state() != JingleClient::CLOSED) { |
| 31 jingle_client_->Close(); | 36 jingle_client_->Close(); |
| 37 } |
| 32 } | 38 } |
| 33 | 39 |
| 34 void HostConnection::OnStateChange(JingleChannel* channel, | 40 void HostConnection::OnStateChange(JingleChannel* channel, |
| 35 JingleChannel::State state) { | 41 JingleChannel::State state) { |
| 36 DCHECK(handler_); | 42 DCHECK(handler_); |
| 37 if (state == JingleChannel::FAILED) | 43 if (state == JingleChannel::OPEN) |
| 44 handler_->OnConnectionOpened(this); |
| 45 else if (state == JingleChannel::FAILED) |
| 38 handler_->OnConnectionFailed(this); | 46 handler_->OnConnectionFailed(this); |
| 39 else if (state == JingleChannel::CLOSED) | 47 else if (state == JingleChannel::CLOSED) |
| 40 handler_->OnConnectionClosed(this); | 48 handler_->OnConnectionClosed(this); |
| 41 else if (state == JingleChannel::OPEN) | |
| 42 handler_->OnConnectionOpened(this); | |
| 43 } | 49 } |
| 44 | 50 |
| 45 void HostConnection::OnPacketReceived(JingleChannel* channel, | 51 void HostConnection::OnPacketReceived(JingleChannel* channel, |
| 46 scoped_refptr<media::DataBuffer> buffer) { | 52 scoped_refptr<media::DataBuffer> buffer) { |
| 47 HostMessageList list; | 53 HostMessageList list; |
| 48 decoder_->ParseHostMessages(buffer, &list); | 54 decoder_->ParseHostMessages(buffer, &list); |
| 49 DCHECK(handler_); | 55 DCHECK(handler_); |
| 50 handler_->HandleMessages(this, &list); | 56 handler_->HandleMessages(this, &list); |
| 51 } | 57 } |
| 52 | 58 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 69 // Client rejects all connection. | 75 // Client rejects all connection. |
| 70 return false; | 76 return false; |
| 71 } | 77 } |
| 72 | 78 |
| 73 void HostConnection::OnNewConnection(JingleClient* client, | 79 void HostConnection::OnNewConnection(JingleClient* client, |
| 74 scoped_refptr<JingleChannel> channel) { | 80 scoped_refptr<JingleChannel> channel) { |
| 75 NOTREACHED() << "SimpleClient can't accept connection."; | 81 NOTREACHED() << "SimpleClient can't accept connection."; |
| 76 } | 82 } |
| 77 | 83 |
| 78 } // namespace remoting | 84 } // namespace remoting |
| OLD | NEW |