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

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

Issue 1902873002: Convert //extensions/browser/api from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 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 18 matching lines...) Expand all
29 // Determines if the JSON-encoded payload is equivalent to 29 // Determines if the JSON-encoded payload is equivalent to
30 // { "type": |chk_type| } 30 // { "type": |chk_type| }
31 bool NestedPayloadTypeEquals(const std::string& chk_type, 31 bool NestedPayloadTypeEquals(const std::string& chk_type,
32 const CastMessage& message) { 32 const CastMessage& message) {
33 MessageInfo message_info; 33 MessageInfo message_info;
34 CastMessageToMessageInfo(message, &message_info); 34 CastMessageToMessageInfo(message, &message_info);
35 std::string type_json; 35 std::string type_json;
36 if (!message_info.data->GetAsString(&type_json)) { 36 if (!message_info.data->GetAsString(&type_json)) {
37 return false; 37 return false;
38 } 38 }
39 scoped_ptr<base::Value> type_value(base::JSONReader::Read(type_json)); 39 std::unique_ptr<base::Value> type_value(base::JSONReader::Read(type_json));
40 if (!type_value.get()) { 40 if (!type_value.get()) {
41 return false; 41 return false;
42 } 42 }
43 43
44 base::DictionaryValue* type_dict; 44 base::DictionaryValue* type_dict;
45 if (!type_value->GetAsDictionary(&type_dict)) { 45 if (!type_value->GetAsDictionary(&type_dict)) {
46 return false; 46 return false;
47 } 47 }
48 48
49 std::string type_string; 49 std::string type_string;
(...skipping 25 matching lines...) Expand all
75 return output; 75 return output;
76 } 76 }
77 output.set_payload_type( 77 output.set_payload_type(
78 CastMessage::PayloadType::CastMessage_PayloadType_STRING); 78 CastMessage::PayloadType::CastMessage_PayloadType_STRING);
79 return output; 79 return output;
80 } 80 }
81 81
82 KeepAliveDelegate::KeepAliveDelegate( 82 KeepAliveDelegate::KeepAliveDelegate(
83 CastSocket* socket, 83 CastSocket* socket,
84 scoped_refptr<Logger> logger, 84 scoped_refptr<Logger> logger,
85 scoped_ptr<CastTransport::Delegate> inner_delegate, 85 std::unique_ptr<CastTransport::Delegate> inner_delegate,
86 base::TimeDelta ping_interval, 86 base::TimeDelta ping_interval,
87 base::TimeDelta liveness_timeout) 87 base::TimeDelta liveness_timeout)
88 : started_(false), 88 : started_(false),
89 socket_(socket), 89 socket_(socket),
90 logger_(logger), 90 logger_(logger),
91 inner_delegate_(std::move(inner_delegate)), 91 inner_delegate_(std::move(inner_delegate)),
92 liveness_timeout_(liveness_timeout), 92 liveness_timeout_(liveness_timeout),
93 ping_interval_(ping_interval) { 93 ping_interval_(ping_interval) {
94 DCHECK(ping_interval_ < liveness_timeout_); 94 DCHECK(ping_interval_ < liveness_timeout_);
95 DCHECK(inner_delegate_); 95 DCHECK(inner_delegate_);
96 DCHECK(socket_); 96 DCHECK(socket_);
97 ping_message_ = CreateKeepAliveMessage(kHeartbeatPingType); 97 ping_message_ = CreateKeepAliveMessage(kHeartbeatPingType);
98 pong_message_ = CreateKeepAliveMessage(kHeartbeatPongType); 98 pong_message_ = CreateKeepAliveMessage(kHeartbeatPongType);
99 } 99 }
100 100
101 KeepAliveDelegate::~KeepAliveDelegate() { 101 KeepAliveDelegate::~KeepAliveDelegate() {
102 } 102 }
103 103
104 void KeepAliveDelegate::SetTimersForTest( 104 void KeepAliveDelegate::SetTimersForTest(
105 scoped_ptr<base::Timer> injected_ping_timer, 105 std::unique_ptr<base::Timer> injected_ping_timer,
106 scoped_ptr<base::Timer> injected_liveness_timer) { 106 std::unique_ptr<base::Timer> injected_liveness_timer) {
107 ping_timer_ = std::move(injected_ping_timer); 107 ping_timer_ = std::move(injected_ping_timer);
108 liveness_timer_ = std::move(injected_liveness_timer); 108 liveness_timer_ = std::move(injected_liveness_timer);
109 } 109 }
110 110
111 void KeepAliveDelegate::Start() { 111 void KeepAliveDelegate::Start() {
112 DCHECK(thread_checker_.CalledOnValidThread()); 112 DCHECK(thread_checker_.CalledOnValidThread());
113 DCHECK(!started_); 113 DCHECK(!started_);
114 114
115 VLOG(1) << "Starting keep-alive timers."; 115 VLOG(1) << "Starting keep-alive timers.";
116 VLOG(1) << "Ping timeout: " << ping_interval_; 116 VLOG(1) << "Ping timeout: " << ping_interval_;
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 if (started_) { 197 if (started_) {
198 started_ = false; 198 started_ = false;
199 ping_timer_->Stop(); 199 ping_timer_->Stop();
200 liveness_timer_->Stop(); 200 liveness_timer_->Stop();
201 } 201 }
202 } 202 }
203 203
204 } // namespace cast_channel 204 } // namespace cast_channel
205 } // namespace api 205 } // namespace api
206 } // namespace extensions 206 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698