| 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 26 matching lines...) Expand all Loading... |
| 37 error_(OK) { | 37 error_(OK) { |
| 38 } | 38 } |
| 39 | 39 |
| 40 PepperSession::~PepperSession() { | 40 PepperSession::~PepperSession() { |
| 41 control_channel_socket_.reset(); | 41 control_channel_socket_.reset(); |
| 42 event_channel_socket_.reset(); | 42 event_channel_socket_.reset(); |
| 43 STLDeleteContainerPairSecondPointers(channels_.begin(), channels_.end()); | 43 STLDeleteContainerPairSecondPointers(channels_.begin(), channels_.end()); |
| 44 session_manager_->SessionDestroyed(this); | 44 session_manager_->SessionDestroyed(this); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void PepperSession::SetStateChangeCallback(StateChangeCallback* callback) { | 47 void PepperSession::SetStateChangeCallback( |
| 48 const StateChangeCallback& callback) { |
| 48 DCHECK(CalledOnValidThread()); | 49 DCHECK(CalledOnValidThread()); |
| 49 state_change_callback_.reset(callback); | 50 state_change_callback_ = callback; |
| 50 } | 51 } |
| 51 | 52 |
| 52 Session::Error PepperSession::error() { | 53 Session::Error PepperSession::error() { |
| 53 DCHECK(CalledOnValidThread()); | 54 DCHECK(CalledOnValidThread()); |
| 54 return error_; | 55 return error_; |
| 55 } | 56 } |
| 56 | 57 |
| 57 void PepperSession::StartConnection( | 58 void PepperSession::StartConnection( |
| 58 const std::string& peer_jid, | 59 const std::string& peer_jid, |
| 59 const std::string& peer_public_key, | 60 const std::string& peer_public_key, |
| 60 const std::string& client_token, | 61 const std::string& client_token, |
| 61 CandidateSessionConfig* config, | 62 CandidateSessionConfig* config, |
| 62 Session::StateChangeCallback* state_change_callback) { | 63 const StateChangeCallback& state_change_callback) { |
| 63 DCHECK(CalledOnValidThread()); | 64 DCHECK(CalledOnValidThread()); |
| 64 | 65 |
| 65 peer_jid_ = peer_jid; | 66 peer_jid_ = peer_jid; |
| 66 peer_public_key_ = peer_public_key; | 67 peer_public_key_ = peer_public_key; |
| 67 initiator_token_ = client_token; | 68 initiator_token_ = client_token; |
| 68 candidate_config_.reset(config); | 69 candidate_config_.reset(config); |
| 69 state_change_callback_.reset(state_change_callback); | 70 state_change_callback_ = state_change_callback; |
| 70 | 71 |
| 71 // Generate random session ID. There are usually not more than 1 | 72 // Generate random session ID. There are usually not more than 1 |
| 72 // concurrent session per host, so a random 64-bit integer provides | 73 // concurrent session per host, so a random 64-bit integer provides |
| 73 // enough entropy. In the worst case connection will fail when two | 74 // enough entropy. In the worst case connection will fail when two |
| 74 // clients generate the same session ID concurrently. | 75 // clients generate the same session ID concurrently. |
| 75 session_id_ = base::Int64ToString(base::RandGenerator(kint64max)); | 76 session_id_ = base::Int64ToString(base::RandGenerator(kint64max)); |
| 76 | 77 |
| 77 // Send session-initiate message. | 78 // Send session-initiate message. |
| 78 JingleMessage message(peer_jid_, JingleMessage::SESSION_INITIATE, | 79 JingleMessage message(peer_jid_, JingleMessage::SESSION_INITIATE, |
| 79 session_id_); | 80 session_id_); |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 } | 376 } |
| 376 | 377 |
| 377 void PepperSession::SetState(State new_state) { | 378 void PepperSession::SetState(State new_state) { |
| 378 DCHECK(CalledOnValidThread()); | 379 DCHECK(CalledOnValidThread()); |
| 379 | 380 |
| 380 if (new_state != state_) { | 381 if (new_state != state_) { |
| 381 DCHECK_NE(state_, CLOSED); | 382 DCHECK_NE(state_, CLOSED); |
| 382 DCHECK_NE(state_, FAILED); | 383 DCHECK_NE(state_, FAILED); |
| 383 | 384 |
| 384 state_ = new_state; | 385 state_ = new_state; |
| 385 if (state_change_callback_.get()) | 386 if (!state_change_callback_.is_null()) |
| 386 state_change_callback_->Run(new_state); | 387 state_change_callback_.Run(new_state); |
| 387 } | 388 } |
| 388 } | 389 } |
| 389 | 390 |
| 390 } // namespace protocol | 391 } // namespace protocol |
| 391 } // namespace remoting | 392 } // namespace remoting |
| OLD | NEW |