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

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: Merge to fix hunk failure. 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
« no previous file with comments | « no previous file | chrome/browser/extensions/api/socket/socket_api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..8d1a7a2560c7f1f3d8b06ba96454ad1b7ad295e7 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();
+ virtual bool Prepare() OVERRIDE;
+ virtual void Work() OVERRIDE;
+ virtual 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();
+ virtual bool Prepare() OVERRIDE;
+ virtual void Work() OVERRIDE;
+ virtual 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();
+ virtual bool Prepare() OVERRIDE;
+ virtual void Work() OVERRIDE;
+ virtual 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();
+ virtual bool Prepare() OVERRIDE;
+ virtual void Work() OVERRIDE;
+ virtual 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();
+ virtual bool Prepare() OVERRIDE;
+ virtual void Work() OVERRIDE;
+ virtual bool Respond() OVERRIDE;
+ private:
int socket_id_;
std::string message_;
« no previous file with comments | « no previous file | chrome/browser/extensions/api/socket/socket_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698