| 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 "components/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" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "extensions/browser/api/cast_channel/cast_socket.h" | 12 #include "base/values.h" |
| 13 #include "extensions/browser/api/cast_channel/logger.h" | 13 #include "components/cast_channel/cast_socket.h" |
| 14 #include "extensions/common/api/cast_channel/cast_channel.pb.h" | 14 #include "components/cast_channel/logger.h" |
| 15 #include "extensions/common/api/cast_channel/logging.pb.h" | 15 #include "components/cast_channel/proto/cast_channel.pb.h" |
| 16 #include "components/cast_channel/proto/logging.pb.h" |
| 16 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 17 | 18 |
| 18 namespace extensions { | |
| 19 namespace api { | |
| 20 namespace cast_channel { | 19 namespace cast_channel { |
| 21 namespace { | 20 namespace { |
| 22 | 21 |
| 23 const char kHeartbeatNamespace[] = "urn:x-cast:com.google.cast.tp.heartbeat"; | 22 const char kHeartbeatNamespace[] = "urn:x-cast:com.google.cast.tp.heartbeat"; |
| 24 const char kPingSenderId[] = "chrome"; | 23 const char kPingSenderId[] = "chrome"; |
| 25 const char kPingReceiverId[] = "receiver-0"; | 24 const char kPingReceiverId[] = "receiver-0"; |
| 26 const char kTypeNodeId[] = "type"; | 25 const char kTypeNodeId[] = "type"; |
| 27 | 26 |
| 28 // Parses the JSON-encoded payload of |message| and returns the value in the | 27 // Parses the JSON-encoded payload of |message| and returns the value in the |
| 29 // "type" field or the empty string if the parse fails or the field is not | 28 // "type" field or the empty string if the parse fails or the field is not |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 inner_delegate_(std::move(inner_delegate)), | 80 inner_delegate_(std::move(inner_delegate)), |
| 82 liveness_timeout_(liveness_timeout), | 81 liveness_timeout_(liveness_timeout), |
| 83 ping_interval_(ping_interval) { | 82 ping_interval_(ping_interval) { |
| 84 DCHECK(ping_interval_ < liveness_timeout_); | 83 DCHECK(ping_interval_ < liveness_timeout_); |
| 85 DCHECK(inner_delegate_); | 84 DCHECK(inner_delegate_); |
| 86 DCHECK(socket_); | 85 DCHECK(socket_); |
| 87 ping_message_ = CreateKeepAliveMessage(kHeartbeatPingType); | 86 ping_message_ = CreateKeepAliveMessage(kHeartbeatPingType); |
| 88 pong_message_ = CreateKeepAliveMessage(kHeartbeatPongType); | 87 pong_message_ = CreateKeepAliveMessage(kHeartbeatPongType); |
| 89 } | 88 } |
| 90 | 89 |
| 91 KeepAliveDelegate::~KeepAliveDelegate() { | 90 KeepAliveDelegate::~KeepAliveDelegate() {} |
| 92 } | |
| 93 | 91 |
| 94 void KeepAliveDelegate::SetTimersForTest( | 92 void KeepAliveDelegate::SetTimersForTest( |
| 95 std::unique_ptr<base::Timer> injected_ping_timer, | 93 std::unique_ptr<base::Timer> injected_ping_timer, |
| 96 std::unique_ptr<base::Timer> injected_liveness_timer) { | 94 std::unique_ptr<base::Timer> injected_liveness_timer) { |
| 97 ping_timer_ = std::move(injected_ping_timer); | 95 ping_timer_ = std::move(injected_ping_timer); |
| 98 liveness_timer_ = std::move(injected_liveness_timer); | 96 liveness_timer_ = std::move(injected_liveness_timer); |
| 99 } | 97 } |
| 100 | 98 |
| 101 void KeepAliveDelegate::Start() { | 99 void KeepAliveDelegate::Start() { |
| 102 DCHECK(thread_checker_.CalledOnValidThread()); | 100 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 | 187 |
| 190 void KeepAliveDelegate::Stop() { | 188 void KeepAliveDelegate::Stop() { |
| 191 if (started_) { | 189 if (started_) { |
| 192 started_ = false; | 190 started_ = false; |
| 193 ping_timer_->Stop(); | 191 ping_timer_->Stop(); |
| 194 liveness_timer_->Stop(); | 192 liveness_timer_->Stop(); |
| 195 } | 193 } |
| 196 } | 194 } |
| 197 | 195 |
| 198 } // namespace cast_channel | 196 } // namespace cast_channel |
| 199 } // namespace api | |
| 200 } // namespace extensions | |
| OLD | NEW |