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

Side by Side Diff: remoting/host/heartbeat_sender.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/host/heartbeat_sender.h" 5 #include "remoting/host/heartbeat_sender.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/message_loop_proxy.h" 9 #include "base/message_loop_proxy.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "remoting/base/constants.h" 12 #include "remoting/base/constants.h"
13 #include "remoting/host/host_config.h" 13 #include "remoting/host/host_config.h"
14 #include "remoting/jingle_glue/iq_request.h" 14 #include "remoting/jingle_glue/iq_sender.h"
15 #include "remoting/jingle_glue/jingle_thread.h" 15 #include "remoting/jingle_glue/jingle_thread.h"
16 #include "remoting/jingle_glue/signal_strategy.h" 16 #include "remoting/jingle_glue/signal_strategy.h"
17 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" 17 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h"
18 #include "third_party/libjingle/source/talk/xmpp/constants.h" 18 #include "third_party/libjingle/source/talk/xmpp/constants.h"
19 19
20 using buzz::QName; 20 using buzz::QName;
21 using buzz::XmlElement; 21 using buzz::XmlElement;
22 22
23 namespace remoting { 23 namespace remoting {
24 24
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 return true; 65 return true;
66 } 66 }
67 67
68 void HeartbeatSender::OnSignallingConnected(SignalStrategy* signal_strategy, 68 void HeartbeatSender::OnSignallingConnected(SignalStrategy* signal_strategy,
69 const std::string& full_jid) { 69 const std::string& full_jid) {
70 DCHECK(message_loop_->BelongsToCurrentThread()); 70 DCHECK(message_loop_->BelongsToCurrentThread());
71 DCHECK(state_ == INITIALIZED || state_ == STOPPED); 71 DCHECK(state_ == INITIALIZED || state_ == STOPPED);
72 state_ = STARTED; 72 state_ = STARTED;
73 73
74 full_jid_ = full_jid; 74 full_jid_ = full_jid;
75 request_.reset(signal_strategy->CreateIqRequest()); 75
76 request_->set_callback(base::Bind(&HeartbeatSender::ProcessResponse, 76 iq_sender_.reset(new IqSender(signal_strategy));
77 base::Unretained(this)));
78 77
79 DoSendStanza(); 78 DoSendStanza();
80 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(interval_ms_), this, 79 timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(interval_ms_), this,
81 &HeartbeatSender::DoSendStanza); 80 &HeartbeatSender::DoSendStanza);
82 } 81 }
83 82
84 void HeartbeatSender::OnSignallingDisconnected() { 83 void HeartbeatSender::OnSignallingDisconnected() {
85 DCHECK(message_loop_->BelongsToCurrentThread()); 84 DCHECK(message_loop_->BelongsToCurrentThread());
86 state_ = STOPPED; 85 state_ = STOPPED;
87 request_.reset(NULL); 86 request_.reset();
87 iq_sender_.reset();
88 } 88 }
89 89
90 // Ignore any notifications other than signalling 90 // Ignore any notifications other than signalling
91 // connected/disconnected events. 91 // connected/disconnected events.
92 void HeartbeatSender::OnAccessDenied() { } 92 void HeartbeatSender::OnAccessDenied() { }
93 void HeartbeatSender::OnClientAuthenticated(const std::string& jid) { } 93 void HeartbeatSender::OnClientAuthenticated(const std::string& jid) { }
94 void HeartbeatSender::OnClientDisconnected(const std::string& jid) { } 94 void HeartbeatSender::OnClientDisconnected(const std::string& jid) { }
95 void HeartbeatSender::OnShutdown() { } 95 void HeartbeatSender::OnShutdown() { }
96 96
97 void HeartbeatSender::DoSendStanza() { 97 void HeartbeatSender::DoSendStanza() {
98 DCHECK(message_loop_->BelongsToCurrentThread()); 98 DCHECK(message_loop_->BelongsToCurrentThread());
99 DCHECK_EQ(state_, STARTED); 99 DCHECK_EQ(state_, STARTED);
100 100
101 VLOG(1) << "Sending heartbeat stanza to " << kChromotingBotJid; 101 VLOG(1) << "Sending heartbeat stanza to " << kChromotingBotJid;
102 request_->SendIq(IqRequest::MakeIqStanza( 102 request_.reset(iq_sender_->SendIq(
103 buzz::STR_SET, kChromotingBotJid, CreateHeartbeatMessage())); 103 buzz::STR_SET, kChromotingBotJid, CreateHeartbeatMessage(),
104 base::Bind(&HeartbeatSender::ProcessResponse,
105 base::Unretained(this))));
104 } 106 }
105 107
106 void HeartbeatSender::ProcessResponse(const XmlElement* response) { 108 void HeartbeatSender::ProcessResponse(const XmlElement* response) {
107 DCHECK(message_loop_->BelongsToCurrentThread()); 109 DCHECK(message_loop_->BelongsToCurrentThread());
108 110
109 std::string type = response->Attr(buzz::QN_TYPE); 111 std::string type = response->Attr(buzz::QN_TYPE);
110 if (type == buzz::STR_ERROR) { 112 if (type == buzz::STR_ERROR) {
111 LOG(ERROR) << "Received error in response to heartbeat: " 113 LOG(ERROR) << "Received error in response to heartbeat: "
112 << response->Str(); 114 << response->Str();
113 return; 115 return;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str); 168 QName(kChromotingXmlNamespace, kSignatureTimeAttr), time_str);
167 169
168 std::string message = full_jid_ + ' ' + time_str; 170 std::string message = full_jid_ + ' ' + time_str;
169 std::string signature(key_pair_.GetSignature(message)); 171 std::string signature(key_pair_.GetSignature(message));
170 signature_tag->AddText(signature); 172 signature_tag->AddText(signature);
171 173
172 return signature_tag; 174 return signature_tag;
173 } 175 }
174 176
175 } // namespace remoting 177 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698