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/pepper_session.h" | 5 #include "remoting/protocol/pepper_session.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 state_change_callback_ = callback; | 49 state_change_callback_ = callback; |
50 } | 50 } |
51 | 51 |
52 Session::Error PepperSession::error() { | 52 Session::Error PepperSession::error() { |
53 DCHECK(CalledOnValidThread()); | 53 DCHECK(CalledOnValidThread()); |
54 return error_; | 54 return error_; |
55 } | 55 } |
56 | 56 |
57 void PepperSession::StartConnection( | 57 void PepperSession::StartConnection( |
58 const std::string& peer_jid, | 58 const std::string& peer_jid, |
59 Authenticator* authenticator, | 59 scoped_ptr<Authenticator> authenticator, |
60 CandidateSessionConfig* config, | 60 scoped_ptr<CandidateSessionConfig> config, |
61 const StateChangeCallback& state_change_callback) { | 61 const StateChangeCallback& state_change_callback) { |
62 DCHECK(CalledOnValidThread()); | 62 DCHECK(CalledOnValidThread()); |
63 DCHECK(authenticator); | 63 DCHECK(authenticator.get()); |
64 DCHECK_EQ(authenticator->state(), Authenticator::MESSAGE_READY); | 64 DCHECK_EQ(authenticator->state(), Authenticator::MESSAGE_READY); |
65 | 65 |
66 peer_jid_ = peer_jid; | 66 peer_jid_ = peer_jid; |
67 authenticator_.reset(authenticator); | 67 authenticator_ = authenticator.Pass(); |
68 candidate_config_.reset(config); | 68 candidate_config_ = config.Pass(); |
69 state_change_callback_ = state_change_callback; | 69 state_change_callback_ = state_change_callback; |
70 | 70 |
71 // Generate random session ID. There are usually not more than 1 | 71 // Generate random session ID. There are usually not more than 1 |
72 // concurrent session per host, so a random 64-bit integer provides | 72 // concurrent session per host, so a random 64-bit integer provides |
73 // enough entropy. In the worst case connection will fail when two | 73 // enough entropy. In the worst case connection will fail when two |
74 // clients generate the same session ID concurrently. | 74 // clients generate the same session ID concurrently. |
75 session_id_ = base::Int64ToString(base::RandGenerator(kint64max)); | 75 session_id_ = base::Int64ToString(base::RandGenerator(kint64max)); |
76 | 76 |
77 // Send session-initiate message. | 77 // Send session-initiate message. |
78 JingleMessage message(peer_jid_, JingleMessage::SESSION_INITIATE, | 78 JingleMessage message(peer_jid_, JingleMessage::SESSION_INITIATE, |
(...skipping 27 matching lines...) Expand all Loading... |
106 void PepperSession::OnError(Error error) { | 106 void PepperSession::OnError(Error error) { |
107 error_ = error; | 107 error_ = error; |
108 CloseInternal(true); | 108 CloseInternal(true); |
109 } | 109 } |
110 | 110 |
111 void PepperSession::CreateStreamChannel( | 111 void PepperSession::CreateStreamChannel( |
112 const std::string& name, | 112 const std::string& name, |
113 const StreamChannelCallback& callback) { | 113 const StreamChannelCallback& callback) { |
114 DCHECK(!channels_[name]); | 114 DCHECK(!channels_[name]); |
115 | 115 |
116 ChannelAuthenticator* channel_authenticator = | 116 scoped_ptr<ChannelAuthenticator> channel_authenticator = |
117 authenticator_->CreateChannelAuthenticator(); | 117 authenticator_->CreateChannelAuthenticator(); |
118 PepperStreamChannel* channel = new PepperStreamChannel( | 118 PepperStreamChannel* channel = new PepperStreamChannel( |
119 this, name, callback); | 119 this, name, callback); |
120 channels_[name] = channel; | 120 channels_[name] = channel; |
121 channel->Connect(session_manager_->pp_instance_, | 121 channel->Connect(session_manager_->pp_instance_, |
122 session_manager_->transport_config_, | 122 session_manager_->transport_config_, |
123 channel_authenticator); | 123 channel_authenticator.Pass()); |
124 } | 124 } |
125 | 125 |
126 void PepperSession::CreateDatagramChannel( | 126 void PepperSession::CreateDatagramChannel( |
127 const std::string& name, | 127 const std::string& name, |
128 const DatagramChannelCallback& callback) { | 128 const DatagramChannelCallback& callback) { |
129 // TODO(sergeyu): Implement datagram channel support. | 129 // TODO(sergeyu): Implement datagram channel support. |
130 NOTREACHED(); | 130 NOTREACHED(); |
131 } | 131 } |
132 | 132 |
133 void PepperSession::CancelChannelCreation(const std::string& name) { | 133 void PepperSession::CancelChannelCreation(const std::string& name) { |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 } | 327 } |
328 | 328 |
329 return true; | 329 return true; |
330 } | 330 } |
331 | 331 |
332 void PepperSession::ProcessAuthenticationStep() { | 332 void PepperSession::ProcessAuthenticationStep() { |
333 DCHECK_EQ(state_, CONNECTED); | 333 DCHECK_EQ(state_, CONNECTED); |
334 | 334 |
335 if (authenticator_->state() == Authenticator::MESSAGE_READY) { | 335 if (authenticator_->state() == Authenticator::MESSAGE_READY) { |
336 JingleMessage message(peer_jid_, JingleMessage::SESSION_INFO, session_id_); | 336 JingleMessage message(peer_jid_, JingleMessage::SESSION_INFO, session_id_); |
337 message.info.reset(authenticator_->GetNextMessage()); | 337 message.info = authenticator_->GetNextMessage(); |
338 DCHECK(message.info.get()); | 338 DCHECK(message.info.get()); |
339 | 339 |
340 session_info_request_.reset(session_manager_->iq_sender()->SendIq( | 340 session_info_request_.reset(session_manager_->iq_sender()->SendIq( |
341 message.ToXml(), base::Bind( | 341 message.ToXml(), base::Bind( |
342 &PepperSession::OnSessionInfoResponse, | 342 &PepperSession::OnSessionInfoResponse, |
343 base::Unretained(this)))); | 343 base::Unretained(this)))); |
344 } | 344 } |
345 DCHECK_NE(authenticator_->state(), Authenticator::MESSAGE_READY); | 345 DCHECK_NE(authenticator_->state(), Authenticator::MESSAGE_READY); |
346 | 346 |
347 if (authenticator_->state() == Authenticator::ACCEPTED) { | 347 if (authenticator_->state() == Authenticator::ACCEPTED) { |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 DCHECK_NE(state_, FAILED); | 424 DCHECK_NE(state_, FAILED); |
425 | 425 |
426 state_ = new_state; | 426 state_ = new_state; |
427 if (!state_change_callback_.is_null()) | 427 if (!state_change_callback_.is_null()) |
428 state_change_callback_.Run(new_state); | 428 state_change_callback_.Run(new_state); |
429 } | 429 } |
430 } | 430 } |
431 | 431 |
432 } // namespace protocol | 432 } // namespace protocol |
433 } // namespace remoting | 433 } // namespace remoting |
OLD | NEW |