summaryrefslogtreecommitdiffstats
path: root/net/proxy/single_threaded_proxy_resolver.h
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-08 21:10:27 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-08 21:10:27 +0000
commit0007f1434eafa4e955ff916d50a7a39fd850d435 (patch)
tree278dca04911fbefee519ac7ab449d208f4938a3d /net/proxy/single_threaded_proxy_resolver.h
parent41c9921ad0ffa548263262477777e865cd85b144 (diff)
downloadchromium_src-0007f1434eafa4e955ff916d50a7a39fd850d435.zip
chromium_src-0007f1434eafa4e955ff916d50a7a39fd850d435.tar.gz
chromium_src-0007f1434eafa4e955ff916d50a7a39fd850d435.tar.bz2
Revert 51877, since SpdyNetworkTransactionTest.CorruptFrameSessionError started failing after this check-in (but only on vista modules builder).
BUG=48588 Original CL description: Add the capability to run multiple proxy PAC scripts in parallel. Refactors SingleThreadedProxyResolver into MultiThreadedProxyResolver. New threads are created lazily on demand, up to a fixed maximum. Note that this CL does NOT change the policy in Chrome -- it will continue to use a single thread for proxy resolving, but using the new code to do so. BUG=11079 Review URL: http://codereview.chromium.org/2822043 TBR=eroman@chromium.org Review URL: http://codereview.chromium.org/2945004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51893 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy/single_threaded_proxy_resolver.h')
-rw-r--r--net/proxy/single_threaded_proxy_resolver.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/net/proxy/single_threaded_proxy_resolver.h b/net/proxy/single_threaded_proxy_resolver.h
new file mode 100644
index 0000000..1c9582c
--- /dev/null
+++ b/net/proxy/single_threaded_proxy_resolver.h
@@ -0,0 +1,94 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_PROXY_SINGLE_THREADED_PROXY_RESOLVER_H_
+#define NET_PROXY_SINGLE_THREADED_PROXY_RESOLVER_H_
+
+#include <deque>
+#include <string>
+
+#include "base/ref_counted.h"
+#include "base/scoped_ptr.h"
+#include "net/proxy/proxy_resolver.h"
+
+namespace base {
+class Thread;
+} // namespace base
+
+namespace net {
+
+// ProxyResolver implementation that wraps a synchronous ProxyResolver, and
+// runs it on a single worker thread. If multiple requests accumulate, they
+// are serviced in FIFO order.
+class SingleThreadedProxyResolver : public ProxyResolver {
+ public:
+ // |resolver| is a synchronous ProxyResolver implementation. It doesn't
+ // have to be thread-safe, since it is run on exactly one thread. The
+ // constructor takes ownership of |resolver|.
+ explicit SingleThreadedProxyResolver(ProxyResolver* resolver);
+
+ virtual ~SingleThreadedProxyResolver();
+
+ // ProxyResolver implementation:
+ virtual int GetProxyForURL(const GURL& url,
+ ProxyInfo* results,
+ CompletionCallback* callback,
+ RequestHandle* request,
+ const BoundNetLog& net_log);
+ virtual void CancelRequest(RequestHandle request);
+ virtual void CancelSetPacScript();
+ virtual void PurgeMemory();
+
+ protected:
+ // The wrapped (synchronous) ProxyResolver.
+ ProxyResolver* resolver() { return resolver_.get(); }
+
+ private:
+ // Refcounted helper class that bridges between origin thread and worker
+ // thread.
+ class Job;
+ friend class Job;
+ class SetPacScriptTask;
+ friend class SetPacScriptTask;
+ // FIFO queue that contains the in-progress job, and any pending jobs.
+ typedef std::deque<scoped_refptr<Job> > PendingJobsQueue;
+
+ base::Thread* thread() { return thread_.get(); }
+
+ // ProxyResolver implementation:
+ virtual int SetPacScript(const GURL& pac_url,
+ const string16& pac_script,
+ CompletionCallback* callback);
+
+ // Starts the worker thread if it isn't already running.
+ void EnsureThreadStarted();
+
+ // Starts the next job from |pending_jobs_| if possible.
+ void ProcessPendingJobs();
+
+ // Removes the front entry of the jobs queue. |expected_job| is our
+ // expectation of what the front of the job queue is; it is only used by
+ // DCHECK for verification purposes.
+ void RemoveFrontOfJobsQueueAndStartNext(Job* expected_job);
+
+ // Clears |outstanding_set_pac_script_task_|.
+ // Called when |task| has just finished.
+ void RemoveOutstandingSetPacScriptTask(SetPacScriptTask* task);
+
+ // The synchronous resolver implementation.
+ scoped_ptr<ProxyResolver> resolver_;
+
+ // The thread where |resolver_| is run on.
+ // Note that declaration ordering is important here. |thread_| needs to be
+ // destroyed *before* |resolver_|, in case |resolver_| is currently
+ // executing on |thread_|.
+ scoped_ptr<base::Thread> thread_;
+
+ PendingJobsQueue pending_jobs_;
+ scoped_refptr<SetPacScriptTask> outstanding_set_pac_script_task_;
+};
+
+} // namespace net
+
+#endif // NET_PROXY_SINGLE_THREADED_PROXY_RESOLVER_H_