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

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

Issue 1212023004: Convert all usages of mojo::ErrorHandler in //device/serial to callbacks. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 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 | « no previous file | device/serial/data_receiver.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_RECEIVER_H_ 5 #ifndef DEVICE_SERIAL_DATA_RECEIVER_H_
6 #define DEVICE_SERIAL_DATA_RECEIVER_H_ 6 #define DEVICE_SERIAL_DATA_RECEIVER_H_
7 7
8 #include <queue> 8 #include <queue>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
11 #include "base/memory/linked_ptr.h" 11 #include "base/memory/linked_ptr.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/memory/weak_ptr.h" 13 #include "base/memory/weak_ptr.h"
14 #include "device/serial/buffer.h" 14 #include "device/serial/buffer.h"
15 #include "device/serial/data_stream.mojom.h" 15 #include "device/serial/data_stream.mojom.h"
16 #include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h" 16 #include "third_party/mojo/src/mojo/public/cpp/system/data_pipe.h"
17 17
18 namespace device { 18 namespace device {
19 19
20 // A DataReceiver receives data from a DataSource. 20 // A DataReceiver receives data from a DataSource.
21 class DataReceiver : public base::RefCounted<DataReceiver>, 21 class DataReceiver : public base::RefCounted<DataReceiver>,
22 public serial::DataSourceClient, 22 public serial::DataSourceClient {
23 public mojo::ErrorHandler {
24 public: 23 public:
25 typedef base::Callback<void(scoped_ptr<ReadOnlyBuffer>)> ReceiveDataCallback; 24 typedef base::Callback<void(scoped_ptr<ReadOnlyBuffer>)> ReceiveDataCallback;
26 typedef base::Callback<void(int32_t error)> ReceiveErrorCallback; 25 typedef base::Callback<void(int32_t error)> ReceiveErrorCallback;
27 26
28 // Constructs a DataReceiver to receive data from |source|, using a buffer 27 // Constructs a DataReceiver to receive data from |source|, using a buffer
29 // size of |buffer_size|, with connection errors reported as 28 // size of |buffer_size|, with connection errors reported as
30 // |fatal_error_value|. 29 // |fatal_error_value|.
31 DataReceiver(mojo::InterfacePtr<serial::DataSource> source, 30 DataReceiver(mojo::InterfacePtr<serial::DataSource> source,
32 mojo::InterfaceRequest<serial::DataSourceClient> client, 31 mojo::InterfaceRequest<serial::DataSourceClient> client,
33 uint32_t buffer_size, 32 uint32_t buffer_size,
(...skipping 12 matching lines...) Expand all
46 friend class base::RefCounted<DataReceiver>; 45 friend class base::RefCounted<DataReceiver>;
47 46
48 ~DataReceiver() override; 47 ~DataReceiver() override;
49 48
50 // serial::DataSourceClient overrides. 49 // serial::DataSourceClient overrides.
51 // Invoked by the DataSource to report errors. 50 // Invoked by the DataSource to report errors.
52 void OnError(int32_t error) override; 51 void OnError(int32_t error) override;
53 // Invoked by the DataSource transmit data. 52 // Invoked by the DataSource transmit data.
54 void OnData(mojo::Array<uint8_t> data) override; 53 void OnData(mojo::Array<uint8_t> data) override;
55 54
56 // mojo::ErrorHandler override. Calls ShutDown(). 55 // mojo error handler
57 void OnConnectionError() override; 56 void OnConnectionError();
58 57
59 // Invoked by the PendingReceive to report that the user is done with the 58 // Invoked by the PendingReceive to report that the user is done with the
60 // receive buffer, having read |bytes_read| bytes from it. 59 // receive buffer, having read |bytes_read| bytes from it.
61 void Done(uint32_t bytes_read); 60 void Done(uint32_t bytes_read);
62 61
63 // The implementation of Receive(). If a |pending_error_| is ready to 62 // The implementation of Receive(). If a |pending_error_| is ready to
64 // dispatch, it does so. Otherwise, this attempts to read from |handle_| and 63 // dispatch, it does so. Otherwise, this attempts to read from |handle_| and
65 // dispatches the contents to |pending_receive_|. If |handle_| is not ready, 64 // dispatches the contents to |pending_receive_|. If |handle_| is not ready,
66 // |waiter_| is used to wait until it is ready. If an error occurs in reading 65 // |waiter_| is used to wait until it is ready. If an error occurs in reading
67 // |handle_|, ShutDown() is called. 66 // |handle_|, ShutDown() is called.
(...skipping 21 matching lines...) Expand all
89 std::queue<linked_ptr<DataFrame>> pending_data_frames_; 88 std::queue<linked_ptr<DataFrame>> pending_data_frames_;
90 89
91 base::WeakPtrFactory<DataReceiver> weak_factory_; 90 base::WeakPtrFactory<DataReceiver> weak_factory_;
92 91
93 DISALLOW_COPY_AND_ASSIGN(DataReceiver); 92 DISALLOW_COPY_AND_ASSIGN(DataReceiver);
94 }; 93 };
95 94
96 } // namespace device 95 } // namespace device
97 96
98 #endif // DEVICE_SERIAL_DATA_RECEIVER_H_ 97 #endif // DEVICE_SERIAL_DATA_RECEIVER_H_
OLDNEW
« no previous file with comments | « no previous file | device/serial/data_receiver.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698