| OLD | NEW |
| 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 30 matching lines...) Expand all Loading... |
| 41 } | 41 } |
| 42 | 42 |
| 43 } // namespace | 43 } // namespace |
| 44 | 44 |
| 45 // static | 45 // static |
| 46 const char KeepAliveDelegate::kHeartbeatPingType[] = "PING"; | 46 const char KeepAliveDelegate::kHeartbeatPingType[] = "PING"; |
| 47 | 47 |
| 48 // static | 48 // static |
| 49 const char KeepAliveDelegate::kHeartbeatPongType[] = "PONG"; | 49 const char KeepAliveDelegate::kHeartbeatPongType[] = "PONG"; |
| 50 | 50 |
| 51 using ::cast_channel::ChannelError; |
| 52 |
| 51 // static | 53 // static |
| 52 CastMessage KeepAliveDelegate::CreateKeepAliveMessage( | 54 CastMessage KeepAliveDelegate::CreateKeepAliveMessage( |
| 53 const char* message_type) { | 55 const char* message_type) { |
| 54 CastMessage output; | 56 CastMessage output; |
| 55 output.set_protocol_version(CastMessage::CASTV2_1_0); | 57 output.set_protocol_version(CastMessage::CASTV2_1_0); |
| 56 output.set_source_id(kPingSenderId); | 58 output.set_source_id(kPingSenderId); |
| 57 output.set_destination_id(kPingReceiverId); | 59 output.set_destination_id(kPingReceiverId); |
| 58 output.set_namespace_(kHeartbeatNamespace); | 60 output.set_namespace_(kHeartbeatNamespace); |
| 59 base::DictionaryValue type_dict; | 61 base::DictionaryValue type_dict; |
| 60 type_dict.SetString(kTypeNodeId, message_type); | 62 type_dict.SetString(kTypeNodeId, message_type); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 base::Unretained(this), message_type)); | 141 base::Unretained(this), message_type)); |
| 140 } | 142 } |
| 141 | 143 |
| 142 void KeepAliveDelegate::SendKeepAliveMessageComplete(const char* message_type, | 144 void KeepAliveDelegate::SendKeepAliveMessageComplete(const char* message_type, |
| 143 int rv) { | 145 int rv) { |
| 144 VLOG(2) << "Sending " << message_type << " complete, rv=" << rv; | 146 VLOG(2) << "Sending " << message_type << " complete, rv=" << rv; |
| 145 if (rv != net::OK) { | 147 if (rv != net::OK) { |
| 146 // An error occurred while sending the ping response. | 148 // An error occurred while sending the ping response. |
| 147 VLOG(1) << "Error sending " << message_type; | 149 VLOG(1) << "Error sending " << message_type; |
| 148 logger_->LogSocketEventWithRv(socket_->id(), proto::PING_WRITE_ERROR, rv); | 150 logger_->LogSocketEventWithRv(socket_->id(), proto::PING_WRITE_ERROR, rv); |
| 149 OnError(cast_channel::CHANNEL_ERROR_SOCKET_ERROR); | 151 OnError(ChannelError::SOCKET_ERROR); |
| 150 } | 152 } |
| 151 } | 153 } |
| 152 | 154 |
| 153 void KeepAliveDelegate::LivenessTimeout() { | 155 void KeepAliveDelegate::LivenessTimeout() { |
| 154 OnError(cast_channel::CHANNEL_ERROR_PING_TIMEOUT); | 156 OnError(ChannelError::PING_TIMEOUT); |
| 155 Stop(); | 157 Stop(); |
| 156 } | 158 } |
| 157 | 159 |
| 158 // CastTransport::Delegate interface. | 160 // CastTransport::Delegate interface. |
| 159 void KeepAliveDelegate::OnError(ChannelError error_state) { | 161 void KeepAliveDelegate::OnError(ChannelError error_state) { |
| 160 DCHECK(thread_checker_.CalledOnValidThread()); | 162 DCHECK(thread_checker_.CalledOnValidThread()); |
| 161 VLOG(1) << "KeepAlive::OnError: " << error_state; | 163 VLOG(1) << "KeepAlive::OnError: " |
| 164 << ::cast_channel::ChannelErrorToString(error_state); |
| 162 inner_delegate_->OnError(error_state); | 165 inner_delegate_->OnError(error_state); |
| 163 Stop(); | 166 Stop(); |
| 164 } | 167 } |
| 165 | 168 |
| 166 void KeepAliveDelegate::OnMessage(const CastMessage& message) { | 169 void KeepAliveDelegate::OnMessage(const CastMessage& message) { |
| 167 DCHECK(thread_checker_.CalledOnValidThread()); | 170 DCHECK(thread_checker_.CalledOnValidThread()); |
| 168 VLOG(2) << "KeepAlive::OnMessage : " << message.payload_utf8(); | 171 VLOG(2) << "KeepAlive::OnMessage : " << message.payload_utf8(); |
| 169 | 172 |
| 170 if (started_) | 173 if (started_) |
| 171 ResetTimers(); | 174 ResetTimers(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 188 if (started_) { | 191 if (started_) { |
| 189 started_ = false; | 192 started_ = false; |
| 190 ping_timer_->Stop(); | 193 ping_timer_->Stop(); |
| 191 liveness_timer_->Stop(); | 194 liveness_timer_->Stop(); |
| 192 } | 195 } |
| 193 } | 196 } |
| 194 | 197 |
| 195 } // namespace cast_channel | 198 } // namespace cast_channel |
| 196 } // namespace api | 199 } // namespace api |
| 197 } // namespace extensions | 200 } // namespace extensions |
| OLD | NEW |