OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/chromeos/dbus/proxy_resolution_service_provider.h" | 5 #include "chrome/browser/chromeos/dbus/proxy_resolution_service_provider.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
8 #include "base/threading/platform_thread.h" | 9 #include "base/threading/platform_thread.h" |
9 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/profiles/profile_manager.h" | 11 #include "chrome/browser/profiles/profile_manager.h" |
11 #include "dbus/bus.h" | 12 #include "dbus/bus.h" |
12 #include "dbus/message.h" | 13 #include "dbus/message.h" |
13 #include "dbus/exported_object.h" | 14 #include "dbus/exported_object.h" |
14 #include "net/base/net_errors.h" | 15 #include "net/base/net_errors.h" |
15 #include "net/proxy/proxy_service.h" | 16 #include "net/proxy/proxy_service.h" |
16 #include "net/url_request/url_request_context.h" | 17 #include "net/url_request/url_request_context.h" |
17 #include "net/url_request/url_request_context_getter.h" | 18 #include "net/url_request/url_request_context_getter.h" |
18 #include "third_party/cros_system_api/dbus/service_constants.h" | 19 #include "third_party/cros_system_api/dbus/service_constants.h" |
19 | 20 |
20 using content::BrowserThread; | 21 using content::BrowserThread; |
21 | 22 |
22 namespace chromeos { | 23 namespace chromeos { |
23 | 24 |
24 // The ProxyResolverInterface implementation used in production. | 25 // The ProxyResolverInterface implementation used in production. |
25 class ProxyResolverImpl : public ProxyResolverInterface { | 26 class ProxyResolverImpl : public ProxyResolverInterface { |
26 public: | 27 public: |
27 // Data being used in one proxy resolution. | 28 // Data being used in one proxy resolution. |
28 class Request { | 29 class Request { |
29 public: | 30 public: |
30 explicit Request(const std::string& source_url) | 31 explicit Request(const std::string& source_url) |
31 : ALLOW_THIS_IN_INITIALIZER_LIST( | 32 : ALLOW_THIS_IN_INITIALIZER_LIST(callback_( |
32 completion_callback_(this, &Request::OnCompletion)), | 33 base::Bind(&Request::OnCompletion, base::Unretained(this)))), |
33 source_url_(source_url) { | 34 source_url_(source_url) { |
34 } | 35 } |
35 | 36 |
36 virtual ~Request() {} | 37 virtual ~Request() {} |
37 | 38 |
38 // Callback on IO thread for when net::ProxyService::ResolveProxy | 39 // Callback on IO thread for when net::ProxyService::ResolveProxy |
39 // completes, synchronously or asynchronously. | 40 // completes, synchronously or asynchronously. |
40 void OnCompletion(int result) { | 41 void OnCompletion(int result) { |
41 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
42 // Generate the error message if the error message is not yet set, | 43 // Generate the error message if the error message is not yet set, |
43 // and there was an error. | 44 // and there was an error. |
44 if (error_.empty() && result != net::OK) | 45 if (error_.empty() && result != net::OK) |
45 error_ = net::ErrorToString(result); | 46 error_ = net::ErrorToString(result); |
46 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, notify_task_); | 47 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, notify_task_); |
47 } | 48 } |
48 | 49 |
49 net::OldCompletionCallbackImpl<Request> completion_callback_; | 50 net::CompletionCallback callback_; |
50 | 51 |
51 std::string source_url_; // URL being resolved. | 52 std::string source_url_; // URL being resolved. |
52 net::ProxyInfo proxy_info_; // ProxyInfo resolved for source_url_. | 53 net::ProxyInfo proxy_info_; // ProxyInfo resolved for source_url_. |
53 std::string error_; // Error from proxy resolution. | 54 std::string error_; // Error from proxy resolution. |
54 base::Closure notify_task_; // Task to notify of resolution result. | 55 base::Closure notify_task_; // Task to notify of resolution result. |
55 | 56 |
56 private: | 57 private: |
57 DISALLOW_COPY_AND_ASSIGN(Request); | 58 DISALLOW_COPY_AND_ASSIGN(Request); |
58 }; | 59 }; |
59 | 60 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 if (!proxy_service) { | 129 if (!proxy_service) { |
129 request->error_ = "No proxy service in chrome"; | 130 request->error_ = "No proxy service in chrome"; |
130 request->OnCompletion(net::ERR_UNEXPECTED); | 131 request->OnCompletion(net::ERR_UNEXPECTED); |
131 return; | 132 return; |
132 } | 133 } |
133 | 134 |
134 VLOG(1) << "Starting network proxy resolution for " | 135 VLOG(1) << "Starting network proxy resolution for " |
135 << request->source_url_; | 136 << request->source_url_; |
136 const int result = proxy_service->ResolveProxy( | 137 const int result = proxy_service->ResolveProxy( |
137 GURL(request->source_url_), &request->proxy_info_, | 138 GURL(request->source_url_), &request->proxy_info_, |
138 &request->completion_callback_, NULL, net::BoundNetLog()); | 139 request->callback_, NULL, net::BoundNetLog()); |
139 if (result != net::ERR_IO_PENDING) { | 140 if (result != net::ERR_IO_PENDING) { |
140 VLOG(1) << "Network proxy resolution completed synchronously."; | 141 VLOG(1) << "Network proxy resolution completed synchronously."; |
141 request->OnCompletion(result); | 142 request->OnCompletion(result); |
142 } | 143 } |
143 } | 144 } |
144 | 145 |
145 // Called on UI thread as task posted from Request::OnCompletion on IO | 146 // Called on UI thread as task posted from Request::OnCompletion on IO |
146 // thread. | 147 // thread. |
147 void NotifyProxyResolved( | 148 void NotifyProxyResolved( |
148 const std::string& signal_interface, | 149 const std::string& signal_interface, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 ProxyResolutionServiceProvider* | 274 ProxyResolutionServiceProvider* |
274 ProxyResolutionServiceProvider::CreateForTesting( | 275 ProxyResolutionServiceProvider::CreateForTesting( |
275 ProxyResolverInterface* resolver) { | 276 ProxyResolverInterface* resolver) { |
276 return new ProxyResolutionServiceProvider(resolver); | 277 return new ProxyResolutionServiceProvider(resolver); |
277 } | 278 } |
278 | 279 |
279 ProxyResolverInterface::~ProxyResolverInterface() { | 280 ProxyResolverInterface::~ProxyResolverInterface() { |
280 } | 281 } |
281 | 282 |
282 } // namespace chromeos | 283 } // namespace chromeos |
OLD | NEW |