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

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

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
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 #include "chrome/browser/chromeos/dbus/proxy_resolution_service_provider.h" 5 #include "chromeos/dbus/services/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/bind_helpers.h"
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "chrome/browser/profiles/profile_manager.h"
11 #include "dbus/bus.h" 10 #include "dbus/bus.h"
11 #include "dbus/exported_object.h"
12 #include "dbus/message.h" 12 #include "dbus/message.h"
13 #include "dbus/exported_object.h"
14 #include "net/base/load_flags.h" 13 #include "net/base/load_flags.h"
15 #include "net/base/net_errors.h" 14 #include "net/base/net_errors.h"
16 #include "net/proxy/proxy_service.h" 15 #include "net/proxy/proxy_service.h"
17 #include "net/url_request/url_request_context.h" 16 #include "net/url_request/url_request_context.h"
18 #include "net/url_request/url_request_context_getter.h" 17 #include "net/url_request/url_request_context_getter.h"
19 #include "third_party/cros_system_api/dbus/service_constants.h" 18 #include "third_party/cros_system_api/dbus/service_constants.h"
20 19
21 namespace chromeos { 20 namespace chromeos {
22 21
23 // The ProxyResolverInterface implementation used in production. 22 // The ProxyResolverInterface implementation used in production.
(...skipping 20 matching lines...) Expand all
44 43
45 std::string source_url_; // URL being resolved. 44 std::string source_url_; // URL being resolved.
46 net::ProxyInfo proxy_info_; // ProxyInfo resolved for source_url_. 45 net::ProxyInfo proxy_info_; // ProxyInfo resolved for source_url_.
47 std::string error_; // Error from proxy resolution. 46 std::string error_; // Error from proxy resolution.
48 base::Closure notify_task_; // Task to notify of resolution result. 47 base::Closure notify_task_; // Task to notify of resolution result.
49 48
50 private: 49 private:
51 DISALLOW_COPY_AND_ASSIGN(Request); 50 DISALLOW_COPY_AND_ASSIGN(Request);
52 }; 51 };
53 52
54 ProxyResolverImpl() : origin_thread_(base::ThreadTaskRunnerHandle::Get()), 53 explicit ProxyResolverImpl(scoped_ptr<ProxyResolverDelegate> delegate)
55 weak_ptr_factory_(this) { 54 : delegate_(delegate.Pass()),
55 origin_thread_(base::ThreadTaskRunnerHandle::Get()),
56 weak_ptr_factory_(this) {
56 } 57 }
57 58
58 virtual ~ProxyResolverImpl() { 59 virtual ~ProxyResolverImpl() {
59 DCHECK(OnOriginThread()); 60 DCHECK(OnOriginThread());
60 61
61 for (std::set<Request*>::iterator iter = all_requests_.begin(); 62 for (std::set<Request*>::iterator iter = all_requests_.begin();
62 iter != all_requests_.end(); ++iter) { 63 iter != all_requests_.end(); ++iter) {
63 Request* request = *iter; 64 Request* request = *iter;
64 LOG(WARNING) << "Pending request for " << request->source_url_; 65 LOG(WARNING) << "Pending request for " << request->source_url_;
65 delete request; 66 delete request;
(...skipping 12 matching lines...) Expand all
78 Request* request = new Request(source_url); 79 Request* request = new Request(source_url);
79 request->notify_task_ = base::Bind( 80 request->notify_task_ = base::Bind(
80 &ProxyResolverImpl::NotifyProxyResolved, 81 &ProxyResolverImpl::NotifyProxyResolved,
81 weak_ptr_factory_.GetWeakPtr(), 82 weak_ptr_factory_.GetWeakPtr(),
82 signal_interface, 83 signal_interface,
83 signal_name, 84 signal_name,
84 exported_object, 85 exported_object,
85 request); 86 request);
86 all_requests_.insert(request); 87 all_requests_.insert(request);
87 88
88 // GetPrimaryUserProfile() and GetRequestContext() must be called on UI 89 // GetRequestContext() must be called on UI thread.
89 // thread.
90 Profile* profile = ProfileManager::GetPrimaryUserProfile();
91 scoped_refptr<net::URLRequestContextGetter> getter = 90 scoped_refptr<net::URLRequestContextGetter> getter =
92 profile->GetRequestContext(); 91 delegate_->GetRequestContext();
93 92
94 getter->GetNetworkTaskRunner()->PostTask( 93 getter->GetNetworkTaskRunner()->PostTask(
95 FROM_HERE, 94 FROM_HERE,
96 base::Bind(&ProxyResolverImpl::ResolveProxyInternal, 95 base::Bind(&ProxyResolverImpl::ResolveProxyInternal,
97 request, 96 request,
98 origin_thread_, 97 origin_thread_,
99 getter, 98 getter,
100 exported_object)); 99 exported_object));
101 } 100 }
102 101
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 all_requests_.erase(iter); 166 all_requests_.erase(iter);
168 } 167 }
169 delete request; 168 delete request;
170 } 169 }
171 170
172 // Returns true if the current thread is on the origin thread. 171 // Returns true if the current thread is on the origin thread.
173 bool OnOriginThread() { 172 bool OnOriginThread() {
174 return origin_thread_->BelongsToCurrentThread(); 173 return origin_thread_->BelongsToCurrentThread();
175 } 174 }
176 175
176 scoped_ptr<ProxyResolverDelegate> delegate_;
177 scoped_refptr<base::SingleThreadTaskRunner> origin_thread_; 177 scoped_refptr<base::SingleThreadTaskRunner> origin_thread_;
178 std::set<Request*> all_requests_; 178 std::set<Request*> all_requests_;
179 base::WeakPtrFactory<ProxyResolverImpl> weak_ptr_factory_; 179 base::WeakPtrFactory<ProxyResolverImpl> weak_ptr_factory_;
180 180
181 DISALLOW_COPY_AND_ASSIGN(ProxyResolverImpl); 181 DISALLOW_COPY_AND_ASSIGN(ProxyResolverImpl);
182 }; 182 };
183 183
184 ProxyResolutionServiceProvider::ProxyResolutionServiceProvider( 184 ProxyResolutionServiceProvider::ProxyResolutionServiceProvider(
185 ProxyResolverInterface* resolver) 185 ProxyResolverInterface* resolver)
186 : resolver_(resolver), 186 : resolver_(resolver),
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 dbus::MethodCall* method_call, 257 dbus::MethodCall* method_call,
258 dbus::ExportedObject::ResponseSender response_sender) { 258 dbus::ExportedObject::ResponseSender response_sender) {
259 if (!provider_weak_ptr) { 259 if (!provider_weak_ptr) {
260 LOG(WARNING) << "Called after the object is deleted"; 260 LOG(WARNING) << "Called after the object is deleted";
261 response_sender.Run(scoped_ptr<dbus::Response>()); 261 response_sender.Run(scoped_ptr<dbus::Response>());
262 return; 262 return;
263 } 263 }
264 provider_weak_ptr->ResolveProxyHandler(method_call, response_sender); 264 provider_weak_ptr->ResolveProxyHandler(method_call, response_sender);
265 } 265 }
266 266
267 ProxyResolutionServiceProvider* ProxyResolutionServiceProvider::Create() { 267 ProxyResolutionServiceProvider* ProxyResolutionServiceProvider::Create(
268 return new ProxyResolutionServiceProvider(new ProxyResolverImpl); 268 scoped_ptr<ProxyResolverDelegate> delegate) {
269 return new ProxyResolutionServiceProvider(
270 new ProxyResolverImpl(delegate.Pass()));
269 } 271 }
270 272
271 ProxyResolutionServiceProvider* 273 ProxyResolutionServiceProvider*
272 ProxyResolutionServiceProvider::CreateForTesting( 274 ProxyResolutionServiceProvider::CreateForTesting(
273 ProxyResolverInterface* resolver) { 275 ProxyResolverInterface* resolver) {
274 return new ProxyResolutionServiceProvider(resolver); 276 return new ProxyResolutionServiceProvider(resolver);
275 } 277 }
276 278
277 ProxyResolverInterface::~ProxyResolverInterface() { 279 ProxyResolverInterface::~ProxyResolverInterface() {
278 } 280 }
279 281
280 } // namespace chromeos 282 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698