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

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

Issue 60033002: Make HostController/DeviceListener deletion fully synchronous. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « tools/android/forwarder2/device_listener.cc ('k') | tools/android/forwarder2/forwarder.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 (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_FORWARDER_H_ 5 #ifndef TOOLS_ANDROID_FORWARDER2_FORWARDER_H_
6 #define TOOLS_ANDROID_FORWARDER2_FORWARDER_H_ 6 #define TOOLS_ANDROID_FORWARDER2_FORWARDER_H_
7 7
8 #include "base/callback.h"
8 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/threading/thread.h"
11 #include "tools/android/forwarder2/self_deleter_helper.h"
9 12
10 namespace forwarder2 { 13 namespace forwarder2 {
11 14
15 class PipeNotifier;
12 class Socket; 16 class Socket;
13 17
14 void StartForwarder(scoped_ptr<Socket> socket1, scoped_ptr<Socket> socket2); 18 // Internal class that wraps a helper thread to forward traffic between
19 // |socket1| and |socket2|. After creating a new instance, call its Start()
20 // method to launch operations. Thread stops automatically if one of the socket
21 // disconnects, but ensures that all buffered writes to the other, still alive,
22 // socket, are written first. When this happens, the instance will delete itself
23 // automatically.
24 // Note that the instance will always be destroyed on the same thread that
25 // created it.
26 class Forwarder {
27 public:
28 // Callback used on error invoked by the Forwarder to self-delete.
29 typedef base::Callback<void (scoped_ptr<Forwarder>)> ErrorCallback;
30
31 Forwarder(scoped_ptr<Socket> socket1,
32 scoped_ptr<Socket> socket2,
33 PipeNotifier* deletion_notifier,
34 const ErrorCallback& error_callback);
35
36 ~Forwarder();
37
38 void Start();
39
40 private:
41 void ThreadHandler();
42
43 void OnThreadHandlerCompletion(const ErrorCallback& error_callback);
44
45 SelfDeleterHelper<Forwarder> self_deleter_helper_;
46 PipeNotifier* const deletion_notifier_;
47 scoped_ptr<Socket> socket1_;
48 scoped_ptr<Socket> socket2_;
49 base::Thread thread_;
50 };
15 51
16 } // namespace forwarder2 52 } // namespace forwarder2
17 53
18 #endif // TOOLS_ANDROID_FORWARDER2_FORWARDER_H_ 54 #endif // TOOLS_ANDROID_FORWARDER2_FORWARDER_H_
OLDNEW
« no previous file with comments | « tools/android/forwarder2/device_listener.cc ('k') | tools/android/forwarder2/forwarder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698