| OLD | NEW |
| 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 "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/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 return result; | 470 return result; |
| 471 | 471 |
| 472 effective_config_ = decider_->effective_config(); | 472 effective_config_ = decider_->effective_config(); |
| 473 script_data_ = decider_->script_data(); | 473 script_data_ = decider_->script_data(); |
| 474 | 474 |
| 475 next_state_ = STATE_SET_PAC_SCRIPT; | 475 next_state_ = STATE_SET_PAC_SCRIPT; |
| 476 return OK; | 476 return OK; |
| 477 } | 477 } |
| 478 | 478 |
| 479 int DoSetPacScript() { | 479 int DoSetPacScript() { |
| 480 DCHECK(script_data_); | 480 DCHECK(script_data_.get()); |
| 481 // TODO(eroman): Should log this latency to the NetLog. | 481 // TODO(eroman): Should log this latency to the NetLog. |
| 482 next_state_ = STATE_SET_PAC_SCRIPT_COMPLETE; | 482 next_state_ = STATE_SET_PAC_SCRIPT_COMPLETE; |
| 483 return proxy_resolver_->SetPacScript( | 483 return proxy_resolver_->SetPacScript( |
| 484 script_data_, | 484 script_data_, |
| 485 base::Bind(&InitProxyResolver::OnIOCompletion, base::Unretained(this))); | 485 base::Bind(&InitProxyResolver::OnIOCompletion, base::Unretained(this))); |
| 486 } | 486 } |
| 487 | 487 |
| 488 int DoSetPacScriptComplete(int result) { | 488 int DoSetPacScriptComplete(int result) { |
| 489 return result; | 489 return result; |
| 490 } | 490 } |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 | 667 |
| 668 if (result != OK) { | 668 if (result != OK) { |
| 669 // If it failed last time and failed again with the same error code this | 669 // If it failed last time and failed again with the same error code this |
| 670 // time, then nothing has actually changed. | 670 // time, then nothing has actually changed. |
| 671 return false; | 671 return false; |
| 672 } | 672 } |
| 673 | 673 |
| 674 // Otherwise if it succeeded both this time and last time, we need to look | 674 // Otherwise if it succeeded both this time and last time, we need to look |
| 675 // closer and see if we ended up downloading different content for the PAC | 675 // closer and see if we ended up downloading different content for the PAC |
| 676 // script. | 676 // script. |
| 677 return !script_data->Equals(last_script_data_); | 677 return !script_data->Equals(last_script_data_.get()); |
| 678 } | 678 } |
| 679 | 679 |
| 680 void NotifyProxyServiceOfChange( | 680 void NotifyProxyServiceOfChange( |
| 681 int result, | 681 int result, |
| 682 const scoped_refptr<ProxyResolverScriptData>& script_data, | 682 const scoped_refptr<ProxyResolverScriptData>& script_data, |
| 683 const ProxyConfig& effective_config) { | 683 const ProxyConfig& effective_config) { |
| 684 // Note that |this| may be deleted after calling into the ProxyService. | 684 // Note that |this| may be deleted after calling into the ProxyService. |
| 685 change_callback_.Run(result, script_data, effective_config); | 685 change_callback_.Run(result, script_data.get(), effective_config); |
| 686 } | 686 } |
| 687 | 687 |
| 688 base::WeakPtrFactory<ProxyScriptDeciderPoller> weak_factory_; | 688 base::WeakPtrFactory<ProxyScriptDeciderPoller> weak_factory_; |
| 689 | 689 |
| 690 ChangeCallback change_callback_; | 690 ChangeCallback change_callback_; |
| 691 ProxyConfig config_; | 691 ProxyConfig config_; |
| 692 bool proxy_resolver_expects_pac_bytes_; | 692 bool proxy_resolver_expects_pac_bytes_; |
| 693 ProxyScriptFetcher* proxy_script_fetcher_; | 693 ProxyScriptFetcher* proxy_script_fetcher_; |
| 694 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher_; | 694 DhcpProxyScriptFetcher* dhcp_proxy_script_fetcher_; |
| 695 | 695 |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 if (current_state_ == STATE_READY) { | 986 if (current_state_ == STATE_READY) { |
| 987 // Start the resolve request. | 987 // Start the resolve request. |
| 988 rv = req->Start(); | 988 rv = req->Start(); |
| 989 if (rv != ERR_IO_PENDING) | 989 if (rv != ERR_IO_PENDING) |
| 990 return req->QueryDidComplete(rv); | 990 return req->QueryDidComplete(rv); |
| 991 } else { | 991 } else { |
| 992 req->net_log()->BeginEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC); | 992 req->net_log()->BeginEvent(NetLog::TYPE_PROXY_SERVICE_WAITING_FOR_INIT_PAC); |
| 993 } | 993 } |
| 994 | 994 |
| 995 DCHECK_EQ(ERR_IO_PENDING, rv); | 995 DCHECK_EQ(ERR_IO_PENDING, rv); |
| 996 DCHECK(!ContainsPendingRequest(req)); | 996 DCHECK(!ContainsPendingRequest(req.get())); |
| 997 pending_requests_.push_back(req); | 997 pending_requests_.push_back(req); |
| 998 | 998 |
| 999 // Completion will be notified through |callback|, unless the caller cancels | 999 // Completion will be notified through |callback|, unless the caller cancels |
| 1000 // the request using |pac_request|. | 1000 // the request using |pac_request|. |
| 1001 if (pac_request) | 1001 if (pac_request) |
| 1002 *pac_request = req.get(); | 1002 *pac_request = req.get(); |
| 1003 return rv; // ERR_IO_PENDING | 1003 return rv; // ERR_IO_PENDING |
| 1004 } | 1004 } |
| 1005 | 1005 |
| 1006 int ProxyService::TryToCompleteSynchronously(const GURL& url, | 1006 int ProxyService::TryToCompleteSynchronously(const GURL& url, |
| (...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1358 base::ThreadTaskRunnerHandle::Get(); | 1358 base::ThreadTaskRunnerHandle::Get(); |
| 1359 | 1359 |
| 1360 // The file loop should be a MessageLoopForIO on Linux. | 1360 // The file loop should be a MessageLoopForIO on Linux. |
| 1361 DCHECK_EQ(base::MessageLoop::TYPE_IO, file_loop->type()); | 1361 DCHECK_EQ(base::MessageLoop::TYPE_IO, file_loop->type()); |
| 1362 | 1362 |
| 1363 // Synchronously fetch the current proxy config (since we are | 1363 // Synchronously fetch the current proxy config (since we are |
| 1364 // running on glib_default_loop). Additionally register for | 1364 // running on glib_default_loop). Additionally register for |
| 1365 // notifications (delivered in either |glib_default_loop| or | 1365 // notifications (delivered in either |glib_default_loop| or |
| 1366 // |file_loop|) to keep us updated when the proxy config changes. | 1366 // |file_loop|) to keep us updated when the proxy config changes. |
| 1367 linux_config_service->SetupAndFetchInitialConfig( | 1367 linux_config_service->SetupAndFetchInitialConfig( |
| 1368 glib_thread_task_runner, | 1368 glib_thread_task_runner.get(), |
| 1369 io_thread_task_runner, | 1369 io_thread_task_runner, |
| 1370 static_cast<base::MessageLoopForIO*>(file_loop)); | 1370 static_cast<base::MessageLoopForIO*>(file_loop)); |
| 1371 | 1371 |
| 1372 return linux_config_service; | 1372 return linux_config_service; |
| 1373 #elif defined(OS_ANDROID) | 1373 #elif defined(OS_ANDROID) |
| 1374 return new ProxyConfigServiceAndroid( | 1374 return new ProxyConfigServiceAndroid( |
| 1375 io_thread_task_runner, | 1375 io_thread_task_runner, |
| 1376 base::MessageLoop::current()->message_loop_proxy()); | 1376 base::MessageLoop::current()->message_loop_proxy()); |
| 1377 #else | 1377 #else |
| 1378 LOG(WARNING) << "Failed to choose a system proxy settings fetcher " | 1378 LOG(WARNING) << "Failed to choose a system proxy settings fetcher " |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1567 OnCompletion(result_); | 1567 OnCompletion(result_); |
| 1568 } | 1568 } |
| 1569 } | 1569 } |
| 1570 | 1570 |
| 1571 void SyncProxyServiceHelper::OnCompletion(int rv) { | 1571 void SyncProxyServiceHelper::OnCompletion(int rv) { |
| 1572 result_ = rv; | 1572 result_ = rv; |
| 1573 event_.Signal(); | 1573 event_.Signal(); |
| 1574 } | 1574 } |
| 1575 | 1575 |
| 1576 } // namespace net | 1576 } // namespace net |
| OLD | NEW |