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

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

Issue 8619011: Use Authenticator interface in Session and SessionManager (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years 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/pepper_session_manager.h" 5 #include "remoting/protocol/pepper_session_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "remoting/jingle_glue/iq_sender.h" 8 #include "remoting/jingle_glue/iq_sender.h"
9 #include "remoting/jingle_glue/jingle_info_request.h" 9 #include "remoting/jingle_glue/jingle_info_request.h"
10 #include "remoting/jingle_glue/signal_strategy.h" 10 #include "remoting/jingle_glue/signal_strategy.h"
11 #include "remoting/protocol/authenticator.h"
11 #include "remoting/protocol/jingle_messages.h" 12 #include "remoting/protocol/jingle_messages.h"
12 #include "remoting/protocol/pepper_session.h" 13 #include "remoting/protocol/pepper_session.h"
13 #include "third_party/libjingle/source/talk/base/socketaddress.h" 14 #include "third_party/libjingle/source/talk/base/socketaddress.h"
14 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" 15 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
15 16
16 using buzz::QName; 17 using buzz::QName;
17 18
18 namespace remoting { 19 namespace remoting {
19 namespace protocol { 20 namespace protocol {
20 21
21 PepperSessionManager::PepperSessionManager(pp::Instance* pp_instance) 22 PepperSessionManager::PepperSessionManager(pp::Instance* pp_instance)
22 : pp_instance_(pp_instance), 23 : pp_instance_(pp_instance),
23 signal_strategy_(NULL), 24 signal_strategy_(NULL),
24 listener_(NULL), 25 listener_(NULL),
25 allow_nat_traversal_(false) { 26 allow_nat_traversal_(false) {
26 } 27 }
27 28
28 PepperSessionManager::~PepperSessionManager() { 29 PepperSessionManager::~PepperSessionManager() {
29 Close(); 30 Close();
30 } 31 }
31 32
32 void PepperSessionManager::Init( 33 void PepperSessionManager::Init(
33 const std::string& local_jid, 34 const std::string& local_jid,
34 SignalStrategy* signal_strategy, 35 SignalStrategy* signal_strategy,
35 SessionManager::Listener* listener, 36 SessionManager::Listener* listener,
36 crypto::RSAPrivateKey* private_key,
37 const std::string& certificate,
38 bool allow_nat_traversal) { 37 bool allow_nat_traversal) {
39 listener_ = listener; 38 listener_ = listener;
40 local_jid_ = local_jid; 39 local_jid_ = local_jid;
41 signal_strategy_ = signal_strategy; 40 signal_strategy_ = signal_strategy;
42 iq_sender_.reset(new IqSender(signal_strategy_)); 41 iq_sender_.reset(new IqSender(signal_strategy_));
43 private_key_.reset(private_key);
44 certificate_ = certificate;
45 allow_nat_traversal_ = allow_nat_traversal; 42 allow_nat_traversal_ = allow_nat_traversal;
46 43
47 signal_strategy_->AddListener(this); 44 signal_strategy_->AddListener(this);
48 45
49 // If NAT traversal is enabled then we need to request STUN/Relay info. 46 // If NAT traversal is enabled then we need to request STUN/Relay info.
50 if (allow_nat_traversal) { 47 if (allow_nat_traversal) {
51 jingle_info_request_.reset(new JingleInfoRequest(signal_strategy_)); 48 jingle_info_request_.reset(new JingleInfoRequest(signal_strategy_));
52 jingle_info_request_->Send(base::Bind(&PepperSessionManager::OnJingleInfo, 49 jingle_info_request_->Send(base::Bind(&PepperSessionManager::OnJingleInfo,
53 base::Unretained(this))); 50 base::Unretained(this)));
54 } else { 51 } else {
(...skipping 14 matching lines...) Expand all
69 transport_config_.relay_token = relay_token; 66 transport_config_.relay_token = relay_token;
70 VLOG(1) << "STUN server: " << transport_config_.stun_server 67 VLOG(1) << "STUN server: " << transport_config_.stun_server
71 << " Relay server: " << transport_config_.relay_server 68 << " Relay server: " << transport_config_.relay_server
72 << " Relay token: " << transport_config_.relay_token; 69 << " Relay token: " << transport_config_.relay_token;
73 70
74 listener_->OnSessionManagerInitialized(); 71 listener_->OnSessionManagerInitialized();
75 } 72 }
76 73
77 Session* PepperSessionManager::Connect( 74 Session* PepperSessionManager::Connect(
78 const std::string& host_jid, 75 const std::string& host_jid,
79 const std::string& host_public_key, 76 Authenticator* authenticator,
80 const std::string& client_token,
81 CandidateSessionConfig* config, 77 CandidateSessionConfig* config,
82 const Session::StateChangeCallback& state_change_callback) { 78 const Session::StateChangeCallback& state_change_callback) {
83 PepperSession* session = new PepperSession(this); 79 PepperSession* session = new PepperSession(this);
84 session->StartConnection(host_jid, host_public_key, client_token, 80 session->StartConnection(host_jid, authenticator, config,
85 config, state_change_callback); 81 state_change_callback);
86 sessions_[session->session_id_] = session; 82 sessions_[session->session_id_] = session;
87 return session; 83 return session;
88 } 84 }
89 85
90 void PepperSessionManager::Close() { 86 void PepperSessionManager::Close() {
91 DCHECK(CalledOnValidThread()); 87 DCHECK(CalledOnValidThread());
92 88
93 // Close() can be called only after all sessions are destroyed. 89 // Close() can be called only after all sessions are destroyed.
94 DCHECK(sessions_.empty()); 90 DCHECK(sessions_.empty());
95 91
96 listener_ = NULL; 92 listener_ = NULL;
97 jingle_info_request_.reset(); 93 jingle_info_request_.reset();
98 94
99 signal_strategy_->RemoveListener(this); 95 signal_strategy_->RemoveListener(this);
100 } 96 }
101 97
98 void PepperSessionManager::set_authenticator_factory(
99 AuthenticatorFactory* authenticator_factory) {
100 DCHECK(CalledOnValidThread());
101 authenticator_factory_.reset(authenticator_factory);
102 }
103
102 bool PepperSessionManager::OnIncomingStanza(const buzz::XmlElement* stanza) { 104 bool PepperSessionManager::OnIncomingStanza(const buzz::XmlElement* stanza) {
103 if (!JingleMessage::IsJingleMessage(stanza)) 105 if (!JingleMessage::IsJingleMessage(stanza))
104 return false; 106 return false;
105 107
106 JingleMessage message; 108 JingleMessage message;
107 std::string error; 109 std::string error;
108 if (!message.ParseXml(stanza, &error)) { 110 if (!message.ParseXml(stanza, &error)) {
109 SendReply(stanza, JingleMessageReply(JingleMessageReply::BAD_REQUEST)); 111 SendReply(stanza, JingleMessageReply(JingleMessageReply::BAD_REQUEST));
110 return true; 112 return true;
111 } 113 }
(...skipping 22 matching lines...) Expand all
134 buzz::XmlElement* stanza = reply.ToXml(original_stanza); 136 buzz::XmlElement* stanza = reply.ToXml(original_stanza);
135 signal_strategy_->SendStanza(stanza); 137 signal_strategy_->SendStanza(stanza);
136 } 138 }
137 139
138 void PepperSessionManager::SessionDestroyed(PepperSession* session) { 140 void PepperSessionManager::SessionDestroyed(PepperSession* session) {
139 sessions_.erase(session->session_id_); 141 sessions_.erase(session->session_id_);
140 } 142 }
141 143
142 } // namespace protocol 144 } // namespace protocol
143 } // namespace remoting 145 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698