| OLD | NEW |
| 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 CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "chrome/browser/extensions/api/api_function.h" | 10 #include "chrome/browser/extensions/api/api_function.h" |
| 11 #include "net/base/io_buffer.h" | 11 #include "net/base/io_buffer.h" |
| 12 #include "net/base/ip_endpoint.h" |
| 12 | 13 |
| 13 #include <string> | 14 #include <string> |
| 14 | 15 |
| 15 namespace extensions { | 16 namespace extensions { |
| 16 | 17 |
| 17 class APIResourceController; | 18 class APIResourceController; |
| 18 class APIResourceEventNotifier; | 19 class APIResourceEventNotifier; |
| 19 | 20 |
| 20 extern const char kBytesWrittenKey[]; | 21 extern const char kBytesWrittenKey[]; |
| 21 extern const char kSocketIdKey[]; | 22 extern const char kSocketIdKey[]; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 36 virtual void Work() OVERRIDE; | 37 virtual void Work() OVERRIDE; |
| 37 virtual bool Respond() OVERRIDE; | 38 virtual bool Respond() OVERRIDE; |
| 38 | 39 |
| 39 private: | 40 private: |
| 40 enum SocketType { | 41 enum SocketType { |
| 41 kSocketTypeInvalid = -1, | 42 kSocketTypeInvalid = -1, |
| 42 kSocketTypeTCP, | 43 kSocketTypeTCP, |
| 43 kSocketTypeUDP | 44 kSocketTypeUDP |
| 44 }; | 45 }; |
| 45 | 46 |
| 47 SocketType socket_type_; |
| 46 int src_id_; | 48 int src_id_; |
| 47 SocketType socket_type_; | |
| 48 std::string address_; | |
| 49 int port_; | |
| 50 APIResourceEventNotifier* event_notifier_; | 49 APIResourceEventNotifier* event_notifier_; |
| 51 | 50 |
| 52 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.create") | 51 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.create") |
| 53 }; | 52 }; |
| 54 | 53 |
| 55 class SocketDestroyFunction : public AsyncIOAPIFunction { | 54 class SocketDestroyFunction : public AsyncIOAPIFunction { |
| 56 protected: | 55 protected: |
| 57 virtual bool Prepare() OVERRIDE; | 56 virtual bool Prepare() OVERRIDE; |
| 58 virtual void Work() OVERRIDE; | 57 virtual void Work() OVERRIDE; |
| 59 virtual bool Respond() OVERRIDE; | 58 virtual bool Respond() OVERRIDE; |
| 60 | 59 |
| 61 private: | 60 private: |
| 62 int socket_id_; | 61 int socket_id_; |
| 63 | 62 |
| 64 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.destroy") | 63 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.destroy") |
| 65 }; | 64 }; |
| 66 | 65 |
| 67 class SocketConnectFunction : public AsyncIOAPIFunction { | 66 class SocketConnectFunction : public AsyncIOAPIFunction { |
| 68 protected: | 67 protected: |
| 69 virtual bool Prepare() OVERRIDE; | 68 virtual bool Prepare() OVERRIDE; |
| 70 virtual void Work() OVERRIDE; | 69 virtual void Work() OVERRIDE; |
| 71 virtual bool Respond() OVERRIDE; | 70 virtual bool Respond() OVERRIDE; |
| 72 | 71 |
| 73 private: | 72 private: |
| 74 int socket_id_; | 73 int socket_id_; |
| 74 std::string address_; |
| 75 int port_; |
| 75 | 76 |
| 76 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.connect") | 77 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.connect") |
| 77 }; | 78 }; |
| 78 | 79 |
| 79 class SocketDisconnectFunction : public AsyncIOAPIFunction { | 80 class SocketDisconnectFunction : public AsyncIOAPIFunction { |
| 80 protected: | 81 protected: |
| 81 virtual bool Prepare() OVERRIDE; | 82 virtual bool Prepare() OVERRIDE; |
| 82 virtual void Work() OVERRIDE; | 83 virtual void Work() OVERRIDE; |
| 83 virtual bool Respond() OVERRIDE; | 84 virtual bool Respond() OVERRIDE; |
| 84 | 85 |
| 85 private: | 86 private: |
| 86 int socket_id_; | 87 int socket_id_; |
| 87 | 88 |
| 88 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.disconnect") | 89 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.disconnect") |
| 89 }; | 90 }; |
| 90 | 91 |
| 92 class SocketBindFunction : public AsyncIOAPIFunction { |
| 93 protected: |
| 94 virtual bool Prepare() OVERRIDE; |
| 95 virtual void Work() OVERRIDE; |
| 96 virtual bool Respond() OVERRIDE; |
| 97 |
| 98 private: |
| 99 int socket_id_; |
| 100 std::string address_; |
| 101 int port_; |
| 102 |
| 103 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.bind") |
| 104 }; |
| 105 |
| 91 class SocketReadFunction : public AsyncIOAPIFunction { | 106 class SocketReadFunction : public AsyncIOAPIFunction { |
| 92 protected: | 107 protected: |
| 93 virtual bool Prepare() OVERRIDE; | 108 virtual bool Prepare() OVERRIDE; |
| 94 virtual void Work() OVERRIDE; | 109 virtual void Work() OVERRIDE; |
| 95 virtual bool Respond() OVERRIDE; | 110 virtual bool Respond() OVERRIDE; |
| 96 | 111 |
| 97 private: | 112 private: |
| 98 int socket_id_; | 113 int socket_id_; |
| 99 | 114 |
| 100 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.read") | 115 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.read") |
| 101 }; | 116 }; |
| 102 | 117 |
| 103 class SocketWriteFunction : public AsyncIOAPIFunction { | 118 class SocketWriteFunction : public AsyncIOAPIFunction { |
| 104 public: | 119 public: |
| 105 SocketWriteFunction(); | 120 SocketWriteFunction(); |
| 106 virtual ~SocketWriteFunction(); | 121 virtual ~SocketWriteFunction(); |
| 107 | 122 |
| 108 protected: | 123 protected: |
| 109 virtual bool Prepare() OVERRIDE; | 124 virtual bool Prepare() OVERRIDE; |
| 110 virtual void Work() OVERRIDE; | 125 virtual void Work() OVERRIDE; |
| 111 virtual bool Respond() OVERRIDE; | 126 virtual bool Respond() OVERRIDE; |
| 112 | 127 |
| 113 private: | 128 private: |
| 114 int socket_id_; | 129 int socket_id_; |
| 115 scoped_refptr<net::IOBufferWithSize> io_buffer_; | 130 scoped_refptr<net::IOBufferWithSize> io_buffer_; |
| 116 | 131 |
| 117 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.write") | 132 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.write") |
| 118 }; | 133 }; |
| 119 | 134 |
| 135 class SocketRecvFromFunction : public AsyncIOAPIFunction { |
| 136 protected: |
| 137 virtual bool Prepare() OVERRIDE; |
| 138 virtual void Work() OVERRIDE; |
| 139 virtual bool Respond() OVERRIDE; |
| 140 |
| 141 private: |
| 142 int socket_id_; |
| 143 net::IPEndPoint address_; |
| 144 |
| 145 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.recvFrom") |
| 146 }; |
| 147 |
| 148 class SocketSendToFunction : public AsyncIOAPIFunction { |
| 149 public: |
| 150 SocketSendToFunction(); |
| 151 virtual ~SocketSendToFunction(); |
| 152 |
| 153 protected: |
| 154 virtual bool Prepare() OVERRIDE; |
| 155 virtual void Work() OVERRIDE; |
| 156 virtual bool Respond() OVERRIDE; |
| 157 |
| 158 private: |
| 159 int socket_id_; |
| 160 scoped_refptr<net::IOBufferWithSize> io_buffer_; |
| 161 std::string address_; |
| 162 int port_; |
| 163 |
| 164 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.sendTo") |
| 165 }; |
| 166 |
| 120 } // namespace extensions | 167 } // namespace extensions |
| 121 | 168 |
| 122 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ | 169 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ |
| OLD | NEW |