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

Side by Side Diff: net/proxy/proxy_service.cc

Issue 525104: Adds a NetworkChangeNotifier dependency to ProxyService; when we observer a n... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Add a test_shell file Created 10 years, 11 months 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 | Annotate | Revision Log
« no previous file with comments | « net/proxy/proxy_service.h ('k') | net/proxy/proxy_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "net/proxy/proxy_service.h" 5 #include "net/proxy/proxy_service.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 ProxyInfo* results_; 191 ProxyInfo* results_;
192 GURL url_; 192 GURL url_;
193 ProxyResolver::RequestHandle resolve_job_; 193 ProxyResolver::RequestHandle resolve_job_;
194 ProxyConfig::ID config_id_; // The config id when the resolve was started. 194 ProxyConfig::ID config_id_; // The config id when the resolve was started.
195 scoped_refptr<LoadLog> load_log_; 195 scoped_refptr<LoadLog> load_log_;
196 }; 196 };
197 197
198 // ProxyService --------------------------------------------------------------- 198 // ProxyService ---------------------------------------------------------------
199 199
200 ProxyService::ProxyService(ProxyConfigService* config_service, 200 ProxyService::ProxyService(ProxyConfigService* config_service,
201 ProxyResolver* resolver) 201 ProxyResolver* resolver,
202 NetworkChangeNotifier* network_change_notifier)
202 : config_service_(config_service), 203 : config_service_(config_service),
203 resolver_(resolver), 204 resolver_(resolver),
204 next_config_id_(1), 205 next_config_id_(1),
205 should_use_proxy_resolver_(false), 206 should_use_proxy_resolver_(false),
206 ALLOW_THIS_IN_INITIALIZER_LIST(init_proxy_resolver_callback_( 207 ALLOW_THIS_IN_INITIALIZER_LIST(init_proxy_resolver_callback_(
207 this, &ProxyService::OnInitProxyResolverComplete)) { 208 this, &ProxyService::OnInitProxyResolverComplete)),
209 network_change_notifier_(network_change_notifier) {
210 // Register to receive network change notifications.
211 if (network_change_notifier_)
212 network_change_notifier_->AddObserver(this);
208 } 213 }
209 214
210 // static 215 // static
211 ProxyService* ProxyService::Create( 216 ProxyService* ProxyService::Create(
212 ProxyConfigService* proxy_config_service, 217 ProxyConfigService* proxy_config_service,
213 bool use_v8_resolver, 218 bool use_v8_resolver,
214 URLRequestContext* url_request_context, 219 URLRequestContext* url_request_context,
220 NetworkChangeNotifier* network_change_notifier,
215 MessageLoop* io_loop) { 221 MessageLoop* io_loop) {
216 ProxyResolver* proxy_resolver; 222 ProxyResolver* proxy_resolver;
217 223
218 if (use_v8_resolver) { 224 if (use_v8_resolver) {
219 // Send javascript errors and alerts to LOG(INFO). 225 // Send javascript errors and alerts to LOG(INFO).
220 HostResolver* host_resolver = url_request_context->host_resolver(); 226 HostResolver* host_resolver = url_request_context->host_resolver();
221 ProxyResolverJSBindings* js_bindings = 227 ProxyResolverJSBindings* js_bindings =
222 ProxyResolverJSBindings::CreateDefault(host_resolver, io_loop); 228 ProxyResolverJSBindings::CreateDefault(host_resolver, io_loop);
223 229
224 proxy_resolver = new ProxyResolverV8(js_bindings); 230 proxy_resolver = new ProxyResolverV8(js_bindings);
225 } else { 231 } else {
226 proxy_resolver = CreateNonV8ProxyResolver(); 232 proxy_resolver = CreateNonV8ProxyResolver();
227 } 233 }
228 234
229 // Wrap the (synchronous) ProxyResolver implementation in a single-threaded 235 // Wrap the (synchronous) ProxyResolver implementation in a single-threaded
230 // runner. This will dispatch requests to a threadpool of size 1. 236 // runner. This will dispatch requests to a threadpool of size 1.
231 proxy_resolver = new SingleThreadedProxyResolver(proxy_resolver); 237 proxy_resolver = new SingleThreadedProxyResolver(proxy_resolver);
232 238
233 ProxyService* proxy_service = new ProxyService( 239 ProxyService* proxy_service = new ProxyService(
234 proxy_config_service, proxy_resolver); 240 proxy_config_service, proxy_resolver, network_change_notifier);
235 241
236 if (proxy_resolver->expects_pac_bytes()) { 242 if (proxy_resolver->expects_pac_bytes()) {
237 // Configure PAC script downloads to be issued using |url_request_context|. 243 // Configure PAC script downloads to be issued using |url_request_context|.
238 DCHECK(url_request_context); 244 DCHECK(url_request_context);
239 proxy_service->SetProxyScriptFetcher( 245 proxy_service->SetProxyScriptFetcher(
240 ProxyScriptFetcher::Create(url_request_context)); 246 ProxyScriptFetcher::Create(url_request_context));
241 } 247 }
242 248
243 return proxy_service; 249 return proxy_service;
244 } 250 }
245 251
246 // static 252 // static
247 ProxyService* ProxyService::CreateFixed(const ProxyConfig& pc) { 253 ProxyService* ProxyService::CreateFixed(const ProxyConfig& pc) {
248 return Create(new ProxyConfigServiceFixed(pc), false, NULL, NULL); 254 return Create(new ProxyConfigServiceFixed(pc), false, NULL, NULL, NULL);
249 } 255 }
250 256
251 // static 257 // static
252 ProxyService* ProxyService::CreateNull() { 258 ProxyService* ProxyService::CreateNull() {
253 // Use a configuration fetcher and proxy resolver which always fail. 259 // Use a configuration fetcher and proxy resolver which always fail.
254 return new ProxyService(new ProxyConfigServiceNull, new ProxyResolverNull); 260 return new ProxyService(new ProxyConfigServiceNull,
261 new ProxyResolverNull,
262 NULL);
255 } 263 }
256 264
257 int ProxyService::ResolveProxy(const GURL& raw_url, 265 int ProxyService::ResolveProxy(const GURL& raw_url,
258 ProxyInfo* result, 266 ProxyInfo* result,
259 CompletionCallback* callback, 267 CompletionCallback* callback,
260 PacRequest** pac_request, 268 PacRequest** pac_request,
261 LoadLog* load_log) { 269 LoadLog* load_log) {
262 DCHECK(callback); 270 DCHECK(callback);
263 271
264 LoadLog::BeginEvent(load_log, LoadLog::TYPE_PROXY_SERVICE); 272 LoadLog::BeginEvent(load_log, LoadLog::TYPE_PROXY_SERVICE);
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 break; 355 break;
348 } 356 }
349 default: 357 default:
350 result->UseDirect(); 358 result->UseDirect();
351 NOTREACHED(); 359 NOTREACHED();
352 break; 360 break;
353 } 361 }
354 } 362 }
355 363
356 ProxyService::~ProxyService() { 364 ProxyService::~ProxyService() {
365 // Unregister to receive network change notifications.
366 if (network_change_notifier_)
367 network_change_notifier_->RemoveObserver(this);
368
357 // Cancel any inprogress requests. 369 // Cancel any inprogress requests.
358 for (PendingRequests::iterator it = pending_requests_.begin(); 370 for (PendingRequests::iterator it = pending_requests_.begin();
359 it != pending_requests_.end(); 371 it != pending_requests_.end();
360 ++it) { 372 ++it) {
361 (*it)->Cancel(); 373 (*it)->Cancel();
362 } 374 }
363 } 375 }
364 376
365 void ProxyService::SuspendAllPendingRequests() { 377 void ProxyService::SuspendAllPendingRequests() {
366 for (PendingRequests::iterator it = pending_requests_.begin(); 378 for (PendingRequests::iterator it = pending_requests_.begin();
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 // regardless of what they map to. 741 // regardless of what they map to.
730 // 742 //
731 // static 743 // static
732 bool ProxyService::IsLocalName(const GURL& url) { 744 bool ProxyService::IsLocalName(const GURL& url) {
733 const std::string& host = url.host(); 745 const std::string& host = url.host();
734 if (host == "127.0.0.1" || host == "[::1]") 746 if (host == "127.0.0.1" || host == "[::1]")
735 return true; 747 return true;
736 return host.find('.') == std::string::npos; 748 return host.find('.') == std::string::npos;
737 } 749 }
738 750
751 void ProxyService::OnIPAddressChanged() {
752 DCHECK(network_change_notifier_);
753
754 // Mark the current configuration as being un-initialized.
755 //
756 // This will force us to re-fetch the configuration (and re-run all of
757 // the initialization steps) on the next ResolveProxy() request, as part
758 // of UpdateConfigIfOld().
759 config_.set_id(ProxyConfig::INVALID_ID);
760 }
761
739 SyncProxyServiceHelper::SyncProxyServiceHelper(MessageLoop* io_message_loop, 762 SyncProxyServiceHelper::SyncProxyServiceHelper(MessageLoop* io_message_loop,
740 ProxyService* proxy_service) 763 ProxyService* proxy_service)
741 : io_message_loop_(io_message_loop), 764 : io_message_loop_(io_message_loop),
742 proxy_service_(proxy_service), 765 proxy_service_(proxy_service),
743 event_(false, false), 766 event_(false, false),
744 ALLOW_THIS_IN_INITIALIZER_LIST(callback_( 767 ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
745 this, &SyncProxyServiceHelper::OnCompletion)) { 768 this, &SyncProxyServiceHelper::OnCompletion)) {
746 DCHECK(io_message_loop_ != MessageLoop::current()); 769 DCHECK(io_message_loop_ != MessageLoop::current());
747 } 770 }
748 771
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
794 OnCompletion(result_); 817 OnCompletion(result_);
795 } 818 }
796 } 819 }
797 820
798 void SyncProxyServiceHelper::OnCompletion(int rv) { 821 void SyncProxyServiceHelper::OnCompletion(int rv) {
799 result_ = rv; 822 result_ = rv;
800 event_.Signal(); 823 event_.Signal();
801 } 824 }
802 825
803 } // namespace net 826 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_service.h ('k') | net/proxy/proxy_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698