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

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

Issue 8432009: Refactor IqRequest. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 9 years, 1 month 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.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"
11 #include "remoting/base/constants.h" 11 #include "remoting/base/constants.h"
12 #include "remoting/jingle_glue/iq_request.h" 12 #include "remoting/jingle_glue/iq_sender.h"
13 #include "remoting/protocol/content_description.h" 13 #include "remoting/protocol/content_description.h"
14 #include "remoting/protocol/jingle_messages.h" 14 #include "remoting/protocol/jingle_messages.h"
15 #include "remoting/protocol/pepper_session_manager.h" 15 #include "remoting/protocol/pepper_session_manager.h"
16 #include "remoting/protocol/pepper_stream_channel.h" 16 #include "remoting/protocol/pepper_stream_channel.h"
17 #include "third_party/libjingle/source/talk/p2p/base/candidate.h" 17 #include "third_party/libjingle/source/talk/p2p/base/candidate.h"
18 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" 18 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
19 19
20 using buzz::XmlElement; 20 using buzz::XmlElement;
21 21
22 namespace remoting { 22 namespace remoting {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 // enough entropy. In the worst case connection will fail when two 74 // enough entropy. In the worst case connection will fail when two
75 // clients generate the same session ID concurrently. 75 // clients generate the same session ID concurrently.
76 session_id_ = base::Int64ToString(base::RandGenerator(kint64max)); 76 session_id_ = base::Int64ToString(base::RandGenerator(kint64max));
77 77
78 // Send session-initiate message. 78 // Send session-initiate message.
79 JingleMessage message(peer_jid_, JingleMessage::SESSION_INITIATE, 79 JingleMessage message(peer_jid_, JingleMessage::SESSION_INITIATE,
80 session_id_); 80 session_id_);
81 message.from = session_manager_->local_jid_; 81 message.from = session_manager_->local_jid_;
82 message.description.reset( 82 message.description.reset(
83 new ContentDescription(candidate_config_->Clone(), initiator_token_, "")); 83 new ContentDescription(candidate_config_->Clone(), initiator_token_, ""));
84 initiate_request_.reset(session_manager_->CreateIqRequest()); 84 initiate_request_.reset(session_manager_->iq_sender()->SendIq(
85 initiate_request_->set_callback(base::Bind( 85 message.ToXml(),
86 &PepperSession::OnSessionInitiateResponse, base::Unretained(this))); 86 base::Bind(&PepperSession::OnSessionInitiateResponse,
87 initiate_request_->SendIq(message.ToXml()); 87 base::Unretained(this))));
88 88
89 SetState(CONNECTING); 89 SetState(CONNECTING);
90 } 90 }
91 91
92 void PepperSession::OnSessionInitiateResponse( 92 void PepperSession::OnSessionInitiateResponse(
93 const buzz::XmlElement* response) { 93 const buzz::XmlElement* response) {
94 const std::string& type = response->Attr(buzz::QName("", "type")); 94 const std::string& type = response->Attr(buzz::QName("", "type"));
95 if (type != "result") { 95 if (type != "result") {
96 LOG(ERROR) << "Received error in response to session-initiate message: \"" 96 LOG(ERROR) << "Received error in response to session-initiate message: \""
97 << response->Str() 97 << response->Str()
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 } 189 }
190 190
191 void PepperSession::Close() { 191 void PepperSession::Close() {
192 DCHECK(CalledOnValidThread()); 192 DCHECK(CalledOnValidThread());
193 193
194 if (state_ == CONNECTING || state_ == CONNECTED || 194 if (state_ == CONNECTING || state_ == CONNECTED ||
195 state_ == CONNECTED_CHANNELS) { 195 state_ == CONNECTED_CHANNELS) {
196 // Send session-terminate message. 196 // Send session-terminate message.
197 JingleMessage message(peer_jid_, JingleMessage::SESSION_TERMINATE, 197 JingleMessage message(peer_jid_, JingleMessage::SESSION_TERMINATE,
198 session_id_); 198 session_id_);
199 scoped_ptr<IqRequest> terminate_request( 199 scoped_ptr<IqRequest> terminate_request(
200 session_manager_->CreateIqRequest()); 200 session_manager_->iq_sender()->SendIq(
201 terminate_request->SendIq(message.ToXml()); 201 message.ToXml(), IqSender::ReplyCallback()));
202 } 202 }
203 203
204 CloseInternal(false); 204 CloseInternal(false);
205 } 205 }
206 206
207 void PepperSession::OnIncomingMessage(const JingleMessage& message, 207 void PepperSession::OnIncomingMessage(const JingleMessage& message,
208 JingleMessageReply* reply) { 208 JingleMessageReply* reply) {
209 DCHECK(CalledOnValidThread()); 209 DCHECK(CalledOnValidThread());
210 210
211 if (message.from != peer_jid_) { 211 if (message.from != peer_jid_) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 323
324 void PepperSession::OnDeleteChannel(PepperChannel* channel) { 324 void PepperSession::OnDeleteChannel(PepperChannel* channel) {
325 ChannelsMap::iterator it = channels_.find(channel->name()); 325 ChannelsMap::iterator it = channels_.find(channel->name());
326 DCHECK_EQ(it->second, channel); 326 DCHECK_EQ(it->second, channel);
327 channels_.erase(it); 327 channels_.erase(it);
328 } 328 }
329 329
330 void PepperSession::SendTransportInfo() { 330 void PepperSession::SendTransportInfo() {
331 JingleMessage message(peer_jid_, JingleMessage::TRANSPORT_INFO, session_id_); 331 JingleMessage message(peer_jid_, JingleMessage::TRANSPORT_INFO, session_id_);
332 message.candidates.swap(pending_candidates_); 332 message.candidates.swap(pending_candidates_);
333 scoped_ptr<IqRequest> request(session_manager_->CreateIqRequest()); 333 scoped_ptr<IqRequest> request(session_manager_->iq_sender()->SendIq(
334 request->SendIq(message.ToXml()); 334 message.ToXml(), IqSender::ReplyCallback()));
335 } 335 }
336 336
337 void PepperSession::CreateChannels() { 337 void PepperSession::CreateChannels() {
338 CreateStreamChannel( 338 CreateStreamChannel(
339 kControlChannelName, 339 kControlChannelName,
340 base::Bind(&PepperSession::OnChannelConnected, 340 base::Bind(&PepperSession::OnChannelConnected,
341 base::Unretained(this), &control_channel_socket_)); 341 base::Unretained(this), &control_channel_socket_));
342 CreateStreamChannel( 342 CreateStreamChannel(
343 kEventChannelName, 343 kEventChannelName,
344 base::Bind(&PepperSession::OnChannelConnected, 344 base::Bind(&PepperSession::OnChannelConnected,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 DCHECK_NE(state_, FAILED); 383 DCHECK_NE(state_, FAILED);
384 384
385 state_ = new_state; 385 state_ = new_state;
386 if (!state_change_callback_.is_null()) 386 if (!state_change_callback_.is_null())
387 state_change_callback_.Run(new_state); 387 state_change_callback_.Run(new_state);
388 } 388 }
389 } 389 }
390 390
391 } // namespace protocol 391 } // namespace protocol
392 } // namespace remoting 392 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698