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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/android/forwarder2/device_listener.cc ('k') | tools/android/forwarder2/forwarder.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/android/forwarder2/forwarder.h
diff --git a/tools/android/forwarder2/forwarder.h b/tools/android/forwarder2/forwarder.h
index d4d2762a99fcf192b2295c84f1632b0a587598cb..5ad1b1a38ec846cdb1e8604f13f72ab11c7a504f 100644
--- a/tools/android/forwarder2/forwarder.h
+++ b/tools/android/forwarder2/forwarder.h
@@ -5,13 +5,49 @@
#ifndef TOOLS_ANDROID_FORWARDER2_FORWARDER_H_
#define TOOLS_ANDROID_FORWARDER2_FORWARDER_H_
+#include "base/callback.h"
#include "base/memory/scoped_ptr.h"
+#include "base/threading/thread.h"
+#include "tools/android/forwarder2/self_deleter_helper.h"
namespace forwarder2 {
+class PipeNotifier;
class Socket;
-void StartForwarder(scoped_ptr<Socket> socket1, scoped_ptr<Socket> socket2);
+// Internal class that wraps a helper thread to forward traffic between
+// |socket1| and |socket2|. After creating a new instance, call its Start()
+// method to launch operations. Thread stops automatically if one of the socket
+// disconnects, but ensures that all buffered writes to the other, still alive,
+// socket, are written first. When this happens, the instance will delete itself
+// automatically.
+// Note that the instance will always be destroyed on the same thread that
+// created it.
+class Forwarder {
+ public:
+ // Callback used on error invoked by the Forwarder to self-delete.
+ typedef base::Callback<void (scoped_ptr<Forwarder>)> ErrorCallback;
+
+ Forwarder(scoped_ptr<Socket> socket1,
+ scoped_ptr<Socket> socket2,
+ PipeNotifier* deletion_notifier,
+ const ErrorCallback& error_callback);
+
+ ~Forwarder();
+
+ void Start();
+
+ private:
+ void ThreadHandler();
+
+ void OnThreadHandlerCompletion(const ErrorCallback& error_callback);
+
+ SelfDeleterHelper<Forwarder> self_deleter_helper_;
+ PipeNotifier* const deletion_notifier_;
+ scoped_ptr<Socket> socket1_;
+ scoped_ptr<Socket> socket2_;
+ base::Thread thread_;
+};
} // namespace forwarder2
« 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