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

Unified Diff: chrome/browser/extensions/api/socket/socket_api.h

Issue 8857004: Delete UDPClientSocket on same thread as creation. Also refactor. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Initial. Created 9 years 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
Index: chrome/browser/extensions/api/socket/socket_api.h
diff --git a/chrome/browser/extensions/api/socket/socket_api.h b/chrome/browser/extensions/api/socket/socket_api.h
index d28c49747735b123aae3dfffc1cd227280c81a7e..6f8b752fa111d6e458c3a07799d8060ab1a3334d 100644
--- a/chrome/browser/extensions/api/socket/socket_api.h
+++ b/chrome/browser/extensions/api/socket/socket_api.h
@@ -12,38 +12,52 @@
namespace extensions {
+class SocketController;
+
extern const char kBytesWrittenKey[];
extern const char kSocketIdKey[];
extern const char kUdpSocketType[];
+class SocketApiFunction : public AsyncExtensionFunction {
+ protected:
+ // Set up for work. Guaranteed to happen on UI thread.
+ virtual bool Prepare() = 0;
+
+ // Do actual work. Guaranteed to happen on IO thread.
+ virtual void Work() = 0;
+
+ // Respond. Guaranteed to happen on UI thread.
+ virtual bool Respond() = 0;
+
+ virtual bool RunImpl() OVERRIDE;
+
+ SocketController* controller();
+
+ private:
+ void WorkOnIOThread();
+ void RespondOnUIThread();
+};
+
// Many of these socket functions are synchronous in the sense that
// they don't involve blocking operations, but we've made them all
// AsyncExtensionFunctions because the underlying UDPClientSocket
// library wants all operations to happen on the same thread as the
// one that created the socket. Too bad.
-class SocketCreateFunction : public AsyncExtensionFunction {
- public:
- SocketCreateFunction();
- virtual ~SocketCreateFunction();
- virtual bool RunImpl() OVERRIDE;
-
+class SocketCreateFunction : public SocketApiFunction {
protected:
- void WorkOnIOThread();
- void RespondOnUIThread();
+ bool Prepare() OVERRIDE;
+ void Work() OVERRIDE;
+ bool Respond() OVERRIDE;
DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.create")
};
-class SocketDestroyFunction : public AsyncExtensionFunction {
- public:
- SocketDestroyFunction();
- virtual ~SocketDestroyFunction();
- virtual bool RunImpl() OVERRIDE;
-
+class SocketDestroyFunction : public SocketApiFunction {
protected:
- void WorkOnIOThread();
- void RespondOnUIThread();
+ bool Prepare() OVERRIDE;
+ void Work() OVERRIDE;
+ bool Respond() OVERRIDE;
private:
int socket_id_;
@@ -51,15 +65,11 @@ class SocketDestroyFunction : public AsyncExtensionFunction {
DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.destroy")
};
-class SocketConnectFunction : public AsyncExtensionFunction {
- public:
- SocketConnectFunction();
- virtual ~SocketConnectFunction();
- virtual bool RunImpl() OVERRIDE;
-
+class SocketConnectFunction : public SocketApiFunction {
protected:
- void WorkOnIOThread();
- void RespondOnUIThread();
+ bool Prepare() OVERRIDE;
+ void Work() OVERRIDE;
+ bool Respond() OVERRIDE;
private:
int socket_id_;
@@ -69,15 +79,11 @@ class SocketConnectFunction : public AsyncExtensionFunction {
DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.connect")
};
-class SocketCloseFunction : public AsyncExtensionFunction {
- public:
- SocketCloseFunction();
- virtual ~SocketCloseFunction();
- virtual bool RunImpl() OVERRIDE;
-
+class SocketCloseFunction : public SocketApiFunction {
protected:
- void WorkOnIOThread();
- void RespondOnUIThread();
+ bool Prepare() OVERRIDE;
+ void Work() OVERRIDE;
+ bool Respond() OVERRIDE;
private:
int socket_id_;
@@ -85,16 +91,13 @@ class SocketCloseFunction : public AsyncExtensionFunction {
DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.close")
};
-class SocketWriteFunction : public AsyncExtensionFunction {
- public:
- SocketWriteFunction();
- virtual ~SocketWriteFunction();
- virtual bool RunImpl() OVERRIDE;
-
+class SocketWriteFunction : public SocketApiFunction {
protected:
- void WorkOnIOThread();
- void RespondOnUIThread();
+ bool Prepare() OVERRIDE;
+ void Work() OVERRIDE;
+ bool Respond() OVERRIDE;
+ private:
int socket_id_;
std::string message_;

Powered by Google App Engine
This is Rietveld 408576698