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

Side by Side Diff: extensions/browser/api/cast_channel/keep_alive_delegate.cc

Issue 2609503002: Fix cast_channel::KeepAliveDelegate DCHECK failure. (Closed)
Patch Set: Created 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "extensions/browser/api/cast_channel/keep_alive_delegate.h" 5 #include "extensions/browser/api/cast_channel/keep_alive_delegate.h"
6 6
7 #include <string> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/json/json_reader.h" 10 #include "base/json/json_reader.h"
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 169
170 // CastTransport::Delegate interface. 170 // CastTransport::Delegate interface.
171 void KeepAliveDelegate::OnError(ChannelError error_state) { 171 void KeepAliveDelegate::OnError(ChannelError error_state) {
172 DCHECK(thread_checker_.CalledOnValidThread()); 172 DCHECK(thread_checker_.CalledOnValidThread());
173 VLOG(1) << "KeepAlive::OnError: " << error_state; 173 VLOG(1) << "KeepAlive::OnError: " << error_state;
174 inner_delegate_->OnError(error_state); 174 inner_delegate_->OnError(error_state);
175 Stop(); 175 Stop();
176 } 176 }
177 177
178 void KeepAliveDelegate::OnMessage(const CastMessage& message) { 178 void KeepAliveDelegate::OnMessage(const CastMessage& message) {
179 DCHECK(started_);
180 DCHECK(thread_checker_.CalledOnValidThread()); 179 DCHECK(thread_checker_.CalledOnValidThread());
181 VLOG(2) << "KeepAlive::OnMessage : " << message.payload_utf8(); 180 VLOG(2) << "KeepAlive::OnMessage : " << message.payload_utf8();
182 181
183 ResetTimers(); 182 if (started_) {
183 ResetTimers();
184 184
185 if (NestedPayloadTypeEquals(kHeartbeatPingType, message)) { 185 if (NestedPayloadTypeEquals(kHeartbeatPingType, message)) {
186 VLOG(2) << "Received PING."; 186 VLOG(2) << "Received PING.";
187 SendKeepAliveMessage(pong_message_, kHeartbeatPongType); 187 SendKeepAliveMessage(pong_message_, kHeartbeatPongType);
188 } else if (NestedPayloadTypeEquals(kHeartbeatPongType, message)) { 188 return;
189 VLOG(2) << "Received PONG."; 189 } else if (NestedPayloadTypeEquals(kHeartbeatPongType, message)) {
190 VLOG(2) << "Received PONG.";
191 return;
192 }
190 } else { 193 } else {
191 // PING and PONG messages are intentionally suppressed from layers above. 194 if (NestedPayloadTypeEquals(kHeartbeatPingType, message) ||
192 inner_delegate_->OnMessage(message); 195 NestedPayloadTypeEquals(kHeartbeatPongType, message)) {
196 VLOG(2) << "Received PING or PONG before starting or after stopping.";
197 return;
198 }
193 } 199 }
200
201 // PING and PONG messages are intentionally suppressed from layers above.
Wez 2017/01/04 00:10:17 nit: This comment is not very clear, especially af
miu 2017/01/12 22:31:27 Done. Looking at this code again, I also couldn't
Wez 2017/01/13 22:37:11 Nice :)
202 inner_delegate_->OnMessage(message);
194 } 203 }
195 204
196 void KeepAliveDelegate::Stop() { 205 void KeepAliveDelegate::Stop() {
197 if (started_) { 206 if (started_) {
198 started_ = false; 207 started_ = false;
199 ping_timer_->Stop(); 208 ping_timer_->Stop();
200 liveness_timer_->Stop(); 209 liveness_timer_->Stop();
201 } 210 }
202 } 211 }
203 212
204 } // namespace cast_channel 213 } // namespace cast_channel
205 } // namespace api 214 } // namespace api
206 } // namespace extensions 215 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698