Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(762)

Side by Side Diff: remoting/protocol/jingle_session.cc

Issue 7796026: Pass SessionConfig by reference instead of pointer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/jingle_session.h" 5 #include "remoting/protocol/jingle_session.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
9 #include "base/rand_util.h" 9 #include "base/rand_util.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 JingleSession::JingleSession( 50 JingleSession::JingleSession(
51 JingleSessionManager* jingle_session_manager, 51 JingleSessionManager* jingle_session_manager,
52 const std::string& local_cert, 52 const std::string& local_cert,
53 crypto::RSAPrivateKey* local_private_key, 53 crypto::RSAPrivateKey* local_private_key,
54 const std::string& peer_public_key) 54 const std::string& peer_public_key)
55 : jingle_session_manager_(jingle_session_manager), 55 : jingle_session_manager_(jingle_session_manager),
56 local_cert_(local_cert), 56 local_cert_(local_cert),
57 state_(INITIALIZING), 57 state_(INITIALIZING),
58 closing_(false), 58 closing_(false),
59 cricket_session_(NULL), 59 cricket_session_(NULL),
60 config_set_(false),
60 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) { 61 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)) {
61 // TODO(hclam): Need a better way to clone a key. 62 // TODO(hclam): Need a better way to clone a key.
62 if (local_private_key) { 63 if (local_private_key) {
63 std::vector<uint8> key_bytes; 64 std::vector<uint8> key_bytes;
64 CHECK(local_private_key->ExportPrivateKey(&key_bytes)); 65 CHECK(local_private_key->ExportPrivateKey(&key_bytes));
65 local_private_key_.reset( 66 local_private_key_.reset(
66 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_bytes)); 67 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_bytes));
67 CHECK(local_private_key_.get()); 68 CHECK(local_private_key_.get());
68 } 69 }
69 } 70 }
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 DCHECK(CalledOnValidThread()); 158 DCHECK(CalledOnValidThread());
158 return control_channel_socket_.get(); 159 return control_channel_socket_.get();
159 } 160 }
160 161
161 net::Socket* JingleSession::event_channel() { 162 net::Socket* JingleSession::event_channel() {
162 DCHECK(CalledOnValidThread()); 163 DCHECK(CalledOnValidThread());
163 return event_channel_socket_.get(); 164 return event_channel_socket_.get();
164 } 165 }
165 166
166 const std::string& JingleSession::jid() { 167 const std::string& JingleSession::jid() {
167 // TODO(sergeyu): Fix ChromotingHost so that it doesn't call this 168 DCHECK(CalledOnValidThread());
168 // method on invalid thread and uncomment this DCHECK.
169 // See crbug.com/88600 .
170 // DCHECK(CalledOnValidThread());
171 return jid_; 169 return jid_;
172 } 170 }
173 171
174 const CandidateSessionConfig* JingleSession::candidate_config() { 172 const CandidateSessionConfig* JingleSession::candidate_config() {
175 DCHECK(CalledOnValidThread()); 173 DCHECK(CalledOnValidThread());
176 DCHECK(candidate_config_.get()); 174 DCHECK(candidate_config_.get());
177 return candidate_config_.get(); 175 return candidate_config_.get();
178 } 176 }
179 177
180 void JingleSession::set_candidate_config( 178 void JingleSession::set_candidate_config(
181 const CandidateSessionConfig* candidate_config) { 179 const CandidateSessionConfig* candidate_config) {
182 DCHECK(CalledOnValidThread()); 180 DCHECK(CalledOnValidThread());
183 DCHECK(!candidate_config_.get()); 181 DCHECK(!candidate_config_.get());
184 DCHECK(candidate_config); 182 DCHECK(candidate_config);
185 candidate_config_.reset(candidate_config); 183 candidate_config_.reset(candidate_config);
186 } 184 }
187 185
188 const std::string& JingleSession::local_certificate() const { 186 const std::string& JingleSession::local_certificate() const {
189 DCHECK(CalledOnValidThread()); 187 DCHECK(CalledOnValidThread());
190 return local_cert_; 188 return local_cert_;
191 } 189 }
192 190
193 const SessionConfig* JingleSession::config() { 191 const SessionConfig& JingleSession::config() {
194 // TODO(sergeyu): Fix ChromotingHost so that it doesn't call this 192 DCHECK(CalledOnValidThread());
195 // method on invalid thread and uncomment this DCHECK. 193 DCHECK(config_set_);
196 // See crbug.com/88600 . 194 return config_;
197 // DCHECK(CalledOnValidThread());
198 DCHECK(config_.get());
199 return config_.get();
200 } 195 }
201 196
202 void JingleSession::set_config(const SessionConfig* config) { 197 void JingleSession::set_config(const SessionConfig& config) {
203 DCHECK(CalledOnValidThread()); 198 DCHECK(CalledOnValidThread());
204 DCHECK(!config_.get()); 199 DCHECK(!config_set_);
205 DCHECK(config); 200 config_ = config;
206 config_.reset(config); 201 config_set_ = true;
207 } 202 }
208 203
209 const std::string& JingleSession::initiator_token() { 204 const std::string& JingleSession::initiator_token() {
210 DCHECK(CalledOnValidThread()); 205 DCHECK(CalledOnValidThread());
211 return initiator_token_; 206 return initiator_token_;
212 } 207 }
213 208
214 void JingleSession::set_initiator_token(const std::string& initiator_token) { 209 void JingleSession::set_initiator_token(const std::string& initiator_token) {
215 DCHECK(CalledOnValidThread()); 210 DCHECK(CalledOnValidThread());
216 initiator_token_ = initiator_token; 211 initiator_token_ = initiator_token;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 const protocol::ContentDescription* content_description = 327 const protocol::ContentDescription* content_description =
333 static_cast<const protocol::ContentDescription*>(content->description); 328 static_cast<const protocol::ContentDescription*>(content->description);
334 CHECK(content_description); 329 CHECK(content_description);
335 330
336 remote_cert_ = content_description->certificate(); 331 remote_cert_ = content_description->certificate();
337 if (remote_cert_.empty()) { 332 if (remote_cert_.empty()) {
338 LOG(ERROR) << "Connection response does not specify certificate"; 333 LOG(ERROR) << "Connection response does not specify certificate";
339 return false; 334 return false;
340 } 335 }
341 336
342 scoped_ptr<SessionConfig> config( 337 SessionConfig config;
343 content_description->config()->GetFinalConfig()); 338 if (!content_description->config()->GetFinalConfig(&config)) {
344 if (!config.get()) {
345 LOG(ERROR) << "Connection response does not specify configuration"; 339 LOG(ERROR) << "Connection response does not specify configuration";
346 return false; 340 return false;
347 } 341 }
348 if (!candidate_config()->IsSupported(config.get())) { 342 if (!candidate_config()->IsSupported(config)) {
349 LOG(ERROR) << "Connection response specifies an invalid configuration"; 343 LOG(ERROR) << "Connection response specifies an invalid configuration";
350 return false; 344 return false;
351 } 345 }
352 346
353 set_config(config.release()); 347 set_config(config);
354 return true; 348 return true;
355 } 349 }
356 350
357 void JingleSession::OnAccept() { 351 void JingleSession::OnAccept() {
358 DCHECK(CalledOnValidThread()); 352 DCHECK(CalledOnValidThread());
359 353
360 // If we initiated the session, store the candidate configuration that the 354 // If we initiated the session, store the candidate configuration that the
361 // host responded with, to refer to later. 355 // host responded with, to refer to later.
362 if (cricket_session_->initiator()) { 356 if (cricket_session_->initiator()) {
363 if (!InitializeConfigFromDescription( 357 if (!InitializeConfigFromDescription(
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 DCHECK_NE(state_, FAILED); 466 DCHECK_NE(state_, FAILED);
473 467
474 state_ = new_state; 468 state_ = new_state;
475 if (state_change_callback_.get()) 469 if (state_change_callback_.get())
476 state_change_callback_->Run(new_state); 470 state_change_callback_->Run(new_state);
477 } 471 }
478 } 472 }
479 473
480 } // namespace protocol 474 } // namespace protocol
481 } // namespace remoting 475 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698