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

Side by Side Diff: tools/android/forwarder2/device_listener.h

Issue 1869503004: Convert //tools to use std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, change iwyu fixes for converted directories to include <memory> 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 TOOLS_ANDROID_FORWARDER2_DEVICE_LISTENER_H_ 5 #ifndef TOOLS_ANDROID_FORWARDER2_DEVICE_LISTENER_H_
6 #define TOOLS_ANDROID_FORWARDER2_DEVICE_LISTENER_H_ 6 #define TOOLS_ANDROID_FORWARDER2_DEVICE_LISTENER_H_
7 7
8 #include <memory>
9
8 #include "base/callback.h" 10 #include "base/callback.h"
9 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
10 #include "base/logging.h" 12 #include "base/logging.h"
11 #include "base/macros.h" 13 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/threading/thread.h" 15 #include "base/threading/thread.h"
15 #include "tools/android/forwarder2/forwarders_manager.h" 16 #include "tools/android/forwarder2/forwarders_manager.h"
16 #include "tools/android/forwarder2/pipe_notifier.h" 17 #include "tools/android/forwarder2/pipe_notifier.h"
17 #include "tools/android/forwarder2/self_deleter_helper.h" 18 #include "tools/android/forwarder2/self_deleter_helper.h"
18 #include "tools/android/forwarder2/socket.h" 19 #include "tools/android/forwarder2/socket.h"
19 20
20 namespace base { 21 namespace base {
21 class SingleThreadTaskRunner; 22 class SingleThreadTaskRunner;
22 } // namespace base 23 } // namespace base
23 24
(...skipping 14 matching lines...) Expand all
38 // can also self-delete by executing the user-provided callback on the thread 39 // can also self-delete by executing the user-provided callback on the thread
39 // the DeviceListener was created on. 40 // the DeviceListener was created on.
40 // Note that the DeviceListener's destructor joins its internal thread (i.e. 41 // Note that the DeviceListener's destructor joins its internal thread (i.e.
41 // waits for its completion) which means that the internal thread is guaranteed 42 // waits for its completion) which means that the internal thread is guaranteed
42 // not to be running anymore once the object is deleted. 43 // not to be running anymore once the object is deleted.
43 class DeviceListener { 44 class DeviceListener {
44 public: 45 public:
45 // Callback that is used for self-deletion on error to let the device 46 // Callback that is used for self-deletion on error to let the device
46 // controller perform some additional cleanup work (e.g. removing the device 47 // controller perform some additional cleanup work (e.g. removing the device
47 // listener instance from its internal map before deleting it). 48 // listener instance from its internal map before deleting it).
48 typedef base::Callback<void (scoped_ptr<DeviceListener>)> ErrorCallback; 49 typedef base::Callback<void(std::unique_ptr<DeviceListener>)> ErrorCallback;
49 50
50 static scoped_ptr<DeviceListener> Create(scoped_ptr<Socket> host_socket, 51 static std::unique_ptr<DeviceListener> Create(
51 int port, 52 std::unique_ptr<Socket> host_socket,
52 const ErrorCallback& error_callback); 53 int port,
54 const ErrorCallback& error_callback);
53 55
54 ~DeviceListener(); 56 ~DeviceListener();
55 57
56 void Start(); 58 void Start();
57 59
58 void SetAdbDataSocket(scoped_ptr<Socket> adb_data_socket); 60 void SetAdbDataSocket(std::unique_ptr<Socket> adb_data_socket);
59 61
60 int listener_port() const { return listener_port_; } 62 int listener_port() const { return listener_port_; }
61 63
62 private: 64 private:
63 DeviceListener(scoped_ptr<Socket> listener_socket, 65 DeviceListener(std::unique_ptr<Socket> listener_socket,
64 scoped_ptr<Socket> host_socket, 66 std::unique_ptr<Socket> host_socket,
65 int port, 67 int port,
66 const ErrorCallback& error_callback); 68 const ErrorCallback& error_callback);
67 69
68 // Pushes an AcceptClientOnInternalThread() task to the internal thread's 70 // Pushes an AcceptClientOnInternalThread() task to the internal thread's
69 // message queue in order to wait for a new client soon. 71 // message queue in order to wait for a new client soon.
70 void AcceptNextClientSoon(); 72 void AcceptNextClientSoon();
71 73
72 void AcceptClientOnInternalThread(); 74 void AcceptClientOnInternalThread();
73 75
74 void OnAdbDataSocketReceivedOnInternalThread( 76 void OnAdbDataSocketReceivedOnInternalThread(
75 scoped_ptr<Socket> adb_data_socket); 77 std::unique_ptr<Socket> adb_data_socket);
76 78
77 void OnInternalThreadError(); 79 void OnInternalThreadError();
78 80
79 SelfDeleterHelper<DeviceListener> self_deleter_helper_; 81 SelfDeleterHelper<DeviceListener> self_deleter_helper_;
80 // Used for the listener thread to be notified on destruction. We have one 82 // Used for the listener thread to be notified on destruction. We have one
81 // notifier per Listener thread since each Listener thread may be requested to 83 // notifier per Listener thread since each Listener thread may be requested to
82 // exit for different reasons independently from each other and independent 84 // exit for different reasons independently from each other and independent
83 // from the main program, ex. when the host requests to forward/listen the 85 // from the main program, ex. when the host requests to forward/listen the
84 // same port again. Both the |host_socket_| and |listener_socket_| must share 86 // same port again. Both the |host_socket_| and |listener_socket_| must share
85 // the same receiver file descriptor from |deletion_notifier_| and it is set 87 // the same receiver file descriptor from |deletion_notifier_| and it is set
86 // in the constructor. 88 // in the constructor.
87 PipeNotifier deletion_notifier_; 89 PipeNotifier deletion_notifier_;
88 // The local device listener socket for accepting connections from the local 90 // The local device listener socket for accepting connections from the local
89 // port (listener_port_). 91 // port (listener_port_).
90 const scoped_ptr<Socket> listener_socket_; 92 const std::unique_ptr<Socket> listener_socket_;
91 // The listener socket for sending control commands. 93 // The listener socket for sending control commands.
92 const scoped_ptr<Socket> host_socket_; 94 const std::unique_ptr<Socket> host_socket_;
93 scoped_ptr<Socket> device_data_socket_; 95 std::unique_ptr<Socket> device_data_socket_;
94 const int listener_port_; 96 const int listener_port_;
95 // Task runner used for deletion set at construction time (i.e. the object is 97 // Task runner used for deletion set at construction time (i.e. the object is
96 // deleted on the same thread it is created on). 98 // deleted on the same thread it is created on).
97 scoped_refptr<base::SingleThreadTaskRunner> deletion_task_runner_; 99 scoped_refptr<base::SingleThreadTaskRunner> deletion_task_runner_;
98 base::Thread thread_; 100 base::Thread thread_;
99 ForwardersManager forwarders_manager_; 101 ForwardersManager forwarders_manager_;
100 102
101 DISALLOW_COPY_AND_ASSIGN(DeviceListener); 103 DISALLOW_COPY_AND_ASSIGN(DeviceListener);
102 }; 104 };
103 105
104 } // namespace forwarder 106 } // namespace forwarder
105 107
106 #endif // TOOLS_ANDROID_FORWARDER2_DEVICE_LISTENER_H_ 108 #endif // TOOLS_ANDROID_FORWARDER2_DEVICE_LISTENER_H_
OLDNEW
« no previous file with comments | « tools/android/forwarder2/device_forwarder_main.cc ('k') | tools/android/forwarder2/device_listener.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698