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

Side by Side Diff: extensions/browser/api/cast_channel/cast_socket.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/cast_socket.h" 5 #include "extensions/browser/api/cast_channel/cast_socket.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 #include <string.h> 8 #include <string.h>
9
9 #include <utility> 10 #include <utility>
10 11
11 #include "base/bind.h" 12 #include "base/bind.h"
12 #include "base/callback_helpers.h" 13 #include "base/callback_helpers.h"
13 #include "base/format_macros.h" 14 #include "base/format_macros.h"
14 #include "base/lazy_instance.h" 15 #include "base/lazy_instance.h"
16 #include "base/memory/ptr_util.h"
15 #include "base/message_loop/message_loop.h" 17 #include "base/message_loop/message_loop.h"
16 #include "base/numerics/safe_conversions.h" 18 #include "base/numerics/safe_conversions.h"
17 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
18 #include "base/strings/stringprintf.h" 20 #include "base/strings/stringprintf.h"
19 #include "base/sys_byteorder.h" 21 #include "base/sys_byteorder.h"
20 #include "base/time/time.h" 22 #include "base/time/time.h"
21 #include "extensions/browser/api/cast_channel/cast_auth_util.h" 23 #include "extensions/browser/api/cast_channel/cast_auth_util.h"
22 #include "extensions/browser/api/cast_channel/cast_framer.h" 24 #include "extensions/browser/api/cast_channel/cast_framer.h"
23 #include "extensions/browser/api/cast_channel/cast_message_util.h" 25 #include "extensions/browser/api/cast_channel/cast_message_util.h"
24 #include "extensions/browser/api/cast_channel/cast_transport.h" 26 #include "extensions/browser/api/cast_channel/cast_transport.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 FakeCertVerifier() {} 78 FakeCertVerifier() {}
77 ~FakeCertVerifier() override {} 79 ~FakeCertVerifier() override {}
78 80
79 int Verify(net::X509Certificate* cert, 81 int Verify(net::X509Certificate* cert,
80 const std::string&, 82 const std::string&,
81 const std::string&, 83 const std::string&,
82 int, 84 int,
83 net::CRLSet*, 85 net::CRLSet*,
84 net::CertVerifyResult* verify_result, 86 net::CertVerifyResult* verify_result,
85 const net::CompletionCallback&, 87 const net::CompletionCallback&,
86 scoped_ptr<net::CertVerifier::Request>*, 88 std::unique_ptr<net::CertVerifier::Request>*,
87 const net::BoundNetLog&) override { 89 const net::BoundNetLog&) override {
88 verify_result->Reset(); 90 verify_result->Reset();
89 verify_result->verified_cert = cert; 91 verify_result->verified_cert = cert;
90 return net::OK; 92 return net::OK;
91 } 93 }
92 }; 94 };
93 95
94 } // namespace 96 } // namespace
95 97
96 CastSocket::CastSocket(const std::string& owner_extension_id) 98 CastSocket::CastSocket(const std::string& owner_extension_id)
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 } 166 }
165 167
166 bool CastSocketImpl::keep_alive() const { 168 bool CastSocketImpl::keep_alive() const {
167 return keep_alive_; 169 return keep_alive_;
168 } 170 }
169 171
170 bool CastSocketImpl::audio_only() const { 172 bool CastSocketImpl::audio_only() const {
171 return audio_only_; 173 return audio_only_;
172 } 174 }
173 175
174 scoped_ptr<net::TCPClientSocket> CastSocketImpl::CreateTcpSocket() { 176 std::unique_ptr<net::TCPClientSocket> CastSocketImpl::CreateTcpSocket() {
175 net::AddressList addresses(ip_endpoint_); 177 net::AddressList addresses(ip_endpoint_);
176 return scoped_ptr<net::TCPClientSocket>( 178 return std::unique_ptr<net::TCPClientSocket>(
177 new net::TCPClientSocket(addresses, nullptr, net_log_, net_log_source_)); 179 new net::TCPClientSocket(addresses, nullptr, net_log_, net_log_source_));
178 // Options cannot be set on the TCPClientSocket yet, because the 180 // Options cannot be set on the TCPClientSocket yet, because the
179 // underlying platform socket will not be created until Bind() 181 // underlying platform socket will not be created until Bind()
180 // or Connect() is called. 182 // or Connect() is called.
181 } 183 }
182 184
183 scoped_ptr<net::SSLClientSocket> CastSocketImpl::CreateSslSocket( 185 std::unique_ptr<net::SSLClientSocket> CastSocketImpl::CreateSslSocket(
184 scoped_ptr<net::StreamSocket> socket) { 186 std::unique_ptr<net::StreamSocket> socket) {
185 net::SSLConfig ssl_config; 187 net::SSLConfig ssl_config;
186 cert_verifier_ = make_scoped_ptr(new FakeCertVerifier); 188 cert_verifier_ = base::WrapUnique(new FakeCertVerifier);
187 transport_security_state_.reset(new net::TransportSecurityState); 189 transport_security_state_.reset(new net::TransportSecurityState);
188 net::SSLClientSocketContext context; 190 net::SSLClientSocketContext context;
189 // CertVerifier and TransportSecurityState are owned by us, not the 191 // CertVerifier and TransportSecurityState are owned by us, not the
190 // context object. 192 // context object.
191 context.cert_verifier = cert_verifier_.get(); 193 context.cert_verifier = cert_verifier_.get();
192 context.transport_security_state = transport_security_state_.get(); 194 context.transport_security_state = transport_security_state_.get();
193 195
194 scoped_ptr<net::ClientSocketHandle> connection(new net::ClientSocketHandle); 196 std::unique_ptr<net::ClientSocketHandle> connection(
197 new net::ClientSocketHandle);
195 connection->SetSocket(std::move(socket)); 198 connection->SetSocket(std::move(socket));
196 net::HostPortPair host_and_port = net::HostPortPair::FromIPEndPoint( 199 net::HostPortPair host_and_port = net::HostPortPair::FromIPEndPoint(
197 ip_endpoint_); 200 ip_endpoint_);
198 201
199 return net::ClientSocketFactory::GetDefaultFactory()->CreateSSLClientSocket( 202 return net::ClientSocketFactory::GetDefaultFactory()->CreateSSLClientSocket(
200 std::move(connection), host_and_port, ssl_config, context); 203 std::move(connection), host_and_port, ssl_config, context);
201 } 204 }
202 205
203 scoped_refptr<net::X509Certificate> CastSocketImpl::ExtractPeerCert() { 206 scoped_refptr<net::X509Certificate> CastSocketImpl::ExtractPeerCert() {
204 net::SSLInfo ssl_info; 207 net::SSLInfo ssl_info;
(...skipping 27 matching lines...) Expand all
232 if (result.success()) { 235 if (result.success()) {
233 VLOG(1) << result.error_message; 236 VLOG(1) << result.error_message;
234 if (!VerifyChannelPolicy(result)) { 237 if (!VerifyChannelPolicy(result)) {
235 return false; 238 return false;
236 } 239 }
237 } 240 }
238 return result.success(); 241 return result.success();
239 } 242 }
240 243
241 void CastSocketImpl::SetTransportForTesting( 244 void CastSocketImpl::SetTransportForTesting(
242 scoped_ptr<CastTransport> transport) { 245 std::unique_ptr<CastTransport> transport) {
243 transport_ = std::move(transport); 246 transport_ = std::move(transport);
244 } 247 }
245 248
246 void CastSocketImpl::Connect(scoped_ptr<CastTransport::Delegate> delegate, 249 void CastSocketImpl::Connect(std::unique_ptr<CastTransport::Delegate> delegate,
247 base::Callback<void(ChannelError)> callback) { 250 base::Callback<void(ChannelError)> callback) {
248 DCHECK(CalledOnValidThread()); 251 DCHECK(CalledOnValidThread());
249 VLOG_WITH_CONNECTION(1) << "Connect readyState = " << ready_state_; 252 VLOG_WITH_CONNECTION(1) << "Connect readyState = " << ready_state_;
250 DCHECK_EQ(proto::CONN_STATE_START_CONNECT, connect_state_); 253 DCHECK_EQ(proto::CONN_STATE_START_CONNECT, connect_state_);
251 254
252 delegate_ = std::move(delegate); 255 delegate_ = std::move(delegate);
253 256
254 if (ready_state_ != READY_STATE_NONE) { 257 if (ready_state_ != READY_STATE_NONE) {
255 logger_->LogSocketEventWithDetails( 258 logger_->LogSocketEventWithDetails(
256 channel_id_, proto::CONNECT_FAILED, "ReadyState not NONE"); 259 channel_id_, proto::CONNECT_FAILED, "ReadyState not NONE");
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 421
419 // SSL connection succeeded. 422 // SSL connection succeeded.
420 if (!transport_.get()) { 423 if (!transport_.get()) {
421 // Create a channel transport if one wasn't already set (e.g. by test 424 // Create a channel transport if one wasn't already set (e.g. by test
422 // code). 425 // code).
423 transport_.reset(new CastTransportImpl(this->socket_.get(), channel_id_, 426 transport_.reset(new CastTransportImpl(this->socket_.get(), channel_id_,
424 ip_endpoint_, channel_auth_, 427 ip_endpoint_, channel_auth_,
425 logger_)); 428 logger_));
426 } 429 }
427 auth_delegate_ = new AuthTransportDelegate(this); 430 auth_delegate_ = new AuthTransportDelegate(this);
428 transport_->SetReadDelegate(make_scoped_ptr(auth_delegate_)); 431 transport_->SetReadDelegate(base::WrapUnique(auth_delegate_));
429 if (channel_auth_ == CHANNEL_AUTH_TYPE_SSL_VERIFIED) { 432 if (channel_auth_ == CHANNEL_AUTH_TYPE_SSL_VERIFIED) {
430 // Additionally verify the connection with a handshake. 433 // Additionally verify the connection with a handshake.
431 SetConnectState(proto::CONN_STATE_AUTH_CHALLENGE_SEND); 434 SetConnectState(proto::CONN_STATE_AUTH_CHALLENGE_SEND);
432 } else { 435 } else {
433 SetConnectState(proto::CONN_STATE_FINISHED); 436 SetConnectState(proto::CONN_STATE_FINISHED);
434 transport_->Start(); 437 transport_->Start();
435 } 438 }
436 } else if (result == net::ERR_CONNECTION_TIMED_OUT) { 439 } else if (result == net::ERR_CONNECTION_TIMED_OUT) {
437 SetConnectState(proto::CONN_STATE_FINISHED); 440 SetConnectState(proto::CONN_STATE_FINISHED);
438 SetErrorState(CHANNEL_ERROR_CONNECT_TIMEOUT); 441 SetErrorState(CHANNEL_ERROR_CONNECT_TIMEOUT);
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 VLOG_WITH_CONNECTION(1) << "SetErrorState " << error_state; 616 VLOG_WITH_CONNECTION(1) << "SetErrorState " << error_state;
614 DCHECK_EQ(CHANNEL_ERROR_NONE, error_state_); 617 DCHECK_EQ(CHANNEL_ERROR_NONE, error_state_);
615 error_state_ = error_state; 618 error_state_ = error_state;
616 logger_->LogSocketErrorState(channel_id_, ErrorStateToProto(error_state_)); 619 logger_->LogSocketErrorState(channel_id_, ErrorStateToProto(error_state_));
617 delegate_->OnError(error_state_); 620 delegate_->OnError(error_state_);
618 } 621 }
619 } // namespace cast_channel 622 } // namespace cast_channel
620 } // namespace api 623 } // namespace api
621 } // namespace extensions 624 } // namespace extensions
622 #undef VLOG_WITH_CONNECTION 625 #undef VLOG_WITH_CONNECTION
OLDNEW
« no previous file with comments | « extensions/browser/api/cast_channel/cast_socket.h ('k') | extensions/browser/api/cast_channel/cast_socket_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698