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

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

Issue 76403004: An implementation of chrome.socket.secure(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed, @rsleevi's comments, added a new TLS test, further separated TLS and TCP tests, and reba… Created 6 years, 9 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 EXTENSIONS_BROWSER_API_SOCKET_SOCKET_API_H_ 5 #ifndef EXTENSIONS_BROWSER_API_SOCKET_SOCKET_API_H_
6 #define EXTENSIONS_BROWSER_API_SOCKET_SOCKET_API_H_ 6 #define EXTENSIONS_BROWSER_API_SOCKET_SOCKET_API_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
11 #include "base/memory/ref_counted.h" 11 #include "base/memory/ref_counted.h"
12 #include "extensions/browser/api/api_resource_manager.h" 12 #include "extensions/browser/api/api_resource_manager.h"
13 #include "extensions/browser/api/async_api_function.h" 13 #include "extensions/browser/api/async_api_function.h"
14 #include "extensions/browser/extension_function.h" 14 #include "extensions/browser/extension_function.h"
15 #include "extensions/common/api/socket.h" 15 #include "extensions/common/api/socket.h"
16 #include "net/base/address_list.h" 16 #include "net/base/address_list.h"
17 #include "net/dns/host_resolver.h" 17 #include "net/dns/host_resolver.h"
18 #include "net/socket/tcp_client_socket.h" 18 #include "net/socket/tcp_client_socket.h"
19 19
20 namespace content { 20 namespace content {
21 class BrowserContext; 21 class BrowserContext;
22 class ResourceContext; 22 class ResourceContext;
23 } 23 }
24 24
25 namespace net { 25 namespace net {
26 class IOBuffer; 26 class IOBuffer;
27 class URLRequestContextGetter;
28 class SSLClientSocket;
27 } 29 }
28 30
29 namespace extensions { 31 namespace extensions {
30 32 class TLSSocket;
31 class Socket; 33 class Socket;
32 34
33 // A simple interface to ApiResourceManager<Socket> or derived class. The goal 35 // A simple interface to ApiResourceManager<Socket> or derived class. The goal
34 // of this interface is to allow Socket API functions to use distinct instances 36 // of this interface is to allow Socket API functions to use distinct instances
35 // of ApiResourceManager<> depending on the type of socket (old version in 37 // of ApiResourceManager<> depending on the type of socket (old version in
36 // "socket" namespace vs new version in "socket.xxx" namespaces). 38 // "socket" namespace vs new version in "socket.xxx" namespaces).
37 class SocketResourceManagerInterface { 39 class SocketResourceManagerInterface {
38 public: 40 public:
39 virtual ~SocketResourceManagerInterface() {} 41 virtual ~SocketResourceManagerInterface() {}
40 42
41 virtual bool SetBrowserContext(content::BrowserContext* context) = 0; 43 virtual bool SetBrowserContext(content::BrowserContext* context) = 0;
42 virtual int Add(Socket* socket) = 0; 44 virtual int Add(Socket *socket) = 0;
43 virtual Socket* Get(const std::string& extension_id, int api_resource_id) = 0; 45 virtual Socket* Get(const std::string& extension_id,
44 virtual void Remove(const std::string& extension_id, int api_resource_id) = 0; 46 int api_resource_id) = 0;
47 virtual void Remove(const std::string& extension_id,
48 int api_resource_id) = 0;
49 virtual void Replace(const std::string& extension_id,
50 int api_resource_id,
51 Socket* socket) = 0;
45 virtual base::hash_set<int>* GetResourceIds( 52 virtual base::hash_set<int>* GetResourceIds(
46 const std::string& extension_id) = 0; 53 const std::string& extension_id) = 0;
47 }; 54 };
48 55
49 // Implementation of SocketResourceManagerInterface using an 56 // Implementation of SocketResourceManagerInterface using an
50 // ApiResourceManager<T> instance (where T derives from Socket). 57 // ApiResourceManager<T> instance (where T derives from Socket).
51 template <typename T> 58 template <typename T>
52 class SocketResourceManager : public SocketResourceManagerInterface { 59 class SocketResourceManager : public SocketResourceManagerInterface {
53 public: 60 public:
54 SocketResourceManager() : manager_(NULL) {} 61 SocketResourceManager() : manager_(NULL) {}
(...skipping 11 matching lines...) Expand all
66 virtual int Add(Socket* socket) OVERRIDE { 73 virtual int Add(Socket* socket) OVERRIDE {
67 // Note: Cast needed here, because "T" may be a subclass of "Socket". 74 // Note: Cast needed here, because "T" may be a subclass of "Socket".
68 return manager_->Add(static_cast<T*>(socket)); 75 return manager_->Add(static_cast<T*>(socket));
69 } 76 }
70 77
71 virtual Socket* Get(const std::string& extension_id, 78 virtual Socket* Get(const std::string& extension_id,
72 int api_resource_id) OVERRIDE { 79 int api_resource_id) OVERRIDE {
73 return manager_->Get(extension_id, api_resource_id); 80 return manager_->Get(extension_id, api_resource_id);
74 } 81 }
75 82
83 virtual void Replace(const std::string& extension_id,
84 int api_resource_id,
85 Socket* socket) OVERRIDE {
86 manager_->Replace(extension_id, api_resource_id, static_cast<T*>(socket));
87 }
88
76 virtual void Remove(const std::string& extension_id, 89 virtual void Remove(const std::string& extension_id,
77 int api_resource_id) OVERRIDE { 90 int api_resource_id) OVERRIDE {
78 manager_->Remove(extension_id, api_resource_id); 91 manager_->Remove(extension_id, api_resource_id);
79 } 92 }
80 93
81 virtual base::hash_set<int>* GetResourceIds(const std::string& extension_id) 94 virtual base::hash_set<int>* GetResourceIds(const std::string& extension_id)
82 OVERRIDE { 95 OVERRIDE {
83 return manager_->GetResourceIds(extension_id); 96 return manager_->GetResourceIds(extension_id);
84 } 97 }
85 98
(...skipping 10 matching lines...) Expand all
96 109
97 // AsyncApiFunction: 110 // AsyncApiFunction:
98 virtual bool PrePrepare() OVERRIDE; 111 virtual bool PrePrepare() OVERRIDE;
99 virtual bool Respond() OVERRIDE; 112 virtual bool Respond() OVERRIDE;
100 113
101 virtual scoped_ptr<SocketResourceManagerInterface> 114 virtual scoped_ptr<SocketResourceManagerInterface>
102 CreateSocketResourceManager(); 115 CreateSocketResourceManager();
103 116
104 int AddSocket(Socket* socket); 117 int AddSocket(Socket* socket);
105 Socket* GetSocket(int api_resource_id); 118 Socket* GetSocket(int api_resource_id);
119 void ReplaceSocket(int api_resource_id, Socket* socket);
106 void RemoveSocket(int api_resource_id); 120 void RemoveSocket(int api_resource_id);
107 base::hash_set<int>* GetSocketIds(); 121 base::hash_set<int>* GetSocketIds();
108 122
109 private: 123 private:
110 scoped_ptr<SocketResourceManagerInterface> manager_; 124 scoped_ptr<SocketResourceManagerInterface> manager_;
111 }; 125 };
112 126
113 class SocketExtensionWithDnsLookupFunction : public SocketAsyncApiFunction { 127 class SocketExtensionWithDnsLookupFunction : public SocketAsyncApiFunction {
114 protected: 128 protected:
115 SocketExtensionWithDnsLookupFunction(); 129 SocketExtensionWithDnsLookupFunction();
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 protected: 509 protected:
496 virtual ~SocketGetJoinedGroupsFunction(); 510 virtual ~SocketGetJoinedGroupsFunction();
497 511
498 // AsyncApiFunction 512 // AsyncApiFunction
499 virtual bool Prepare() OVERRIDE; 513 virtual bool Prepare() OVERRIDE;
500 virtual void Work() OVERRIDE; 514 virtual void Work() OVERRIDE;
501 515
502 private: 516 private:
503 scoped_ptr<core_api::socket::GetJoinedGroups::Params> params_; 517 scoped_ptr<core_api::socket::GetJoinedGroups::Params> params_;
504 }; 518 };
519
520 class SocketSecureFunction : public SocketAsyncApiFunction {
521 public:
522 DECLARE_EXTENSION_FUNCTION("socket.secure", SOCKET_SECURE);
523 SocketSecureFunction();
524
525 protected:
526 virtual ~SocketSecureFunction();
527
528 // AsyncApiFunction
529 virtual bool Prepare() OVERRIDE;
530 virtual void AsyncWorkStart() OVERRIDE;
531
532 private:
533 // Callback from TLSSocket::UpgradeSocketToTLS().
534 void TlsConnectDone(scoped_ptr<TLSSocket> socket, int result);
535
536 scoped_ptr<core_api::socket::Secure::Params> params_;
537 scoped_refptr<net::URLRequestContextGetter> url_request_getter_;
538
539 DISALLOW_COPY_AND_ASSIGN(SocketSecureFunction);
540 };
541
505 } // namespace extensions 542 } // namespace extensions
506 543
507 #endif // EXTENSIONS_BROWSER_API_SOCKET_SOCKET_API_H_ 544 #endif // EXTENSIONS_BROWSER_API_SOCKET_SOCKET_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698