| 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_CHROMEOS_DBUS_PROXY_RESOLUTION_SERVICE_PROVIDER_H_ | 5 #ifndef CHROMEOS_DBUS_SERVICES_PROXY_RESOLUTION_SERVICE_PROVIDER_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_DBUS_PROXY_RESOLUTION_SERVICE_PROVIDER_H_ | 6 #define CHROMEOS_DBUS_SERVICES_PROXY_RESOLUTION_SERVICE_PROVIDER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "chromeos/chromeos_export.h" |
| 14 #include "chromeos/dbus/services/cros_dbus_service.h" | 15 #include "chromeos/dbus/services/cros_dbus_service.h" |
| 15 #include "dbus/exported_object.h" | 16 #include "dbus/exported_object.h" |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class SingleThreadTaskRunner; | 19 class SingleThreadTaskRunner; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace dbus { | 22 namespace dbus { |
| 22 class MethodCall; | 23 class MethodCall; |
| 23 } | 24 } |
| 24 | 25 |
| 26 namespace net { |
| 27 class URLRequestContextGetter; |
| 28 } |
| 29 |
| 25 namespace chromeos { | 30 namespace chromeos { |
| 26 | 31 |
| 32 class ProxyResolverDelegate; |
| 27 class ProxyResolverInterface; | 33 class ProxyResolverInterface; |
| 28 | 34 |
| 29 // This class provides proxy resolution service for CrosDBusService. | 35 // This class provides proxy resolution service for CrosDBusService. |
| 30 // It processes proxy resolution requests for ChromeOS clients. | 36 // It processes proxy resolution requests for ChromeOS clients. |
| 31 // | 37 // |
| 32 // The following methods are exported. | 38 // The following methods are exported. |
| 33 // | 39 // |
| 34 // Interface: org.chromium.LibCrosServiceInterface (kLibCrosServiceInterface) | 40 // Interface: org.chromium.LibCrosServiceInterface (kLibCrosServiceInterface) |
| 35 // Method: ResolveNetworkProxy (kResolveNetworkProxy) | 41 // Method: ResolveNetworkProxy (kResolveNetworkProxy) |
| 36 // Parameters: string:source_url | 42 // Parameters: string:source_url |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 // look like: | 74 // look like: |
| 69 // | 75 // |
| 70 // signal sender=:1.23 -> dest=(null destination) serial=12345 | 76 // signal sender=:1.23 -> dest=(null destination) serial=12345 |
| 71 // path=/org/chromium/LibCrosService; interface=org.chromium.TestInterface; | 77 // path=/org/chromium/LibCrosService; interface=org.chromium.TestInterface; |
| 72 // member=TestSignal | 78 // member=TestSignal |
| 73 // string "http://www.gmail.com/" | 79 // string "http://www.gmail.com/" |
| 74 // string "PROXY proxy.example.com:8080" | 80 // string "PROXY proxy.example.com:8080" |
| 75 // string "" | 81 // string "" |
| 76 // | 82 // |
| 77 | 83 |
| 78 class ProxyResolutionServiceProvider | 84 class CHROMEOS_EXPORT ProxyResolutionServiceProvider |
| 79 : public CrosDBusService::ServiceProviderInterface { | 85 : public CrosDBusService::ServiceProviderInterface { |
| 80 public: | 86 public: |
| 81 virtual ~ProxyResolutionServiceProvider(); | 87 virtual ~ProxyResolutionServiceProvider(); |
| 82 | 88 |
| 83 // CrosDBusService::ServiceProviderInterface override. | 89 // CrosDBusService::ServiceProviderInterface override. |
| 84 virtual void Start( | 90 virtual void Start( |
| 85 scoped_refptr<dbus::ExportedObject> exported_object) override; | 91 scoped_refptr<dbus::ExportedObject> exported_object) override; |
| 86 | 92 |
| 87 // Creates the instance. | 93 // Creates the instance. |
| 88 static ProxyResolutionServiceProvider* Create(); | 94 static ProxyResolutionServiceProvider* Create( |
| 95 scoped_ptr<ProxyResolverDelegate> delgate); |
| 89 | 96 |
| 90 private: | 97 private: |
| 91 explicit ProxyResolutionServiceProvider(ProxyResolverInterface *resovler); | 98 explicit ProxyResolutionServiceProvider(ProxyResolverInterface *resovler); |
| 92 | 99 |
| 93 // Creates the instance for testing. Takes the ownership of |resovler| | 100 // Creates the instance for testing. Takes the ownership of |resovler| |
| 94 friend class ProxyResolutionServiceProviderTest; | 101 friend class ProxyResolutionServiceProviderTest; |
| 95 static ProxyResolutionServiceProvider* CreateForTesting( | 102 static ProxyResolutionServiceProvider* CreateForTesting( |
| 96 ProxyResolverInterface* resolver); | 103 ProxyResolverInterface* resolver); |
| 97 | 104 |
| 98 // Called from ExportedObject, when ResolveProxyHandler() is exported as | 105 // Called from ExportedObject, when ResolveProxyHandler() is exported as |
| (...skipping 19 matching lines...) Expand all Loading... |
| 118 bool OnOriginThread(); | 125 bool OnOriginThread(); |
| 119 | 126 |
| 120 scoped_refptr<dbus::ExportedObject> exported_object_; | 127 scoped_refptr<dbus::ExportedObject> exported_object_; |
| 121 scoped_ptr<ProxyResolverInterface> resolver_; | 128 scoped_ptr<ProxyResolverInterface> resolver_; |
| 122 scoped_refptr<base::SingleThreadTaskRunner> origin_thread_; | 129 scoped_refptr<base::SingleThreadTaskRunner> origin_thread_; |
| 123 base::WeakPtrFactory<ProxyResolutionServiceProvider> weak_ptr_factory_; | 130 base::WeakPtrFactory<ProxyResolutionServiceProvider> weak_ptr_factory_; |
| 124 | 131 |
| 125 DISALLOW_COPY_AND_ASSIGN(ProxyResolutionServiceProvider); | 132 DISALLOW_COPY_AND_ASSIGN(ProxyResolutionServiceProvider); |
| 126 }; | 133 }; |
| 127 | 134 |
| 135 // The delegate which provides necessary objects to the proxy resolver. |
| 136 class CHROMEOS_EXPORT ProxyResolverDelegate { |
| 137 public: |
| 138 virtual ~ProxyResolverDelegate() {} |
| 139 |
| 140 // Returns the request context used to perform proxy resolution. |
| 141 // Always called on UI thread. |
| 142 virtual scoped_refptr<net::URLRequestContextGetter> GetRequestContext() = 0; |
| 143 }; |
| 144 |
| 128 // The interface is defined so we can mock out the proxy resolver | 145 // The interface is defined so we can mock out the proxy resolver |
| 129 // implementation. | 146 // implementation. |
| 130 class ProxyResolverInterface { | 147 class CHROMEOS_EXPORT ProxyResolverInterface { |
| 131 public: | 148 public: |
| 132 // Resolves the proxy for the given URL. Returns the result as a | 149 // Resolves the proxy for the given URL. Returns the result as a |
| 133 // signal sent to |signal_interface| and | 150 // signal sent to |signal_interface| and |
| 134 // |signal_name|. |exported_object| will be used to send the | 151 // |signal_name|. |exported_object| will be used to send the |
| 135 // signal. The signal contains the three string members: | 152 // signal. The signal contains the three string members: |
| 136 // | 153 // |
| 137 // - source url: the requested source URL. | 154 // - source url: the requested source URL. |
| 138 // - proxy info: proxy info for the source URL in PAC format. | 155 // - proxy info: proxy info for the source URL in PAC format. |
| 139 // - error message: empty if the proxy resolution was successful. | 156 // - error message: empty if the proxy resolution was successful. |
| 140 virtual void ResolveProxy( | 157 virtual void ResolveProxy( |
| 141 const std::string& source_url, | 158 const std::string& source_url, |
| 142 const std::string& signal_interface, | 159 const std::string& signal_interface, |
| 143 const std::string& signal_name, | 160 const std::string& signal_name, |
| 144 scoped_refptr<dbus::ExportedObject> exported_object) = 0; | 161 scoped_refptr<dbus::ExportedObject> exported_object) = 0; |
| 145 | 162 |
| 146 virtual ~ProxyResolverInterface(); | 163 virtual ~ProxyResolverInterface(); |
| 147 }; | 164 }; |
| 148 | 165 |
| 149 } // namespace chromeos | 166 } // namespace chromeos |
| 150 | 167 |
| 151 #endif // CHROME_BROWSER_CHROMEOS_DBUS_PROXY_RESOLUTION_SERVICE_PROVIDER_H_ | 168 #endif // CHROMEOS_DBUS_SERVICES_PROXY_RESOLUTION_SERVICE_PROVIDER_H_ |
| OLD | NEW |