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

Side by Side Diff: extensions/browser/api/cast_channel/cast_socket.h

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 #ifndef EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_ 5 #ifndef EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_
6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_ 6 #define EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <queue> 10 #include <queue>
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // Used by BrowserContextKeyedAPIFactory. 65 // Used by BrowserContextKeyedAPIFactory.
66 static const char* service_name() { return "CastSocketImplManager"; } 66 static const char* service_name() { return "CastSocketImplManager"; }
67 67
68 // Connects the channel to the peer. If successful, the channel will be in 68 // Connects the channel to the peer. If successful, the channel will be in
69 // READY_STATE_OPEN. DO NOT delete the CastSocket object in |callback|. 69 // READY_STATE_OPEN. DO NOT delete the CastSocket object in |callback|.
70 // Instead use Close(). 70 // Instead use Close().
71 // |callback| will be invoked with any ChannelError that occurred, or 71 // |callback| will be invoked with any ChannelError that occurred, or
72 // CHANNEL_ERROR_NONE if successful. 72 // CHANNEL_ERROR_NONE if successful.
73 // |delegate| receives message receipt and error events. 73 // |delegate| receives message receipt and error events.
74 // Ownership of |delegate| is transferred to this CastSocket. 74 // Ownership of |delegate| is transferred to this CastSocket.
75 virtual void Connect(scoped_ptr<CastTransport::Delegate> delegate, 75 virtual void Connect(std::unique_ptr<CastTransport::Delegate> delegate,
76 base::Callback<void(ChannelError)> callback) = 0; 76 base::Callback<void(ChannelError)> callback) = 0;
77 77
78 // Closes the channel if not already closed. On completion, the channel will 78 // Closes the channel if not already closed. On completion, the channel will
79 // be in READY_STATE_CLOSED. 79 // be in READY_STATE_CLOSED.
80 // 80 //
81 // It is fine to delete this object in |callback|. 81 // It is fine to delete this object in |callback|.
82 virtual void Close(const net::CompletionCallback& callback) = 0; 82 virtual void Close(const net::CompletionCallback& callback) = 0;
83 83
84 // The IP endpoint for the destination of the channel. 84 // The IP endpoint for the destination of the channel.
85 virtual const net::IPEndPoint& ip_endpoint() const = 0; 85 virtual const net::IPEndPoint& ip_endpoint() const = 0;
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 net::NetLog* net_log, 150 net::NetLog* net_log,
151 const base::TimeDelta& connect_timeout, 151 const base::TimeDelta& connect_timeout,
152 bool keep_alive, 152 bool keep_alive,
153 const scoped_refptr<Logger>& logger, 153 const scoped_refptr<Logger>& logger,
154 uint64_t device_capabilities); 154 uint64_t device_capabilities);
155 155
156 // Ensures that the socket is closed. 156 // Ensures that the socket is closed.
157 ~CastSocketImpl() override; 157 ~CastSocketImpl() override;
158 158
159 // CastSocket interface. 159 // CastSocket interface.
160 void Connect(scoped_ptr<CastTransport::Delegate> delegate, 160 void Connect(std::unique_ptr<CastTransport::Delegate> delegate,
161 base::Callback<void(ChannelError)> callback) override; 161 base::Callback<void(ChannelError)> callback) override;
162 CastTransport* transport() const override; 162 CastTransport* transport() const override;
163 void Close(const net::CompletionCallback& callback) override; 163 void Close(const net::CompletionCallback& callback) override;
164 const net::IPEndPoint& ip_endpoint() const override; 164 const net::IPEndPoint& ip_endpoint() const override;
165 int id() const override; 165 int id() const override;
166 void set_id(int channel_id) override; 166 void set_id(int channel_id) override;
167 ChannelAuthType channel_auth() const override; 167 ChannelAuthType channel_auth() const override;
168 ReadyState ready_state() const override; 168 ReadyState ready_state() const override;
169 ChannelError error_state() const override; 169 ChannelError error_state() const override;
170 bool keep_alive() const override; 170 bool keep_alive() const override;
(...skipping 21 matching lines...) Expand all
192 void Start() override; 192 void Start() override;
193 193
194 private: 194 private:
195 CastSocketImpl* socket_; 195 CastSocketImpl* socket_;
196 ChannelError error_state_; 196 ChannelError error_state_;
197 LastErrors last_errors_; 197 LastErrors last_errors_;
198 }; 198 };
199 199
200 // Replaces the internally-constructed transport object with one provided 200 // Replaces the internally-constructed transport object with one provided
201 // by the caller (e.g. a mock). 201 // by the caller (e.g. a mock).
202 void SetTransportForTesting(scoped_ptr<CastTransport> transport); 202 void SetTransportForTesting(std::unique_ptr<CastTransport> transport);
203 203
204 // Verifies whether the socket complies with cast channel policy. 204 // Verifies whether the socket complies with cast channel policy.
205 // Audio only channel policy mandates that a device declaring a video out 205 // Audio only channel policy mandates that a device declaring a video out
206 // capability must not have a certificate with audio only policy. 206 // capability must not have a certificate with audio only policy.
207 bool VerifyChannelPolicy(const AuthResult& result); 207 bool VerifyChannelPolicy(const AuthResult& result);
208 208
209 private: 209 private:
210 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestConnectAuthMessageCorrupted); 210 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, TestConnectAuthMessageCorrupted);
211 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, 211 FRIEND_TEST_ALL_PREFIXES(CastSocketTest,
212 TestConnectChallengeReplyReceiveError); 212 TestConnectChallengeReplyReceiveError);
213 FRIEND_TEST_ALL_PREFIXES(CastSocketTest, 213 FRIEND_TEST_ALL_PREFIXES(CastSocketTest,
214 TestConnectChallengeVerificationFails); 214 TestConnectChallengeVerificationFails);
215 friend class AuthTransportDelegate; 215 friend class AuthTransportDelegate;
216 friend class ApiResourceManager<CastSocketImpl>; 216 friend class ApiResourceManager<CastSocketImpl>;
217 friend class CastSocketTest; 217 friend class CastSocketTest;
218 friend class TestCastSocket; 218 friend class TestCastSocket;
219 219
220 void SetErrorState(ChannelError error_state) override; 220 void SetErrorState(ChannelError error_state) override;
221 221
222 // Frees resources and cancels pending callbacks. |ready_state_| will be set 222 // Frees resources and cancels pending callbacks. |ready_state_| will be set
223 // READY_STATE_CLOSED on completion. A no-op if |ready_state_| is already 223 // READY_STATE_CLOSED on completion. A no-op if |ready_state_| is already
224 // READY_STATE_CLOSED. 224 // READY_STATE_CLOSED.
225 void CloseInternal(); 225 void CloseInternal();
226 226
227 // Creates an instance of TCPClientSocket. 227 // Creates an instance of TCPClientSocket.
228 virtual scoped_ptr<net::TCPClientSocket> CreateTcpSocket(); 228 virtual std::unique_ptr<net::TCPClientSocket> CreateTcpSocket();
229 // Creates an instance of SSLClientSocket with the given underlying |socket|. 229 // Creates an instance of SSLClientSocket with the given underlying |socket|.
230 virtual scoped_ptr<net::SSLClientSocket> CreateSslSocket( 230 virtual std::unique_ptr<net::SSLClientSocket> CreateSslSocket(
231 scoped_ptr<net::StreamSocket> socket); 231 std::unique_ptr<net::StreamSocket> socket);
232 // Extracts peer certificate from SSLClientSocket instance when the socket 232 // Extracts peer certificate from SSLClientSocket instance when the socket
233 // is in cert error state. 233 // is in cert error state.
234 // Returns null if the certificate could not be extracted. 234 // Returns null if the certificate could not be extracted.
235 // TODO(kmarshall): Use MockSSLClientSocket for tests instead of overriding 235 // TODO(kmarshall): Use MockSSLClientSocket for tests instead of overriding
236 // this function. 236 // this function.
237 virtual scoped_refptr<net::X509Certificate> ExtractPeerCert(); 237 virtual scoped_refptr<net::X509Certificate> ExtractPeerCert();
238 // Verifies whether the challenge reply received from the peer is valid: 238 // Verifies whether the challenge reply received from the peer is valid:
239 // 1. Signature in the reply is valid. 239 // 1. Signature in the reply is valid.
240 // 2. Certificate is rooted to a trusted CA. 240 // 2. Certificate is rooted to a trusted CA.
241 virtual bool VerifyChallengeReply(); 241 virtual bool VerifyChallengeReply();
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 net::NetLog::Source net_log_source_; 297 net::NetLog::Source net_log_source_;
298 // True when keep-alive signaling should be handled for this socket. 298 // True when keep-alive signaling should be handled for this socket.
299 bool keep_alive_; 299 bool keep_alive_;
300 300
301 // Shared logging object, used to log CastSocket events for diagnostics. 301 // Shared logging object, used to log CastSocket events for diagnostics.
302 scoped_refptr<Logger> logger_; 302 scoped_refptr<Logger> logger_;
303 303
304 // CertVerifier is owned by us but should be deleted AFTER SSLClientSocket 304 // CertVerifier is owned by us but should be deleted AFTER SSLClientSocket
305 // since in some cases the destructor of SSLClientSocket may call a method 305 // since in some cases the destructor of SSLClientSocket may call a method
306 // to cancel a cert verification request. 306 // to cancel a cert verification request.
307 scoped_ptr<net::CertVerifier> cert_verifier_; 307 std::unique_ptr<net::CertVerifier> cert_verifier_;
308 scoped_ptr<net::TransportSecurityState> transport_security_state_; 308 std::unique_ptr<net::TransportSecurityState> transport_security_state_;
309 309
310 // Owned ptr to the underlying TCP socket. 310 // Owned ptr to the underlying TCP socket.
311 scoped_ptr<net::TCPClientSocket> tcp_socket_; 311 std::unique_ptr<net::TCPClientSocket> tcp_socket_;
312 312
313 // Owned ptr to the underlying SSL socket. 313 // Owned ptr to the underlying SSL socket.
314 scoped_ptr<net::SSLClientSocket> socket_; 314 std::unique_ptr<net::SSLClientSocket> socket_;
315 315
316 // Certificate of the peer. This field may be empty if the peer 316 // Certificate of the peer. This field may be empty if the peer
317 // certificate is not yet fetched. 317 // certificate is not yet fetched.
318 scoped_refptr<net::X509Certificate> peer_cert_; 318 scoped_refptr<net::X509Certificate> peer_cert_;
319 319
320 // Reply received from the receiver to a challenge request. 320 // Reply received from the receiver to a challenge request.
321 scoped_ptr<CastMessage> challenge_reply_; 321 std::unique_ptr<CastMessage> challenge_reply_;
322 322
323 // Callback invoked when the socket is connected or fails to connect. 323 // Callback invoked when the socket is connected or fails to connect.
324 base::Callback<void(ChannelError)> connect_callback_; 324 base::Callback<void(ChannelError)> connect_callback_;
325 325
326 // Callback invoked by |connect_timeout_timer_| to cancel the connection. 326 // Callback invoked by |connect_timeout_timer_| to cancel the connection.
327 base::CancelableClosure connect_timeout_callback_; 327 base::CancelableClosure connect_timeout_callback_;
328 328
329 // Duration to wait before timing out. 329 // Duration to wait before timing out.
330 base::TimeDelta connect_timeout_; 330 base::TimeDelta connect_timeout_;
331 331
332 // Timer invoked when the connection has timed out. 332 // Timer invoked when the connection has timed out.
333 scoped_ptr<base::Timer> connect_timeout_timer_; 333 std::unique_ptr<base::Timer> connect_timeout_timer_;
334 334
335 // Set when a timeout is triggered and the connection process has 335 // Set when a timeout is triggered and the connection process has
336 // canceled. 336 // canceled.
337 bool is_canceled_; 337 bool is_canceled_;
338 338
339 // Capabilities declared by the cast device. 339 // Capabilities declared by the cast device.
340 uint64_t device_capabilities_; 340 uint64_t device_capabilities_;
341 341
342 // Whether the channel is audio only as identified by the device 342 // Whether the channel is audio only as identified by the device
343 // certificate during channel authentication. 343 // certificate during channel authentication.
(...skipping 16 matching lines...) Expand all
360 360
361 // Task invoked to (re)start the connect loop. Canceled on entry to the 361 // Task invoked to (re)start the connect loop. Canceled on entry to the
362 // connect loop. 362 // connect loop.
363 base::CancelableClosure connect_loop_callback_; 363 base::CancelableClosure connect_loop_callback_;
364 364
365 // Task invoked to send the auth challenge. Canceled when the auth challenge 365 // Task invoked to send the auth challenge. Canceled when the auth challenge
366 // has been sent. 366 // has been sent.
367 base::CancelableClosure send_auth_challenge_callback_; 367 base::CancelableClosure send_auth_challenge_callback_;
368 368
369 // Cast message formatting and parsing layer. 369 // Cast message formatting and parsing layer.
370 scoped_ptr<CastTransport> transport_; 370 std::unique_ptr<CastTransport> transport_;
371 371
372 // Caller's message read and error handling delegate. 372 // Caller's message read and error handling delegate.
373 scoped_ptr<CastTransport::Delegate> delegate_; 373 std::unique_ptr<CastTransport::Delegate> delegate_;
374 374
375 // Raw pointer to the auth handshake delegate. Used to get detailed error 375 // Raw pointer to the auth handshake delegate. Used to get detailed error
376 // information. 376 // information.
377 AuthTransportDelegate* auth_delegate_; 377 AuthTransportDelegate* auth_delegate_;
378 378
379 DISALLOW_COPY_AND_ASSIGN(CastSocketImpl); 379 DISALLOW_COPY_AND_ASSIGN(CastSocketImpl);
380 }; 380 };
381 } // namespace cast_channel 381 } // namespace cast_channel
382 } // namespace api 382 } // namespace api
383 } // namespace extensions 383 } // namespace extensions
384 384
385 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_ 385 #endif // EXTENSIONS_BROWSER_API_CAST_CHANNEL_CAST_SOCKET_H_
OLDNEW
« no previous file with comments | « extensions/browser/api/cast_channel/cast_message_util.cc ('k') | extensions/browser/api/cast_channel/cast_socket.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698