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/threading/platform_thread.h" | 8 #include "base/threading/platform_thread.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/profiles/profile_manager.h" | 10 #include "chrome/browser/profiles/profile_manager.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 } | 73 } |
74 | 74 |
75 // ProxyResolverInterface override. | 75 // ProxyResolverInterface override. |
76 virtual void ResolveProxy( | 76 virtual void ResolveProxy( |
77 const std::string& source_url, | 77 const std::string& source_url, |
78 const std::string& signal_interface, | 78 const std::string& signal_interface, |
79 const std::string& signal_name, | 79 const std::string& signal_name, |
80 scoped_refptr<dbus::ExportedObject> exported_object) { | 80 scoped_refptr<dbus::ExportedObject> exported_object) { |
81 DCHECK(OnOriginThread()); | 81 DCHECK(OnOriginThread()); |
82 | 82 |
83 // GetDefaultProfile() must be called on UI thread. | 83 // GetDefaultProfile() and GetRequestContext() must be called on UI |
| 84 // thread. |
84 Profile* profile = ProfileManager::GetDefaultProfile(); | 85 Profile* profile = ProfileManager::GetDefaultProfile(); |
| 86 scoped_refptr<net::URLRequestContextGetter> getter = |
| 87 profile->GetRequestContext(); |
| 88 |
85 BrowserThread::PostTask( | 89 BrowserThread::PostTask( |
86 BrowserThread::IO, FROM_HERE, | 90 BrowserThread::IO, FROM_HERE, |
87 base::Bind(&ProxyResolverImpl::ResolveProxyInternal, | 91 base::Bind(&ProxyResolverImpl::ResolveProxyInternal, |
88 this, | 92 this, |
89 profile, | 93 getter, |
90 source_url, | 94 source_url, |
91 signal_interface, | 95 signal_interface, |
92 signal_name, | 96 signal_name, |
93 exported_object)); | 97 exported_object)); |
94 } | 98 } |
95 | 99 |
96 private: | 100 private: |
97 // Helper function for ResolveProxy(). | 101 // Helper function for ResolveProxy(). |
98 void ResolveProxyInternal( | 102 void ResolveProxyInternal( |
99 Profile* profile, | 103 scoped_refptr<net::URLRequestContextGetter> getter, |
100 const std::string& source_url, | 104 const std::string& source_url, |
101 const std::string& signal_interface, | 105 const std::string& signal_interface, |
102 const std::string& signal_name, | 106 const std::string& signal_name, |
103 scoped_refptr<dbus::ExportedObject> exported_object) { | 107 scoped_refptr<dbus::ExportedObject> exported_object) { |
104 // Make sure we're running on IO thread. | 108 // Make sure we're running on IO thread. |
105 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 109 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
106 | 110 |
107 // Create a request slot for this proxy resolution request. | 111 // Create a request slot for this proxy resolution request. |
108 Request* request = new Request(source_url); | 112 Request* request = new Request(source_url); |
109 request->notify_task_ = base::Bind( | 113 request->notify_task_ = base::Bind( |
110 &ProxyResolverImpl::NotifyProxyResolved, | 114 &ProxyResolverImpl::NotifyProxyResolved, |
111 this, | 115 this, |
112 signal_interface, | 116 signal_interface, |
113 signal_name, | 117 signal_name, |
114 exported_object, | 118 exported_object, |
115 request); | 119 request); |
116 // Queue request slot. | 120 // Queue request slot. |
117 { | 121 { |
118 base::AutoLock lock(data_lock_); | 122 base::AutoLock lock(data_lock_); |
119 all_requests_.push_back(request); | 123 all_requests_.push_back(request); |
120 } | 124 } |
121 | 125 |
122 // Check if we have the URLRequestContextGetter. | 126 // Check if we have the URLRequestContextGetter. |
123 scoped_refptr<net::URLRequestContextGetter> getter = | |
124 profile->GetRequestContext(); | |
125 if (!getter) { | 127 if (!getter) { |
126 request->error_ = "No URLRequestContextGetter"; | 128 request->error_ = "No URLRequestContextGetter"; |
127 request->OnCompletion(net::ERR_UNEXPECTED); | 129 request->OnCompletion(net::ERR_UNEXPECTED); |
128 return; | 130 return; |
129 } | 131 } |
130 | 132 |
131 // Retrieve ProxyService from profile's request context. | 133 // Retrieve ProxyService from profile's request context. |
132 net::ProxyService* proxy_service = | 134 net::ProxyService* proxy_service = |
133 getter->GetURLRequestContext()->proxy_service(); | 135 getter->GetURLRequestContext()->proxy_service(); |
134 if (!proxy_service) { | 136 if (!proxy_service) { |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 ProxyResolutionServiceProvider* | 265 ProxyResolutionServiceProvider* |
264 ProxyResolutionServiceProvider::CreateForTesting( | 266 ProxyResolutionServiceProvider::CreateForTesting( |
265 ProxyResolverInterface* resolver) { | 267 ProxyResolverInterface* resolver) { |
266 return new ProxyResolutionServiceProvider(resolver); | 268 return new ProxyResolutionServiceProvider(resolver); |
267 } | 269 } |
268 | 270 |
269 ProxyResolverInterface::~ProxyResolverInterface() { | 271 ProxyResolverInterface::~ProxyResolverInterface() { |
270 } | 272 } |
271 | 273 |
272 } // namespace chromeos | 274 } // namespace chromeos |
OLD | NEW |