summaryrefslogtreecommitdiffstats
path: root/net/proxy
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-31 01:34:20 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-31 01:34:20 +0000
commit41b2780f0135d23196958816d3adcfd606b80f1e (patch)
tree306a00be7404dfc6d3ff9ef667d35827f87281a2 /net/proxy
parent18a12354e6c3e1edf2f85e11cd7359127d2d3ce2 (diff)
downloadchromium_src-41b2780f0135d23196958816d3adcfd606b80f1e.zip
chromium_src-41b2780f0135d23196958816d3adcfd606b80f1e.tar.gz
chromium_src-41b2780f0135d23196958816d3adcfd606b80f1e.tar.bz2
Move proxy resolve requests out of plugin/renderer process, and into the browser.
Review URL: http://codereview.chromium.org/14142 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9006 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy')
-rw-r--r--net/proxy/proxy_service.cc65
-rw-r--r--net/proxy/proxy_service.h26
2 files changed, 89 insertions, 2 deletions
diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc
index f1c9865..4745bce 100644
--- a/net/proxy/proxy_service.cc
+++ b/net/proxy/proxy_service.cc
@@ -11,6 +11,7 @@
#include <algorithm>
+#include "base/compiler_specific.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/string_tokenizer.h"
@@ -522,7 +523,7 @@ bool ProxyService::ShouldBypassProxyForURL(const GURL& url) {
if (url.host().find('.') == std::string::npos)
return true;
}
-
+
for(std::vector<std::string>::const_iterator i = config_.proxy_bypass.begin();
i != config_.proxy_bypass.end(); ++i) {
std::string bypass_url_domain = *i;
@@ -543,7 +544,7 @@ bool ProxyService::ShouldBypassProxyForURL(const GURL& url) {
if (MatchPattern(url_domain, bypass_url_domain))
return true;
-
+
// Some systems (the Mac, for example) allow CIDR-style specification of
// proxy bypass for IP-specified hosts (e.g. "10.0.0.0/8"; see
// http://www.tcd.ie/iss/internet/osx_proxy.php for a real-world example).
@@ -554,5 +555,65 @@ bool ProxyService::ShouldBypassProxyForURL(const GURL& url) {
return false;
}
+SyncProxyServiceHelper::SyncProxyServiceHelper(MessageLoop* io_message_loop,
+ ProxyService* proxy_service)
+ : io_message_loop_(io_message_loop),
+ proxy_service_(proxy_service),
+ event_(false, false),
+ ALLOW_THIS_IN_INITIALIZER_LIST(callback_(
+ this, &SyncProxyServiceHelper::OnCompletion)) {
+ DCHECK(io_message_loop_ != MessageLoop::current());
+}
+
+int SyncProxyServiceHelper::ResolveProxy(const GURL& url,
+ ProxyInfo* proxy_info) {
+ DCHECK(io_message_loop_ != MessageLoop::current());
+
+ io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
+ this, &SyncProxyServiceHelper::StartAsyncResolve, url));
+
+ event_.Wait();
+
+ if (result_ == net::OK) {
+ *proxy_info = proxy_info_;
+ }
+ return result_;
+}
+
+int SyncProxyServiceHelper::ReconsiderProxyAfterError(const GURL& url,
+ ProxyInfo* proxy_info) {
+ DCHECK(io_message_loop_ != MessageLoop::current());
+
+ io_message_loop_->PostTask(FROM_HERE, NewRunnableMethod(
+ this, &SyncProxyServiceHelper::StartAsyncReconsider, url));
+
+ event_.Wait();
+
+ if (result_ == net::OK) {
+ *proxy_info = proxy_info_;
+ }
+ return result_;
+}
+
+void SyncProxyServiceHelper::StartAsyncResolve(const GURL& url) {
+ result_ = proxy_service_->ResolveProxy(url, &proxy_info_, &callback_, NULL);
+ if (result_ != net::ERR_IO_PENDING) {
+ OnCompletion(result_);
+ }
+}
+
+void SyncProxyServiceHelper::StartAsyncReconsider(const GURL& url) {
+ result_ = proxy_service_->ReconsiderProxyAfterError(
+ url, &proxy_info_, &callback_, NULL);
+ if (result_ != net::ERR_IO_PENDING) {
+ OnCompletion(result_);
+ }
+}
+
+void SyncProxyServiceHelper::OnCompletion(int rv) {
+ result_ = rv;
+ event_.Signal();
+}
+
} // namespace net
diff --git a/net/proxy/proxy_service.h b/net/proxy/proxy_service.h
index 1d528dc..846a2d9 100644
--- a/net/proxy/proxy_service.h
+++ b/net/proxy/proxy_service.h
@@ -13,6 +13,7 @@
#include "base/string_util.h"
#include "base/thread.h"
#include "base/time.h"
+#include "base/waitable_event.h"
#include "googleurl/src/gurl.h"
#include "net/base/completion_callback.h"
@@ -312,6 +313,31 @@ class ProxyResolver {
ProxyInfo* results) = 0;
};
+// Wrapper for invoking methods on a ProxyService synchronously.
+class SyncProxyServiceHelper
+ : public base::RefCountedThreadSafe<SyncProxyServiceHelper> {
+ public:
+ SyncProxyServiceHelper(MessageLoop* io_message_loop,
+ ProxyService* proxy_service);
+
+ int ResolveProxy(const GURL& url, ProxyInfo* proxy_info);
+ int ReconsiderProxyAfterError(const GURL& url, ProxyInfo* proxy_info);
+
+ private:
+ void StartAsyncResolve(const GURL& url);
+ void StartAsyncReconsider(const GURL& url);
+
+ void OnCompletion(int result);
+
+ MessageLoop* io_message_loop_;
+ ProxyService* proxy_service_;
+
+ base::WaitableEvent event_;
+ CompletionCallbackImpl<SyncProxyServiceHelper> callback_;
+ ProxyInfo proxy_info_;
+ int result_;
+};
+
} // namespace net
#endif // NET_PROXY_PROXY_SERVICE_H_