| 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/protocol/jingle_connection_to_host.h" | 5 #include "remoting/protocol/jingle_connection_to_host.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "remoting/base/constants.h" | 9 #include "remoting/base/constants.h" |
| 10 #include "remoting/jingle_glue/jingle_thread.h" | 10 #include "remoting/jingle_glue/jingle_thread.h" |
| 11 #include "remoting/proto/auth.pb.h" | 11 #include "remoting/proto/auth.pb.h" |
| 12 #include "remoting/protocol/client_message_dispatcher.h" |
| 12 #include "remoting/protocol/client_stub.h" | 13 #include "remoting/protocol/client_stub.h" |
| 13 #include "remoting/protocol/input_sender.h" | 14 #include "remoting/protocol/input_sender.h" |
| 14 #include "remoting/protocol/jingle_session_manager.h" | 15 #include "remoting/protocol/jingle_session_manager.h" |
| 15 #include "remoting/protocol/video_reader.h" | 16 #include "remoting/protocol/video_reader.h" |
| 16 #include "remoting/protocol/video_stub.h" | 17 #include "remoting/protocol/video_stub.h" |
| 17 #include "remoting/protocol/util.h" | 18 #include "remoting/protocol/util.h" |
| 18 | 19 |
| 19 namespace remoting { | 20 namespace remoting { |
| 20 namespace protocol { | 21 namespace protocol { |
| 21 | 22 |
| 22 JingleConnectionToHost::JingleConnectionToHost(JingleThread* thread) | 23 JingleConnectionToHost::JingleConnectionToHost(JingleThread* thread) |
| 23 : thread_(thread), | 24 : thread_(thread), |
| 24 event_callback_(NULL) { | 25 event_callback_(NULL), |
| 26 dispatcher_(new ClientMessageDispatcher()) { |
| 25 } | 27 } |
| 26 | 28 |
| 27 JingleConnectionToHost::~JingleConnectionToHost() { | 29 JingleConnectionToHost::~JingleConnectionToHost() { |
| 28 } | 30 } |
| 29 | 31 |
| 30 void JingleConnectionToHost::Connect(const std::string& username, | 32 void JingleConnectionToHost::Connect(const std::string& username, |
| 31 const std::string& auth_token, | 33 const std::string& auth_token, |
| 32 const std::string& host_jid, | 34 const std::string& host_jid, |
| 33 HostEventCallback* event_callback, | 35 HostEventCallback* event_callback, |
| 34 ClientStub* client_stub, | 36 ClientStub* client_stub, |
| 35 VideoStub* video_stub) { | 37 VideoStub* video_stub) { |
| 36 event_callback_ = event_callback; | 38 event_callback_ = event_callback; |
| 39 client_stub_ = client_stub; |
| 37 video_stub_ = video_stub; | 40 video_stub_ = video_stub; |
| 38 | 41 |
| 39 // Initialize |jingle_client_|. | 42 // Initialize |jingle_client_|. |
| 40 jingle_client_ = new JingleClient(thread_); | 43 jingle_client_ = new JingleClient(thread_); |
| 41 jingle_client_->Init(username, auth_token, | 44 jingle_client_->Init(username, auth_token, |
| 42 kChromotingTokenServiceName, this); | 45 kChromotingTokenServiceName, this); |
| 43 | 46 |
| 44 // Save jid of the host. The actual connection is created later after | 47 // Save jid of the host. The actual connection is created later after |
| 45 // |jingle_client_| is connected. | 48 // |jingle_client_| is connected. |
| 46 host_jid_ = host_jid; | 49 host_jid_ = host_jid; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 58 video_reader_->Close(); | 61 video_reader_->Close(); |
| 59 | 62 |
| 60 if (session_) { | 63 if (session_) { |
| 61 session_->Close( | 64 session_->Close( |
| 62 NewRunnableMethod(this, &JingleConnectionToHost::OnDisconnected)); | 65 NewRunnableMethod(this, &JingleConnectionToHost::OnDisconnected)); |
| 63 } else { | 66 } else { |
| 64 OnDisconnected(); | 67 OnDisconnected(); |
| 65 } | 68 } |
| 66 } | 69 } |
| 67 | 70 |
| 68 void JingleConnectionToHost::OnControlMessage(ControlMessage* msg) { | |
| 69 // TODO(sergeyu): Remove this method and pass ClientStub to the control | |
| 70 // stream dispatcher. | |
| 71 delete msg; | |
| 72 } | |
| 73 | |
| 74 void JingleConnectionToHost::InitSession() { | 71 void JingleConnectionToHost::InitSession() { |
| 75 DCHECK_EQ(message_loop(), MessageLoop::current()); | 72 DCHECK_EQ(message_loop(), MessageLoop::current()); |
| 76 | 73 |
| 77 // Initialize chromotocol |session_manager_|. | 74 // Initialize chromotocol |session_manager_|. |
| 78 protocol::JingleSessionManager* session_manager = | 75 JingleSessionManager* session_manager = |
| 79 new protocol::JingleSessionManager(thread_); | 76 new JingleSessionManager(thread_); |
| 80 // TODO(ajwong): Make this a command switch when we're more stable. | 77 // TODO(ajwong): Make this a command switch when we're more stable. |
| 81 session_manager->set_allow_local_ips(true); | 78 session_manager->set_allow_local_ips(true); |
| 82 session_manager->Init( | 79 session_manager->Init( |
| 83 jingle_client_->GetFullJid(), | 80 jingle_client_->GetFullJid(), |
| 84 jingle_client_->session_manager(), | 81 jingle_client_->session_manager(), |
| 85 NewCallback(this, &JingleConnectionToHost::OnNewSession)); | 82 NewCallback(this, &JingleConnectionToHost::OnNewSession)); |
| 86 session_manager_ = session_manager; | 83 session_manager_ = session_manager; |
| 87 | 84 |
| 88 CandidateSessionConfig* candidate_config = | 85 CandidateSessionConfig* candidate_config = |
| 89 CandidateSessionConfig::CreateDefault(); | 86 CandidateSessionConfig::CreateDefault(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 | 134 |
| 138 if (state == JingleClient::CONNECTED) { | 135 if (state == JingleClient::CONNECTED) { |
| 139 VLOG(1) << "Connected as: " << client->GetFullJid(); | 136 VLOG(1) << "Connected as: " << client->GetFullJid(); |
| 140 InitSession(); | 137 InitSession(); |
| 141 } else if (state == JingleClient::CLOSED) { | 138 } else if (state == JingleClient::CLOSED) { |
| 142 VLOG(1) << "Connection closed."; | 139 VLOG(1) << "Connection closed."; |
| 143 event_callback_->OnConnectionClosed(this); | 140 event_callback_->OnConnectionClosed(this); |
| 144 } | 141 } |
| 145 } | 142 } |
| 146 | 143 |
| 147 void JingleConnectionToHost::OnNewSession(protocol::Session* session, | 144 void JingleConnectionToHost::OnNewSession(Session* session, |
| 148 protocol::SessionManager::IncomingSessionResponse* response) { | 145 SessionManager::IncomingSessionResponse* response) { |
| 149 DCHECK_EQ(message_loop(), MessageLoop::current()); | 146 DCHECK_EQ(message_loop(), MessageLoop::current()); |
| 150 // Client always rejects incoming sessions. | 147 // Client always rejects incoming sessions. |
| 151 *response = protocol::SessionManager::DECLINE; | 148 *response = SessionManager::DECLINE; |
| 152 } | 149 } |
| 153 | 150 |
| 154 void JingleConnectionToHost::OnSessionStateChange( | 151 void JingleConnectionToHost::OnSessionStateChange( |
| 155 protocol::Session::State state) { | 152 Session::State state) { |
| 156 DCHECK_EQ(message_loop(), MessageLoop::current()); | 153 DCHECK_EQ(message_loop(), MessageLoop::current()); |
| 157 DCHECK(event_callback_); | 154 DCHECK(event_callback_); |
| 158 | 155 |
| 159 switch (state) { | 156 switch (state) { |
| 160 case protocol::Session::FAILED: | 157 case Session::FAILED: |
| 161 event_callback_->OnConnectionFailed(this); | 158 event_callback_->OnConnectionFailed(this); |
| 162 break; | 159 break; |
| 163 | 160 |
| 164 case protocol::Session::CLOSED: | 161 case Session::CLOSED: |
| 165 event_callback_->OnConnectionClosed(this); | 162 event_callback_->OnConnectionClosed(this); |
| 166 break; | 163 break; |
| 167 | 164 |
| 168 case protocol::Session::CONNECTED: | 165 case Session::CONNECTED: |
| 169 // Initialize reader and writer. | 166 // Initialize reader and writer. |
| 170 control_reader_.Init<ControlMessage>( | |
| 171 session_->control_channel(), | |
| 172 NewCallback(this, &JingleConnectionToHost::OnControlMessage)); | |
| 173 video_reader_.reset(VideoReader::Create(session_->config())); | 167 video_reader_.reset(VideoReader::Create(session_->config())); |
| 174 video_reader_->Init(session_, video_stub_); | 168 video_reader_->Init(session_, video_stub_); |
| 175 input_stub_.reset(new InputSender(session_->event_channel())); | 169 input_stub_.reset(new InputSender(session_->event_channel())); |
| 170 dispatcher_->Initialize(session_.get(), client_stub_); |
| 176 event_callback_->OnConnectionOpened(this); | 171 event_callback_->OnConnectionOpened(this); |
| 177 break; | 172 break; |
| 178 | 173 |
| 179 default: | 174 default: |
| 180 // Ignore the other states by default. | 175 // Ignore the other states by default. |
| 181 break; | 176 break; |
| 182 } | 177 } |
| 183 } | 178 } |
| 184 | 179 |
| 185 MessageLoop* JingleConnectionToHost::message_loop() { | 180 MessageLoop* JingleConnectionToHost::message_loop() { |
| 186 return thread_->message_loop(); | 181 return thread_->message_loop(); |
| 187 } | 182 } |
| 188 | 183 |
| 189 } // namespace protocol | 184 } // namespace protocol |
| 190 } // namespace remoting | 185 } // namespace remoting |
| OLD | NEW |