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

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

Issue 8743017: Real (but naive) UDP socket sending. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Post-try-server fixes. 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
new file mode 100644
index 0000000000000000000000000000000000000000..d28c49747735b123aae3dfffc1cd227280c81a7e
--- /dev/null
+++ b/chrome/browser/extensions/api/socket/socket_api.h
@@ -0,0 +1,106 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_
+#define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_
+#pragma once
+
+#include "chrome/browser/extensions/extension_function.h"
+
+#include <string>
+
+namespace extensions {
+
+extern const char kBytesWrittenKey[];
+extern const char kSocketIdKey[];
+extern const char kUdpSocketType[];
+
+// 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;
+
+ protected:
+ void WorkOnIOThread();
+ void RespondOnUIThread();
+
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.create")
+};
+
+class SocketDestroyFunction : public AsyncExtensionFunction {
+ public:
+ SocketDestroyFunction();
+ virtual ~SocketDestroyFunction();
+ virtual bool RunImpl() OVERRIDE;
+
+ protected:
+ void WorkOnIOThread();
+ void RespondOnUIThread();
+
+ private:
+ int socket_id_;
+
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.destroy")
+};
+
+class SocketConnectFunction : public AsyncExtensionFunction {
+ public:
+ SocketConnectFunction();
+ virtual ~SocketConnectFunction();
+ virtual bool RunImpl() OVERRIDE;
+
+ protected:
+ void WorkOnIOThread();
+ void RespondOnUIThread();
+
+ private:
+ int socket_id_;
+ std::string address_;
+ int port_;
+
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.connect")
+};
+
+class SocketCloseFunction : public AsyncExtensionFunction {
+ public:
+ SocketCloseFunction();
+ virtual ~SocketCloseFunction();
+ virtual bool RunImpl() OVERRIDE;
+
+ protected:
+ void WorkOnIOThread();
+ void RespondOnUIThread();
+
+ private:
+ int socket_id_;
+
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.close")
+};
+
+class SocketWriteFunction : public AsyncExtensionFunction {
+ public:
+ SocketWriteFunction();
+ virtual ~SocketWriteFunction();
+ virtual bool RunImpl() OVERRIDE;
+
+ protected:
+ void WorkOnIOThread();
+ void RespondOnUIThread();
+
+ int socket_id_;
+ std::string message_;
+
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.write")
+};
+
+} // namespace extensions
+
+#endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_

Powered by Google App Engine
This is Rietveld 408576698