summaryrefslogtreecommitdiffstats
path: root/chrome/browser/net
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-26 21:12:20 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-26 21:12:20 +0000
commit775fd9e3215360868781cb7bc615b0b4d782f0a9 (patch)
tree1436421924de756654737312b2dad652315981d1 /chrome/browser/net
parent44d178bbf8cf937dc1180da5ccfd27ce9abe3f51 (diff)
downloadchromium_src-775fd9e3215360868781cb7bc615b0b4d782f0a9.zip
chromium_src-775fd9e3215360868781cb7bc615b0b4d782f0a9.tar.gz
chromium_src-775fd9e3215360868781cb7bc615b0b4d782f0a9.tar.bz2
Remove the concept of threading from ProxyService, and move it into the ProxyResolver dependency.
ProxyResolver may now complete requests asynchronously, and is defined to handle multiple requests. The code from ProxyService that queued requests onto the single PAC thread has moved into SingleThreadedProxyResolver. This refactor lays the groundwork for: (1) http://crbug.com/11746 -- Run PAC proxy resolving out of process. (Can inject an IPC bridge implementation of ProxyResolver) (2) http://crbug.com/11079 -- Run PAC proxy resolving on multiple threads. (Can implement a MultithreadedProxyResolver type class; still complications around v8 threadsafety though). BUG=http://crbug.com/11746, http://crbug.com/11079 TEST=existing unit-tests. Review URL: http://codereview.chromium.org/149525 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21631 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/net')
-rw-r--r--chrome/browser/net/resolve_proxy_msg_helper_unittest.cc38
1 files changed, 29 insertions, 9 deletions
diff --git a/chrome/browser/net/resolve_proxy_msg_helper_unittest.cc b/chrome/browser/net/resolve_proxy_msg_helper_unittest.cc
index d33a03b..84bb1d5 100644
--- a/chrome/browser/net/resolve_proxy_msg_helper_unittest.cc
+++ b/chrome/browser/net/resolve_proxy_msg_helper_unittest.cc
@@ -8,6 +8,7 @@
#include "net/base/net_errors.h"
#include "net/proxy/proxy_config_service.h"
#include "net/proxy/proxy_resolver.h"
+#include "net/proxy/single_threaded_proxy_resolver.h"
#include "testing/gtest/include/gtest/gtest.h"
// This ProxyConfigService always returns "http://pac" as the PAC url to use.
@@ -22,21 +23,29 @@ class MockProxyConfigService: public net::ProxyConfigService {
// This PAC resolver always returns the hostname of the query URL as the
// proxy to use. The Block() method will make GetProxyForURL() hang until
// Unblock() is called.
-class MockProxyResolver : public net::ProxyResolver {
+class SyncMockProxyResolver : public net::ProxyResolver {
public:
- MockProxyResolver() : ProxyResolver(true), event_(false, false),
- is_blocked_(false) {
+ SyncMockProxyResolver() : ProxyResolver(false /*expects_pac_bytes*/),
+ event_(false, false),
+ is_blocked_(false) {
}
virtual int GetProxyForURL(const GURL& query_url,
- const GURL& /*pac_url*/,
- net::ProxyInfo* results) {
+ net::ProxyInfo* results,
+ net::CompletionCallback* callback,
+ RequestHandle* request) {
if (is_blocked_)
event_.Wait();
results->UseNamedProxy(query_url.host());
return net::OK;
}
+ virtual void CancelRequest(RequestHandle request) {
+ NOTREACHED();
+ }
+
+ virtual void SetPacScriptByUrlInternal(const GURL& pac_url) {}
+
void Block() {
is_blocked_ = true;
event_.Reset();
@@ -52,6 +61,17 @@ class MockProxyResolver : public net::ProxyResolver {
bool is_blocked_;
};
+class MockProxyResolver : public net::SingleThreadedProxyResolver {
+ public:
+ MockProxyResolver()
+ : net::SingleThreadedProxyResolver(new SyncMockProxyResolver) {
+ x = reinterpret_cast<SyncMockProxyResolver*>(resolver());
+ }
+
+ // TODO(eroman): cleanup.
+ SyncMockProxyResolver* x;
+};
+
// This struct holds the values that were passed to
// Delegate::OnResolveProxyCompleted(). The caller should use WaitUntilDone()
// to block until the result has been populated.
@@ -271,7 +291,7 @@ TEST(ResolveProxyMsgHelperTest, QueueRequests) {
scoped_ptr<IPC::Message> msg3(new IPC::Message());
// Make the proxy resolver hang on the next request.
- runner.proxy_resolver()->Block();
+ runner.proxy_resolver()->x->Block();
// Start three requests. Since the proxy resolver is hung, the second two
// will be pending.
@@ -285,7 +305,7 @@ TEST(ResolveProxyMsgHelperTest, QueueRequests) {
result3->WaitUntilStarted();
// Unblock the proxy service so requests 1-3 can complete.
- runner.proxy_resolver()->Unblock();
+ runner.proxy_resolver()->x->Unblock();
// Wait for all the requests to finish (they run in FIFO order).
result3->WaitUntilDone();
@@ -320,7 +340,7 @@ TEST(ResolveProxyMsgHelperTest, CancelPendingRequests) {
IPC::Message* msg3 = new IPC::Message();
// Make the next request block.
- runner.proxy_resolver()->Block();
+ runner.proxy_resolver()->x->Block();
// Start three requests; since the first one blocked, the other two should
// be pending.
@@ -338,7 +358,7 @@ TEST(ResolveProxyMsgHelperTest, CancelPendingRequests) {
// Unblocking the proxy resolver means the three requests can complete --
// however they should not try to notify the delegate since we have already
// deleted the helper.
- runner.proxy_resolver()->Unblock();
+ runner.proxy_resolver()->x->Unblock();
// Check that none of the requests were sent to the delegate.
EXPECT_FALSE(