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

Side by Side Diff: chrome/browser/chromeos/dbus/proxy_resolution_service_provider.h

Issue 743623002: Move ProxyResolutionServiceProvider to chromeos/dbus/services (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_DBUS_PROXY_RESOLUTION_SERVICE_PROVIDER_H_
6 #define CHROME_BROWSER_CHROMEOS_DBUS_PROXY_RESOLUTION_SERVICE_PROVIDER_H_
7
8 #include <string>
9
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "chromeos/dbus/services/cros_dbus_service.h"
15 #include "dbus/exported_object.h"
16
17 namespace base {
18 class SingleThreadTaskRunner;
19 }
20
21 namespace dbus {
22 class MethodCall;
23 }
24
25 namespace chromeos {
26
27 class ProxyResolverInterface;
28
29 // This class provides proxy resolution service for CrosDBusService.
30 // It processes proxy resolution requests for ChromeOS clients.
31 //
32 // The following methods are exported.
33 //
34 // Interface: org.chromium.LibCrosServiceInterface (kLibCrosServiceInterface)
35 // Method: ResolveNetworkProxy (kResolveNetworkProxy)
36 // Parameters: string:source_url
37 // string:signal_interface
38 // string:signal_name
39 //
40 // Resolves the proxy for |source_url|. Returns the result
41 // as a D-Bus signal sent to |signal_interface| and |signal_name|.
42 //
43 // The returned signal will contain the three values:
44 // - string:source_url - requested source URL.
45 // - string:proxy_info - proxy info for the source URL in PAC format
46 // like "PROXY cache.example.com:12345"
47 // - string:error_message - error message. Empty if successful.
48 //
49 // This service can be manually tested using dbus-monitor and
50 // dbus-send. For instance, you can resolve proxy configuration for
51 // http://www.gmail.com/ as follows:
52 //
53 // 1. Open a terminal and run the following:
54 //
55 // % dbus-monitor --system interface=org.chromium.TestInterface
56 //
57 // 2. Open another terminal and run the following:
58 //
59 // % dbus-send --system --type=method_call
60 // --dest=org.chromium.LibCrosService
61 // /org/chromium/LibCrosService
62 // org.chromium.LibCrosServiceInterface.ResolveNetworkProxy
63 // string:http://www.gmail.com/
64 // string:org.chromium.TestInterface
65 // string:TestSignal
66 //
67 // 3. Go back to the original terminal and check the output which should
68 // look like:
69 //
70 // signal sender=:1.23 -> dest=(null destination) serial=12345
71 // path=/org/chromium/LibCrosService; interface=org.chromium.TestInterface;
72 // member=TestSignal
73 // string "http://www.gmail.com/"
74 // string "PROXY proxy.example.com:8080"
75 // string ""
76 //
77
78 class ProxyResolutionServiceProvider
79 : public CrosDBusService::ServiceProviderInterface {
80 public:
81 virtual ~ProxyResolutionServiceProvider();
82
83 // CrosDBusService::ServiceProviderInterface override.
84 virtual void Start(
85 scoped_refptr<dbus::ExportedObject> exported_object) override;
86
87 // Creates the instance.
88 static ProxyResolutionServiceProvider* Create();
89
90 private:
91 explicit ProxyResolutionServiceProvider(ProxyResolverInterface *resovler);
92
93 // Creates the instance for testing. Takes the ownership of |resovler|
94 friend class ProxyResolutionServiceProviderTest;
95 static ProxyResolutionServiceProvider* CreateForTesting(
96 ProxyResolverInterface* resolver);
97
98 // Called from ExportedObject, when ResolveProxyHandler() is exported as
99 // a D-Bus method, or failed to be exported.
100 void OnExported(const std::string& interface_name,
101 const std::string& method_name,
102 bool success);
103
104 // Callback to be invoked when ChromeOS clients send network proxy
105 // resolution requests to the service running in chrome executable.
106 // Called on UI thread from dbus request.
107 void ResolveProxyHandler(dbus::MethodCall* method_call,
108 dbus::ExportedObject::ResponseSender response_sender);
109
110 // Calls ResolveProxyHandler() if weak_ptr is not NULL. Used to ensure a
111 // safe shutdown.
112 static void CallResolveProxyHandler(
113 base::WeakPtr<ProxyResolutionServiceProvider> weak_ptr,
114 dbus::MethodCall* method_call,
115 dbus::ExportedObject::ResponseSender response_sender);
116
117 // Returns true if the current thread is on the origin thread.
118 bool OnOriginThread();
119
120 scoped_refptr<dbus::ExportedObject> exported_object_;
121 scoped_ptr<ProxyResolverInterface> resolver_;
122 scoped_refptr<base::SingleThreadTaskRunner> origin_thread_;
123 base::WeakPtrFactory<ProxyResolutionServiceProvider> weak_ptr_factory_;
124
125 DISALLOW_COPY_AND_ASSIGN(ProxyResolutionServiceProvider);
126 };
127
128 // The interface is defined so we can mock out the proxy resolver
129 // implementation.
130 class ProxyResolverInterface {
131 public:
132 // Resolves the proxy for the given URL. Returns the result as a
133 // signal sent to |signal_interface| and
134 // |signal_name|. |exported_object| will be used to send the
135 // signal. The signal contains the three string members:
136 //
137 // - source url: the requested source URL.
138 // - proxy info: proxy info for the source URL in PAC format.
139 // - error message: empty if the proxy resolution was successful.
140 virtual void ResolveProxy(
141 const std::string& source_url,
142 const std::string& signal_interface,
143 const std::string& signal_name,
144 scoped_refptr<dbus::ExportedObject> exported_object) = 0;
145
146 virtual ~ProxyResolverInterface();
147 };
148
149 } // namespace chromeos
150
151 #endif // CHROME_BROWSER_CHROMEOS_DBUS_PROXY_RESOLUTION_SERVICE_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698