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

Side by Side Diff: device/serial/data_source_sender.h

Issue 1874313002: Convert device 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
« no previous file with comments | « device/serial/data_sink_unittest.cc ('k') | device/serial/data_source_sender.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 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 DEVICE_SERIAL_DATA_SOURCE_SENDER_H_ 5 #ifndef DEVICE_SERIAL_DATA_SOURCE_SENDER_H_
6 #define DEVICE_SERIAL_DATA_SOURCE_SENDER_H_ 6 #define DEVICE_SERIAL_DATA_SOURCE_SENDER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory>
10 #include <vector> 11 #include <vector>
11 12
12 #include "base/callback.h" 13 #include "base/callback.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
15 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
16 #include "device/serial/buffer.h" 17 #include "device/serial/buffer.h"
17 #include "device/serial/data_stream.mojom.h" 18 #include "device/serial/data_stream.mojom.h"
18 #include "mojo/public/cpp/bindings/binding.h" 19 #include "mojo/public/cpp/bindings/binding.h"
19 #include "mojo/public/cpp/system/data_pipe.h" 20 #include "mojo/public/cpp/system/data_pipe.h"
20 21
21 namespace device { 22 namespace device {
22 23
23 // A DataSourceSender is an interface between a source of data and a 24 // A DataSourceSender is an interface between a source of data and a
24 // DataSourceClient. 25 // DataSourceClient.
25 class DataSourceSender : public base::RefCounted<DataSourceSender>, 26 class DataSourceSender : public base::RefCounted<DataSourceSender>,
26 public serial::DataSource { 27 public serial::DataSource {
27 public: 28 public:
28 typedef base::Callback<void(scoped_ptr<WritableBuffer>)> ReadyCallback; 29 typedef base::Callback<void(std::unique_ptr<WritableBuffer>)> ReadyCallback;
29 typedef base::Callback<void()> ErrorCallback; 30 typedef base::Callback<void()> ErrorCallback;
30 31
31 // Constructs a DataSourceSender. Whenever the pipe is ready for writing, the 32 // Constructs a DataSourceSender. Whenever the pipe is ready for writing, the
32 // |ready_callback| will be called with the WritableBuffer to be filled. 33 // |ready_callback| will be called with the WritableBuffer to be filled.
33 // |ready_callback| will not be called again until the previous WritableBuffer 34 // |ready_callback| will not be called again until the previous WritableBuffer
34 // is destroyed. If a connection error occurs, |error_callback| will be 35 // is destroyed. If a connection error occurs, |error_callback| will be
35 // called and the DataSourceSender will act as if ShutDown() had been called. 36 // called and the DataSourceSender will act as if ShutDown() had been called.
36 DataSourceSender(mojo::InterfaceRequest<serial::DataSource> source, 37 DataSourceSender(mojo::InterfaceRequest<serial::DataSource> source,
37 mojo::InterfacePtr<serial::DataSourceClient> client, 38 mojo::InterfacePtr<serial::DataSourceClient> client,
38 const ReadyCallback& ready_callback, 39 const ReadyCallback& ready_callback,
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 mojo::Binding<serial::DataSource> binding_; 75 mojo::Binding<serial::DataSource> binding_;
75 mojo::InterfacePtr<serial::DataSourceClient> client_; 76 mojo::InterfacePtr<serial::DataSourceClient> client_;
76 77
77 // The callback to call when the client is ready for more data. 78 // The callback to call when the client is ready for more data.
78 ReadyCallback ready_callback_; 79 ReadyCallback ready_callback_;
79 80
80 // The callback to call if a fatal error occurs. 81 // The callback to call if a fatal error occurs.
81 ErrorCallback error_callback_; 82 ErrorCallback error_callback_;
82 83
83 // The current pending send operation if there is one. 84 // The current pending send operation if there is one.
84 scoped_ptr<PendingSend> pending_send_; 85 std::unique_ptr<PendingSend> pending_send_;
85 86
86 // The number of bytes available for buffering in the client. 87 // The number of bytes available for buffering in the client.
87 uint32_t available_buffer_capacity_; 88 uint32_t available_buffer_capacity_;
88 89
89 // Whether sending is paused due to an error. 90 // Whether sending is paused due to an error.
90 bool paused_; 91 bool paused_;
91 92
92 // Whether we have encountered a fatal error and shut down. 93 // Whether we have encountered a fatal error and shut down.
93 bool shut_down_; 94 bool shut_down_;
94 95
95 base::WeakPtrFactory<DataSourceSender> weak_factory_; 96 base::WeakPtrFactory<DataSourceSender> weak_factory_;
96 97
97 DISALLOW_COPY_AND_ASSIGN(DataSourceSender); 98 DISALLOW_COPY_AND_ASSIGN(DataSourceSender);
98 }; 99 };
99 100
100 } // namespace device 101 } // namespace device
101 102
102 #endif // DEVICE_SERIAL_DATA_SOURCE_SENDER_H_ 103 #endif // DEVICE_SERIAL_DATA_SOURCE_SENDER_H_
OLDNEW
« no previous file with comments | « device/serial/data_sink_unittest.cc ('k') | device/serial/data_source_sender.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698