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

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

Issue 9005034: Refactor SignalStrategy so that it can be reused for multiple connections. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 8 years, 11 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
« no previous file with comments | « remoting/protocol/connection_to_host.h ('k') | remoting/protocol/jingle_session_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/connection_to_host.h" 5 #include "remoting/protocol/connection_to_host.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/location.h" 9 #include "base/location.h"
10 #include "base/message_loop_proxy.h" 10 #include "base/message_loop_proxy.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 access_code_ = access_code; 64 access_code_ = access_code;
65 65
66 // Save jid of the host. The actual connection is created later after 66 // Save jid of the host. The actual connection is created later after
67 // |signal_strategy_| is connected. 67 // |signal_strategy_| is connected.
68 host_jid_ = host_jid; 68 host_jid_ = host_jid;
69 host_public_key_ = host_public_key; 69 host_public_key_ = host_public_key;
70 70
71 JavascriptSignalStrategy* strategy = new JavascriptSignalStrategy(your_jid); 71 JavascriptSignalStrategy* strategy = new JavascriptSignalStrategy(your_jid);
72 strategy->AttachXmppProxy(xmpp_proxy); 72 strategy->AttachXmppProxy(xmpp_proxy);
73 signal_strategy_.reset(strategy); 73 signal_strategy_.reset(strategy);
74 signal_strategy_->Init(this); 74 signal_strategy_->AddListener(this);
75 signal_strategy_->Connect();
76
77 session_manager_.reset(new PepperSessionManager(pp_instance_));
78 session_manager_->Init(signal_strategy_.get(), this, allow_nat_traversal_);
75 } 79 }
76 80
77 void ConnectionToHost::Disconnect(const base::Closure& shutdown_task) { 81 void ConnectionToHost::Disconnect(const base::Closure& shutdown_task) {
78 if (!message_loop_->BelongsToCurrentThread()) { 82 if (!message_loop_->BelongsToCurrentThread()) {
79 message_loop_->PostTask( 83 message_loop_->PostTask(
80 FROM_HERE, base::Bind(&ConnectionToHost::Disconnect, 84 FROM_HERE, base::Bind(&ConnectionToHost::Disconnect,
81 base::Unretained(this), shutdown_task)); 85 base::Unretained(this), shutdown_task));
82 return; 86 return;
83 } 87 }
84 88
85 CloseChannels(); 89 CloseChannels();
86 90
87 if (session_.get()) 91 if (session_.get())
88 session_.reset(); 92 session_.reset();
89 93
90 if (session_manager_.get()) 94 if (session_manager_.get())
91 session_manager_.reset(); 95 session_manager_.reset();
92 96
93 if (signal_strategy_.get()) 97 if (signal_strategy_.get()) {
98 signal_strategy_->RemoveListener(this);
94 signal_strategy_.reset(); 99 signal_strategy_.reset();
100 }
95 101
96 shutdown_task.Run(); 102 shutdown_task.Run();
97 } 103 }
98 104
99 void ConnectionToHost::InitSession() {
100 DCHECK(message_loop_->BelongsToCurrentThread());
101
102 session_manager_.reset(new PepperSessionManager(pp_instance_));
103 session_manager_->Init(
104 local_jid_, signal_strategy_.get(), this, allow_nat_traversal_);
105 }
106
107 const SessionConfig& ConnectionToHost::config() { 105 const SessionConfig& ConnectionToHost::config() {
108 return session_->config(); 106 return session_->config();
109 } 107 }
110 108
111 void ConnectionToHost::OnStateChange( 109 void ConnectionToHost::OnSignalStrategyStateChange(
112 SignalStrategy::StatusObserver::State state) { 110 SignalStrategy::State state) {
113 DCHECK(message_loop_->BelongsToCurrentThread()); 111 DCHECK(message_loop_->BelongsToCurrentThread());
114 DCHECK(event_callback_); 112 DCHECK(event_callback_);
115 113
116 if (state == SignalStrategy::StatusObserver::CONNECTED) { 114 if (state == SignalStrategy::CONNECTED) {
117 VLOG(1) << "Connected as: " << local_jid_; 115 VLOG(1) << "Connected as: " << signal_strategy_->GetLocalJid();
118 InitSession(); 116 } else if (state == SignalStrategy::DISCONNECTED) {
119 } else if (state == SignalStrategy::StatusObserver::CLOSED) {
120 VLOG(1) << "Connection closed."; 117 VLOG(1) << "Connection closed.";
121 CloseOnError(NETWORK_FAILURE); 118 CloseOnError(NETWORK_FAILURE);
122 } 119 }
123 } 120 }
124 121
125 void ConnectionToHost::OnJidChange(const std::string& full_jid) { 122 void ConnectionToHost::OnSessionManagerReady() {
126 DCHECK(message_loop_->BelongsToCurrentThread());
127 local_jid_ = full_jid;
128 }
129
130 void ConnectionToHost::OnSessionManagerInitialized() {
131 DCHECK(message_loop_->BelongsToCurrentThread()); 123 DCHECK(message_loop_->BelongsToCurrentThread());
132 124
133 // After SessionManager is initialized we can try to connect to the host. 125 // After SessionManager is initialized we can try to connect to the host.
134 CandidateSessionConfig* candidate_config = 126 CandidateSessionConfig* candidate_config =
135 CandidateSessionConfig::CreateDefault(); 127 CandidateSessionConfig::CreateDefault();
136 V1ClientAuthenticator* authenticator = 128 V1ClientAuthenticator* authenticator =
137 new V1ClientAuthenticator(local_jid_, access_code_); 129 new V1ClientAuthenticator(signal_strategy_->GetLocalJid(), access_code_);
138 session_.reset(session_manager_->Connect( 130 session_.reset(session_manager_->Connect(
139 host_jid_, authenticator, candidate_config, 131 host_jid_, authenticator, candidate_config,
140 base::Bind(&ConnectionToHost::OnSessionStateChange, 132 base::Bind(&ConnectionToHost::OnSessionStateChange,
141 base::Unretained(this)))); 133 base::Unretained(this))));
142 } 134 }
143 135
144 void ConnectionToHost::OnIncomingSession( 136 void ConnectionToHost::OnIncomingSession(
145 Session* session, 137 Session* session,
146 SessionManager::IncomingSessionResponse* response) { 138 SessionManager::IncomingSessionResponse* response) {
147 DCHECK(message_loop_->BelongsToCurrentThread()); 139 DCHECK(message_loop_->BelongsToCurrentThread());
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 239
248 if (state != state_) { 240 if (state != state_) {
249 state_ = state; 241 state_ = state;
250 error_ = error; 242 error_ = error;
251 event_callback_->OnConnectionState(state_, error_); 243 event_callback_->OnConnectionState(state_, error_);
252 } 244 }
253 } 245 }
254 246
255 } // namespace protocol 247 } // namespace protocol
256 } // namespace remoting 248 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/connection_to_host.h ('k') | remoting/protocol/jingle_session_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698