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

Side by Side Diff: chrome/browser/extensions/api/socket/socket_api.h

Issue 10537017: Allow hostnames in socket.connect(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: mihaip's comments + clang fix. Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "chrome/common/extensions/api/experimental_socket.h" 11 #include "chrome/common/extensions/api/experimental_socket.h"
12 #include "net/base/address_list.h"
13 #include "net/base/host_resolver.h"
12 14
13 #include <string> 15 #include <string>
14 16
15 namespace net { 17 namespace net {
16 class IOBuffer; 18 class IOBuffer;
17 } 19 }
18 20
21 class IOThread;
22
19 namespace extensions { 23 namespace extensions {
20 24
21 class APIResourceController; 25 class APIResourceController;
22 class APIResourceEventNotifier; 26 class APIResourceEventNotifier;
23 27
24 class SocketExtensionFunction : public AsyncAPIFunction { 28 class SocketExtensionFunction : public AsyncAPIFunction {
25 protected: 29 protected:
26 virtual ~SocketExtensionFunction() {} 30 virtual ~SocketExtensionFunction() {}
27 31
28 // AsyncAPIFunction: 32 // AsyncAPIFunction:
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 virtual void Work() OVERRIDE; 77 virtual void Work() OVERRIDE;
74 78
75 private: 79 private:
76 int socket_id_; 80 int socket_id_;
77 }; 81 };
78 82
79 class SocketConnectFunction : public SocketExtensionFunction { 83 class SocketConnectFunction : public SocketExtensionFunction {
80 public: 84 public:
81 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.connect") 85 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.connect")
82 86
87 SocketConnectFunction();
88
83 protected: 89 protected:
84 virtual ~SocketConnectFunction() {} 90 virtual ~SocketConnectFunction();
85 91
86 // AsyncAPIFunction: 92 // AsyncAPIFunction:
87 virtual bool Prepare() OVERRIDE; 93 virtual bool Prepare() OVERRIDE;
88 virtual void AsyncWorkStart() OVERRIDE; 94 virtual void AsyncWorkStart() OVERRIDE;
89 void OnCompleted(int result);
90 95
91 private: 96 private:
97 void StartDnsLookup();
98 void OnDnsLookup(int resolve_result);
99 void StartConnect();
100 void OnConnect(int result);
101
92 int socket_id_; 102 int socket_id_;
93 std::string address_; 103 std::string hostname_;
104 std::string resolved_address_;
94 int port_; 105 int port_;
106
107 // This instance is widely available through BrowserProcess, but we need to
108 // acquire it on the UI thread and then use it on the IO thread, so we keep a
109 // plain pointer to it here as we move from thread to thread.
110 IOThread* io_thread_;
111
112 scoped_ptr<net::HostResolver::RequestHandle> request_handle_;
113 scoped_ptr<net::AddressList> addresses_;
95 }; 114 };
96 115
97 class SocketDisconnectFunction : public SocketExtensionFunction { 116 class SocketDisconnectFunction : public SocketExtensionFunction {
98 public: 117 public:
99 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.disconnect") 118 DECLARE_EXTENSION_FUNCTION_NAME("experimental.socket.disconnect")
100 119
101 protected: 120 protected:
102 virtual ~SocketDisconnectFunction() {} 121 virtual ~SocketDisconnectFunction() {}
103 122
104 // AsyncAPIFunction: 123 // AsyncAPIFunction:
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 virtual bool Prepare() OVERRIDE; 256 virtual bool Prepare() OVERRIDE;
238 virtual void Work() OVERRIDE; 257 virtual void Work() OVERRIDE;
239 258
240 private: 259 private:
241 scoped_ptr<api::experimental_socket::SetNoDelay::Params> params_; 260 scoped_ptr<api::experimental_socket::SetNoDelay::Params> params_;
242 }; 261 };
243 262
244 } // namespace extensions 263 } // namespace extensions
245 264
246 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_ 265 #endif // CHROME_BROWSER_EXTENSIONS_API_SOCKET_SOCKET_API_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/dns/mock_host_resolver_creator.cc ('k') | chrome/browser/extensions/api/socket/socket_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698