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

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

Issue 1064863004: Use base::ResetAndReturn() in remoting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
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/callback_helpers.h"
10 #include "base/rand_util.h" 11 #include "base/rand_util.h"
11 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/stringize_macros.h" 13 #include "base/strings/stringize_macros.h"
13 #include "base/thread_task_runner_handle.h" 14 #include "base/thread_task_runner_handle.h"
14 #include "base/time/time.h" 15 #include "base/time/time.h"
15 #include "remoting/base/constants.h" 16 #include "remoting/base/constants.h"
16 #include "remoting/base/logging.h" 17 #include "remoting/base/logging.h"
17 #include "remoting/host/server_log_entry_host.h" 18 #include "remoting/host/server_log_entry_host.h"
18 #include "remoting/signaling/iq_sender.h" 19 #include "remoting/signaling/iq_sender.h"
19 #include "remoting/signaling/server_log_entry.h" 20 #include "remoting/signaling/server_log_entry.h"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 } 99 }
99 100
100 bool HeartbeatSender::OnSignalStrategyIncomingStanza( 101 bool HeartbeatSender::OnSignalStrategyIncomingStanza(
101 const buzz::XmlElement* stanza) { 102 const buzz::XmlElement* stanza) {
102 return false; 103 return false;
103 } 104 }
104 105
105 void HeartbeatSender::OnHostOfflineReasonTimeout() { 106 void HeartbeatSender::OnHostOfflineReasonTimeout() {
106 DCHECK(!host_offline_reason_ack_callback_.is_null()); 107 DCHECK(!host_offline_reason_ack_callback_.is_null());
107 108
108 base::Callback<void(bool)> local_callback = host_offline_reason_ack_callback_; 109 base::ResetAndReturn(&host_offline_reason_ack_callback_).Run(false);
109 host_offline_reason_ack_callback_.Reset();
110 local_callback.Run(false);
111 } 110 }
112 111
113 void HeartbeatSender::OnHostOfflineReasonAck() { 112 void HeartbeatSender::OnHostOfflineReasonAck() {
114 if (host_offline_reason_ack_callback_.is_null()) { 113 if (host_offline_reason_ack_callback_.is_null()) {
115 DCHECK(!host_offline_reason_timeout_timer_.IsRunning()); 114 DCHECK(!host_offline_reason_timeout_timer_.IsRunning());
116 return; 115 return;
117 } 116 }
118 117
119 DCHECK(host_offline_reason_timeout_timer_.IsRunning()); 118 DCHECK(host_offline_reason_timeout_timer_.IsRunning());
120 host_offline_reason_timeout_timer_.Stop(); 119 host_offline_reason_timeout_timer_.Stop();
121 120
122 // Run the ACK callback under a clean stack via PostTask() (because the 121 // Run the ACK callback under a clean stack via PostTask() (because the
123 // callback can end up deleting |this| HeartbeatSender [i.e. when used from 122 // callback can end up deleting |this| HeartbeatSender [i.e. when used from
124 // HostSignalingManager]). 123 // HostSignalingManager]).
125 base::Closure fully_bound_ack_callback = 124 base::ThreadTaskRunnerHandle::Get()->PostTask(
126 base::Bind(host_offline_reason_ack_callback_, true); 125 FROM_HERE,
127 host_offline_reason_ack_callback_.Reset(); 126 base::Bind(base::ResetAndReturn(&host_offline_reason_ack_callback_),
128 base::ThreadTaskRunnerHandle::Get()->PostTask(FROM_HERE, 127 true));
129 fully_bound_ack_callback);
130 } 128 }
131 129
132 void HeartbeatSender::SetHostOfflineReason( 130 void HeartbeatSender::SetHostOfflineReason(
133 const std::string& host_offline_reason, 131 const std::string& host_offline_reason,
134 const base::TimeDelta& timeout, 132 const base::TimeDelta& timeout,
135 const base::Callback<void(bool success)>& ack_callback) { 133 const base::Callback<void(bool success)>& ack_callback) {
136 DCHECK(thread_checker_.CalledOnValidThread()); 134 DCHECK(thread_checker_.CalledOnValidThread());
137 DCHECK(host_offline_reason_ack_callback_.is_null()); 135 DCHECK(host_offline_reason_ack_callback_.is_null());
138 host_offline_reason_ = host_offline_reason; 136 host_offline_reason_ = host_offline_reason;
139 host_offline_reason_ack_callback_ = ack_callback; 137 host_offline_reason_ack_callback_ = ack_callback;
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 333
336 std::string message = signal_strategy_->GetLocalJid() + ' ' + 334 std::string message = signal_strategy_->GetLocalJid() + ' ' +
337 base::IntToString(sequence_id_); 335 base::IntToString(sequence_id_);
338 std::string signature(host_key_pair_->SignMessage(message)); 336 std::string signature(host_key_pair_->SignMessage(message));
339 signature_tag->AddText(signature); 337 signature_tag->AddText(signature);
340 338
341 return signature_tag.Pass(); 339 return signature_tag.Pass();
342 } 340 }
343 341
344 } // namespace remoting 342 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698