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

Side by Side Diff: remoting/host/heartbeat_sender.cc

Issue 734053003: Reporting of policy errors via host-offline-reason: part 2b (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@hor-nohoststatussender
Patch Set: Addressed CR feedback from Lambros. Created 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <math.h> 7 #include <math.h>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/message_loop/message_loop_proxy.h" 10 #include "base/message_loop/message_loop_proxy.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 const char kExpectedSequenceIdTag[] = "expected-sequence-id"; 43 const char kExpectedSequenceIdTag[] = "expected-sequence-id";
44 44
45 const int64 kDefaultHeartbeatIntervalMs = 5 * 60 * 1000; // 5 minutes. 45 const int64 kDefaultHeartbeatIntervalMs = 5 * 60 * 1000; // 5 minutes.
46 const int64 kResendDelayMs = 10 * 1000; // 10 seconds. 46 const int64 kResendDelayMs = 10 * 1000; // 10 seconds.
47 const int64 kResendDelayOnHostNotFoundMs = 10 * 1000; // 10 seconds. 47 const int64 kResendDelayOnHostNotFoundMs = 10 * 1000; // 10 seconds.
48 const int kMaxResendOnHostNotFoundCount = 12; // 2 minutes (12 x 10 seconds). 48 const int kMaxResendOnHostNotFoundCount = 12; // 2 minutes (12 x 10 seconds).
49 49
50 } // namespace 50 } // namespace
51 51
52 HeartbeatSender::HeartbeatSender( 52 HeartbeatSender::HeartbeatSender(
53 Listener* listener, 53 const base::Closure& on_heartbeat_successful_callback,
54 const base::Closure& on_unknown_host_id_error,
54 const std::string& host_id, 55 const std::string& host_id,
55 SignalStrategy* signal_strategy, 56 SignalStrategy* signal_strategy,
56 scoped_refptr<RsaKeyPair> key_pair, 57 scoped_refptr<RsaKeyPair> key_pair,
57 const std::string& directory_bot_jid) 58 const std::string& directory_bot_jid)
58 : listener_(listener), 59 : on_heartbeat_successful_callback_(on_heartbeat_successful_callback),
60 on_unknown_host_id_error_(on_unknown_host_id_error),
59 host_id_(host_id), 61 host_id_(host_id),
60 signal_strategy_(signal_strategy), 62 signal_strategy_(signal_strategy),
61 key_pair_(key_pair), 63 key_pair_(key_pair),
62 directory_bot_jid_(directory_bot_jid), 64 directory_bot_jid_(directory_bot_jid),
63 interval_ms_(kDefaultHeartbeatIntervalMs), 65 interval_ms_(kDefaultHeartbeatIntervalMs),
64 sequence_id_(0), 66 sequence_id_(0),
65 sequence_id_was_set_(false), 67 sequence_id_was_set_(false),
66 sequence_id_recent_set_num_(0), 68 sequence_id_recent_set_num_(0),
67 heartbeat_succeeded_(false), 69 heartbeat_succeeded_(false),
68 failed_startup_heartbeat_count_(0) { 70 failed_startup_heartbeat_count_(0) {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 failed_startup_heartbeat_count_++; 162 failed_startup_heartbeat_count_++;
161 if (!heartbeat_succeeded_ && (failed_startup_heartbeat_count_ <= 163 if (!heartbeat_succeeded_ && (failed_startup_heartbeat_count_ <=
162 kMaxResendOnHostNotFoundCount)) { 164 kMaxResendOnHostNotFoundCount)) {
163 timer_resend_.Start(FROM_HERE, 165 timer_resend_.Start(FROM_HERE,
164 base::TimeDelta::FromMilliseconds( 166 base::TimeDelta::FromMilliseconds(
165 kResendDelayOnHostNotFoundMs), 167 kResendDelayOnHostNotFoundMs),
166 this, 168 this,
167 &HeartbeatSender::ResendStanza); 169 &HeartbeatSender::ResendStanza);
168 return; 170 return;
169 } 171 }
170 listener_->OnUnknownHostIdError(); 172 on_unknown_host_id_error_.Run();
171 return; 173 return;
172 } 174 }
173 } 175 }
174 176
175 LOG(ERROR) << "Received error in response to heartbeat: " 177 LOG(ERROR) << "Received error in response to heartbeat: "
176 << response->Str(); 178 << response->Str();
177 return; 179 return;
178 } 180 }
179 181
180 // This method must only be called for error or result stanzas. 182 // This method must only be called for error or result stanzas.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 sequence_id_recent_set_num_++; 217 sequence_id_recent_set_num_++;
216 did_set_sequence_id = true; 218 did_set_sequence_id = true;
217 } 219 }
218 } 220 }
219 if (!did_set_sequence_id) { 221 if (!did_set_sequence_id) {
220 // It seems the bot accepted our signature and our message. 222 // It seems the bot accepted our signature and our message.
221 sequence_id_recent_set_num_ = 0; 223 sequence_id_recent_set_num_ = 0;
222 224
223 // Notify listener of the first successful heartbeat. 225 // Notify listener of the first successful heartbeat.
224 if (!heartbeat_succeeded_) { 226 if (!heartbeat_succeeded_) {
225 listener_->OnHeartbeatSuccessful(); 227 on_heartbeat_successful_callback_.Run();
226 } 228 }
227 heartbeat_succeeded_ = true; 229 heartbeat_succeeded_ = true;
228 230
229 // Notify caller of SetHostOfflineReason that we got an ack. 231 // Notify caller of SetHostOfflineReason that we got an ack.
230 if (is_offline_heartbeat_response) { 232 if (is_offline_heartbeat_response) {
231 if (!host_offline_reason_ack_callback_.is_null()) { 233 if (!host_offline_reason_ack_callback_.is_null()) {
232 base::MessageLoop::current()->PostTask( 234 base::MessageLoop::current()->PostTask(
233 FROM_HERE, 235 FROM_HERE,
234 host_offline_reason_ack_callback_); 236 host_offline_reason_ack_callback_);
235 host_offline_reason_ack_callback_.Reset(); 237 host_offline_reason_ack_callback_.Reset();
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 310
309 std::string message = signal_strategy_->GetLocalJid() + ' ' + 311 std::string message = signal_strategy_->GetLocalJid() + ' ' +
310 base::IntToString(sequence_id_); 312 base::IntToString(sequence_id_);
311 std::string signature(key_pair_->SignMessage(message)); 313 std::string signature(key_pair_->SignMessage(message));
312 signature_tag->AddText(signature); 314 signature_tag->AddText(signature);
313 315
314 return signature_tag.Pass(); 316 return signature_tag.Pass();
315 } 317 }
316 318
317 } // namespace remoting 319 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698