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

Side by Side Diff: chromeos/dbus/services/proxy_resolution_service_provider.h

Issue 2775503002: chromeos:: Remove pointless ProxyResolverInterface. (Closed)
Patch Set: fix typo in existing comment Created 3 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
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 CHROMEOS_DBUS_SERVICES_PROXY_RESOLUTION_SERVICE_PROVIDER_H_ 5 #ifndef CHROMEOS_DBUS_SERVICES_PROXY_RESOLUTION_SERVICE_PROVIDER_H_
6 #define CHROMEOS_DBUS_SERVICES_PROXY_RESOLUTION_SERVICE_PROVIDER_H_ 6 #define CHROMEOS_DBUS_SERVICES_PROXY_RESOLUTION_SERVICE_PROVIDER_H_
7 7
8 #include <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
(...skipping 16 matching lines...) Expand all
27 } 27 }
28 28
29 namespace net { 29 namespace net {
30 class ProxyInfo; 30 class ProxyInfo;
31 class ProxyService; 31 class ProxyService;
32 class URLRequestContextGetter; 32 class URLRequestContextGetter;
33 } 33 }
34 34
35 namespace chromeos { 35 namespace chromeos {
36 36
37 class ProxyResolverDelegate;
38 class ProxyResolverInterface;
39
40 // This class provides proxy resolution service for CrosDBusService. 37 // This class provides proxy resolution service for CrosDBusService.
41 // It processes proxy resolution requests for ChromeOS clients. 38 // It processes proxy resolution requests for ChromeOS clients.
42 // 39 //
43 // The following methods are exported. 40 // The following methods are exported.
44 // 41 //
45 // Interface: org.chromium.LibCrosServiceInterface (kLibCrosServiceInterface) 42 // Interface: org.chromium.LibCrosServiceInterface (kLibCrosServiceInterface)
46 // Method: ResolveNetworkProxy (kResolveNetworkProxy) 43 // Method: ResolveNetworkProxy (kResolveNetworkProxy)
47 // Parameters: string:source_url 44 // Parameters: string:source_url
48 // string:signal_interface 45 // string:signal_interface
49 // string:signal_name 46 // string:signal_name
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // path=/org/chromium/LibCrosService; interface=org.chromium.TestInterface; 79 // path=/org/chromium/LibCrosService; interface=org.chromium.TestInterface;
83 // member=TestSignal 80 // member=TestSignal
84 // string "http://www.gmail.com/" 81 // string "http://www.gmail.com/"
85 // string "PROXY proxy.example.com:8080" 82 // string "PROXY proxy.example.com:8080"
86 // string "" 83 // string ""
87 // 84 //
88 85
89 class CHROMEOS_EXPORT ProxyResolutionServiceProvider 86 class CHROMEOS_EXPORT ProxyResolutionServiceProvider
90 : public CrosDBusService::ServiceProviderInterface { 87 : public CrosDBusService::ServiceProviderInterface {
91 public: 88 public:
89 // Delegate interface providing additional resources to
90 // ProxyResolutionServiceProvider.
91 class CHROMEOS_EXPORT Delegate {
92 public:
93 virtual ~Delegate() {}
94
95 // Returns the request context used to perform proxy resolution.
96 // Always called on UI thread.
97 virtual scoped_refptr<net::URLRequestContextGetter> GetRequestContext() = 0;
98
99 // Thin wrapper around net::ProxyService::ResolveProxy() to make testing
100 // easier.
101 virtual int ResolveProxy(net::ProxyService* proxy_service,
102 const GURL& url,
103 net::ProxyInfo* results,
104 const net::CompletionCallback& callback) = 0;
105 };
106
107 explicit ProxyResolutionServiceProvider(std::unique_ptr<Delegate> delegate);
92 ~ProxyResolutionServiceProvider() override; 108 ~ProxyResolutionServiceProvider() override;
93 109
94 // CrosDBusService::ServiceProviderInterface override. 110 // CrosDBusService::ServiceProviderInterface:
95 void Start(scoped_refptr<dbus::ExportedObject> exported_object) override; 111 void Start(scoped_refptr<dbus::ExportedObject> exported_object) override;
96 112
97 // Creates the instance. 113 private:
98 static ProxyResolutionServiceProvider* Create( 114 // Data used for a single proxy resolution.
99 std::unique_ptr<ProxyResolverDelegate> delgate); 115 struct Request;
100 116
101 private: 117 // Returns true if called on |origin_thread_|.
102 explicit ProxyResolutionServiceProvider(ProxyResolverInterface *resovler); 118 bool OnOriginThread();
103 119
104 // Called from ExportedObject, when ResolveProxyHandler() is exported as 120 // Called when ResolveProxy() is exported as a D-Bus method.
105 // a D-Bus method, or failed to be exported.
106 void OnExported(const std::string& interface_name, 121 void OnExported(const std::string& interface_name,
107 const std::string& method_name, 122 const std::string& method_name,
108 bool success); 123 bool success);
109 124
110 // Callback to be invoked when ChromeOS clients send network proxy 125 // Callback invoked when Chrome OS clients send network proxy resolution
111 // resolution requests to the service running in chrome executable. 126 // requests to the service. Called on UI thread.
112 // Called on UI thread from dbus request. 127 void ResolveProxy(dbus::MethodCall* method_call,
113 void ResolveProxyHandler(dbus::MethodCall* method_call, 128 dbus::ExportedObject::ResponseSender response_sender);
114 dbus::ExportedObject::ResponseSender response_sender);
115 129
116 // Calls ResolveProxyHandler() if weak_ptr is not NULL. Used to ensure a 130 // Helper method for ResolveProxy() that runs on network thread.
117 // safe shutdown. 131 void ResolveProxyOnNetworkThread(std::unique_ptr<Request> request);
118 static void CallResolveProxyHandler(
119 base::WeakPtr<ProxyResolutionServiceProvider> weak_ptr,
120 dbus::MethodCall* method_call,
121 dbus::ExportedObject::ResponseSender response_sender);
122 132
123 // Returns true if the current thread is on the origin thread. 133 // Callback on network thread for when net::ProxyService::ResolveProxy()
124 bool OnOriginThread(); 134 // completes, synchronously or asynchronously.
135 void OnResolutionComplete(std::unique_ptr<Request> request, int result);
125 136
137 // Called on UI thread from OnResolutionComplete() to pass the resolved proxy
138 // information to the client over D-Bus.
139 void NotifyProxyResolved(std::unique_ptr<Request> request);
140
141 std::unique_ptr<Delegate> delegate_;
126 scoped_refptr<dbus::ExportedObject> exported_object_; 142 scoped_refptr<dbus::ExportedObject> exported_object_;
127 std::unique_ptr<ProxyResolverInterface> resolver_;
128 scoped_refptr<base::SingleThreadTaskRunner> origin_thread_; 143 scoped_refptr<base::SingleThreadTaskRunner> origin_thread_;
129 base::WeakPtrFactory<ProxyResolutionServiceProvider> weak_ptr_factory_; 144 base::WeakPtrFactory<ProxyResolutionServiceProvider> weak_ptr_factory_;
130 145
131 DISALLOW_COPY_AND_ASSIGN(ProxyResolutionServiceProvider); 146 DISALLOW_COPY_AND_ASSIGN(ProxyResolutionServiceProvider);
132 }; 147 };
133 148
134 // The delegate which provides necessary objects to the proxy resolver.
135 class CHROMEOS_EXPORT ProxyResolverDelegate {
136 public:
137 virtual ~ProxyResolverDelegate() {}
138
139 // Returns the request context used to perform proxy resolution.
140 // Always called on UI thread.
141 virtual scoped_refptr<net::URLRequestContextGetter> GetRequestContext() = 0;
142
143 // Thin wrapper around net::ProxyService::ResolveProxy() to make testing
144 // easier.
145 virtual int ResolveProxy(net::ProxyService* proxy_service,
146 const GURL& url,
147 net::ProxyInfo* results,
148 const net::CompletionCallback& callback) = 0;
149 };
150
151 // The interface is defined so we can mock out the proxy resolver
152 // implementation.
153 class CHROMEOS_EXPORT ProxyResolverInterface {
154 public:
155 // Resolves the proxy for the given URL. Returns the result as a
156 // signal sent to |signal_interface| and
157 // |signal_name|. |exported_object| will be used to send the
158 // signal. The signal contains the three string members:
159 //
160 // - source url: the requested source URL.
161 // - proxy info: proxy info for the source URL in PAC format.
162 // - error message: empty if the proxy resolution was successful.
163 virtual void ResolveProxy(
164 const std::string& source_url,
165 const std::string& signal_interface,
166 const std::string& signal_name,
167 scoped_refptr<dbus::ExportedObject> exported_object) = 0;
168
169 virtual ~ProxyResolverInterface();
170 };
171
172 } // namespace chromeos 149 } // namespace chromeos
173 150
174 #endif // CHROMEOS_DBUS_SERVICES_PROXY_RESOLUTION_SERVICE_PROVIDER_H_ 151 #endif // CHROMEOS_DBUS_SERVICES_PROXY_RESOLUTION_SERVICE_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698