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

Side by Side Diff: remoting/protocol/pseudotcp_adapter.cc

Issue 1864213002: Convert //remoting to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mac IWYU 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
« no previous file with comments | « remoting/protocol/pseudotcp_adapter.h ('k') | remoting/protocol/pseudotcp_adapter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "remoting/protocol/pseudotcp_adapter.h" 5 #include "remoting/protocol/pseudotcp_adapter.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
(...skipping 14 matching lines...) Expand all
25 const int kReadBufferSize = 65536; // Maximum size of a packet. 25 const int kReadBufferSize = 65536; // Maximum size of a packet.
26 const uint16_t kDefaultMtu = 1280; 26 const uint16_t kDefaultMtu = 1280;
27 } // namespace 27 } // namespace
28 28
29 namespace remoting { 29 namespace remoting {
30 namespace protocol { 30 namespace protocol {
31 31
32 class PseudoTcpAdapter::Core : public cricket::IPseudoTcpNotify, 32 class PseudoTcpAdapter::Core : public cricket::IPseudoTcpNotify,
33 public base::RefCounted<Core> { 33 public base::RefCounted<Core> {
34 public: 34 public:
35 explicit Core(scoped_ptr<P2PDatagramSocket> socket); 35 explicit Core(std::unique_ptr<P2PDatagramSocket> socket);
36 36
37 // Functions used to implement net::StreamSocket. 37 // Functions used to implement net::StreamSocket.
38 int Read(const scoped_refptr<net::IOBuffer>& buffer, int buffer_size, 38 int Read(const scoped_refptr<net::IOBuffer>& buffer, int buffer_size,
39 const net::CompletionCallback& callback); 39 const net::CompletionCallback& callback);
40 int Write(const scoped_refptr<net::IOBuffer>& buffer, int buffer_size, 40 int Write(const scoped_refptr<net::IOBuffer>& buffer, int buffer_size,
41 const net::CompletionCallback& callback); 41 const net::CompletionCallback& callback);
42 int Connect(const net::CompletionCallback& callback); 42 int Connect(const net::CompletionCallback& callback);
43 43
44 // cricket::IPseudoTcpNotify interface. 44 // cricket::IPseudoTcpNotify interface.
45 // These notifications are triggered from NotifyPacket. 45 // These notifications are triggered from NotifyPacket.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 void CheckWriteComplete(); 81 void CheckWriteComplete();
82 82
83 // This re-sets |timer| without triggering callbacks. 83 // This re-sets |timer| without triggering callbacks.
84 void AdjustClock(); 84 void AdjustClock();
85 85
86 net::CompletionCallback connect_callback_; 86 net::CompletionCallback connect_callback_;
87 net::CompletionCallback read_callback_; 87 net::CompletionCallback read_callback_;
88 net::CompletionCallback write_callback_; 88 net::CompletionCallback write_callback_;
89 89
90 cricket::PseudoTcp pseudo_tcp_; 90 cricket::PseudoTcp pseudo_tcp_;
91 scoped_ptr<P2PDatagramSocket> socket_; 91 std::unique_ptr<P2PDatagramSocket> socket_;
92 92
93 scoped_refptr<net::IOBuffer> read_buffer_; 93 scoped_refptr<net::IOBuffer> read_buffer_;
94 int read_buffer_size_; 94 int read_buffer_size_;
95 scoped_refptr<net::IOBuffer> write_buffer_; 95 scoped_refptr<net::IOBuffer> write_buffer_;
96 int write_buffer_size_; 96 int write_buffer_size_;
97 97
98 // Whether we need to wait for data to be sent before completing write. 98 // Whether we need to wait for data to be sent before completing write.
99 bool write_waits_for_send_; 99 bool write_waits_for_send_;
100 100
101 // Set to true in the write-waits-for-send mode when we've 101 // Set to true in the write-waits-for-send mode when we've
102 // successfully writtend data to the send buffer and waiting for the 102 // successfully writtend data to the send buffer and waiting for the
103 // data to be sent to the remote end. 103 // data to be sent to the remote end.
104 bool waiting_write_position_; 104 bool waiting_write_position_;
105 105
106 // Number of the bytes written by the last write stored while we wait 106 // Number of the bytes written by the last write stored while we wait
107 // for the data to be sent (i.e. when waiting_write_position_ = true). 107 // for the data to be sent (i.e. when waiting_write_position_ = true).
108 int last_write_result_; 108 int last_write_result_;
109 109
110 bool socket_write_pending_; 110 bool socket_write_pending_;
111 scoped_refptr<net::IOBuffer> socket_read_buffer_; 111 scoped_refptr<net::IOBuffer> socket_read_buffer_;
112 112
113 base::OneShotTimer timer_; 113 base::OneShotTimer timer_;
114 114
115 DISALLOW_COPY_AND_ASSIGN(Core); 115 DISALLOW_COPY_AND_ASSIGN(Core);
116 }; 116 };
117 117
118 118 PseudoTcpAdapter::Core::Core(std::unique_ptr<P2PDatagramSocket> socket)
119 PseudoTcpAdapter::Core::Core(scoped_ptr<P2PDatagramSocket> socket)
120 : pseudo_tcp_(this, 0), 119 : pseudo_tcp_(this, 0),
121 socket_(std::move(socket)), 120 socket_(std::move(socket)),
122 write_waits_for_send_(false), 121 write_waits_for_send_(false),
123 waiting_write_position_(false), 122 waiting_write_position_(false),
124 socket_write_pending_(false) { 123 socket_write_pending_(false) {
125 // Doesn't trigger callbacks. 124 // Doesn't trigger callbacks.
126 pseudo_tcp_.NotifyMTU(kDefaultMtu); 125 pseudo_tcp_.NotifyMTU(kDefaultMtu);
127 } 126 }
128 127
129 PseudoTcpAdapter::Core::~Core() { 128 PseudoTcpAdapter::Core::~Core() {
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 net::CompletionCallback callback = write_callback_; 444 net::CompletionCallback callback = write_callback_;
446 write_callback_.Reset(); 445 write_callback_.Reset();
447 write_buffer_ = NULL; 446 write_buffer_ = NULL;
448 callback.Run(last_write_result_); 447 callback.Run(last_write_result_);
449 } 448 }
450 } 449 }
451 } 450 }
452 451
453 // Public interface implementation. 452 // Public interface implementation.
454 453
455 PseudoTcpAdapter::PseudoTcpAdapter(scoped_ptr<P2PDatagramSocket> socket) 454 PseudoTcpAdapter::PseudoTcpAdapter(std::unique_ptr<P2PDatagramSocket> socket)
456 : core_(new Core(std::move(socket))) { 455 : core_(new Core(std::move(socket))) {}
457 }
458 456
459 PseudoTcpAdapter::~PseudoTcpAdapter() { 457 PseudoTcpAdapter::~PseudoTcpAdapter() {
460 // Make sure that the underlying socket is destroyed before PseudoTcp. 458 // Make sure that the underlying socket is destroyed before PseudoTcp.
461 core_->DeleteSocket(); 459 core_->DeleteSocket();
462 } 460 }
463 461
464 int PseudoTcpAdapter::Read(const scoped_refptr<net::IOBuffer>& buffer, 462 int PseudoTcpAdapter::Read(const scoped_refptr<net::IOBuffer>& buffer,
465 int buffer_size, 463 int buffer_size,
466 const net::CompletionCallback& callback) { 464 const net::CompletionCallback& callback) {
467 DCHECK(CalledOnValidThread()); 465 DCHECK(CalledOnValidThread());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 core_->SetNoDelay(no_delay); 500 core_->SetNoDelay(no_delay);
503 } 501 }
504 502
505 void PseudoTcpAdapter::SetWriteWaitsForSend(bool write_waits_for_send) { 503 void PseudoTcpAdapter::SetWriteWaitsForSend(bool write_waits_for_send) {
506 DCHECK(CalledOnValidThread()); 504 DCHECK(CalledOnValidThread());
507 core_->SetWriteWaitsForSend(write_waits_for_send); 505 core_->SetWriteWaitsForSend(write_waits_for_send);
508 } 506 }
509 507
510 } // namespace protocol 508 } // namespace protocol
511 } // namespace remoting 509 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/pseudotcp_adapter.h ('k') | remoting/protocol/pseudotcp_adapter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698