| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #ifndef NET_PROXY_PROXY_RESOLVER_V8_TRACING_H_ | 5 #ifndef NET_PROXY_PROXY_RESOLVER_V8_TRACING_H_ |
| 6 #define NET_PROXY_PROXY_RESOLVER_V8_TRACING_H_ | 6 #define NET_PROXY_PROXY_RESOLVER_V8_TRACING_H_ |
| 7 | 7 |
| 8 #include <set> |
| 9 |
| 8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 9 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/threading/non_thread_safe.h" | |
| 12 #include "net/base/net_export.h" | 13 #include "net/base/net_export.h" |
| 13 #include "net/proxy/proxy_resolver.h" | 14 #include "net/proxy/proxy_resolver.h" |
| 14 | 15 #include "net/proxy/proxy_resolver_factory.h" |
| 15 namespace base { | |
| 16 class Thread; | |
| 17 class MessageLoopProxy; | |
| 18 } // namespace base | |
| 19 | 16 |
| 20 namespace net { | 17 namespace net { |
| 21 | 18 |
| 22 class HostResolver; | 19 class HostResolver; |
| 23 class NetLog; | 20 class NetLog; |
| 24 class ProxyResolverErrorObserver; | 21 class ProxyResolverErrorObserver; |
| 25 class ProxyResolverV8; | |
| 26 | 22 |
| 27 // ProxyResolverV8Tracing is a non-blocking ProxyResolver. It executes | 23 // ProxyResolverFactoryV8Tracing is a ProxyResolverFactory that returns |
| 24 // non-blocking ProxyResolver instances. Each ProxyResolver instance executes |
| 28 // ProxyResolverV8 on a single helper thread, and does some magic to avoid | 25 // ProxyResolverV8 on a single helper thread, and does some magic to avoid |
| 29 // blocking in DNS. For more details see the design document: | 26 // blocking in DNS. For more details see the design document: |
| 30 // https://docs.google.com/a/google.com/document/d/16Ij5OcVnR3s0MH4Z5XkhI9VTPoMJ
daBn9rKreAmGOdE/edit?pli=1 | 27 // https://docs.google.com/a/google.com/document/d/16Ij5OcVnR3s0MH4Z5XkhI9VTPoMJ
daBn9rKreAmGOdE/edit?pli=1 |
| 31 class NET_EXPORT_PRIVATE ProxyResolverV8Tracing | 28 class NET_EXPORT ProxyResolverFactoryV8Tracing : public ProxyResolverFactory { |
| 32 : public ProxyResolver, | |
| 33 NON_EXPORTED_BASE(public base::NonThreadSafe) { | |
| 34 public: | 29 public: |
| 35 // Constructs a ProxyResolver that will issue DNS requests through | 30 // Note that |host_resolver| and |net_log| are expected to outlive |this| and |
| 36 // |host_resolver|, forward Javascript errors through |error_observer|, and | 31 // any ProxyResolver instances created using |this|. |error_observer_factory| |
| 37 // log Javascript errors and alerts to |net_log|. | 32 // will be invoked once per CreateProxyResolver() call to create a |
| 38 // | 33 // ProxyResolverErrorObserver to be used by the ProxyResolver instance |
| 39 // Note that the constructor takes ownership of |error_observer|, whereas | 34 // returned by that call. |
| 40 // |host_resolver| and |net_log| are expected to outlive |this|. | 35 ProxyResolverFactoryV8Tracing( |
| 41 ProxyResolverV8Tracing(HostResolver* host_resolver, | 36 HostResolver* host_resolver, |
| 42 ProxyResolverErrorObserver* error_observer, | 37 NetLog* net_log, |
| 43 NetLog* net_log); | 38 const ProxyResolver::LoadStateChangedCallback& callback, |
| 39 const base::Callback<scoped_ptr<ProxyResolverErrorObserver>()>& |
| 40 error_observer_factory); |
| 41 ~ProxyResolverFactoryV8Tracing() override; |
| 44 | 42 |
| 45 // Constructs a ProxyResolver that will issue DNS requests through | 43 // ProxyResolverFactory override. |
| 46 // |host_resolver|, forward Javascript errors through |error_observer|, and | 44 int CreateProxyResolver( |
| 47 // log Javascript errors and alerts to |net_log|. When the LoadState for a | 45 const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 48 // request changes, |on_load_state_changed| will be invoked with the | 46 scoped_ptr<ProxyResolver>* resolver, |
| 49 // RequestHandle for that request with the new LoadState. | 47 const CompletionCallback& callback, |
| 50 // | 48 scoped_ptr<Request>* request) override; |
| 51 // Note that the constructor takes ownership of |error_observer|, whereas | |
| 52 // |host_resolver| and |net_log| are expected to outlive |this|. | |
| 53 ProxyResolverV8Tracing(HostResolver* host_resolver, | |
| 54 ProxyResolverErrorObserver* error_observer, | |
| 55 NetLog* net_log, | |
| 56 const LoadStateChangedCallback& on_load_state_changed); | |
| 57 | |
| 58 ~ProxyResolverV8Tracing() override; | |
| 59 | |
| 60 // ProxyResolver implementation: | |
| 61 int GetProxyForURL(const GURL& url, | |
| 62 ProxyInfo* results, | |
| 63 const CompletionCallback& callback, | |
| 64 RequestHandle* request, | |
| 65 const BoundNetLog& net_log) override; | |
| 66 void CancelRequest(RequestHandle request) override; | |
| 67 LoadState GetLoadState(RequestHandle request) const override; | |
| 68 void CancelSetPacScript() override; | |
| 69 int SetPacScript(const scoped_refptr<ProxyResolverScriptData>& script_data, | |
| 70 const CompletionCallback& callback) override; | |
| 71 | 49 |
| 72 private: | 50 private: |
| 73 class Job; | 51 class CreateJob; |
| 74 | 52 |
| 75 // The worker thread on which the ProxyResolverV8 will be run. | 53 void RemoveJob(CreateJob* job); |
| 76 scoped_ptr<base::Thread> thread_; | |
| 77 scoped_ptr<ProxyResolverV8> v8_resolver_; | |
| 78 | 54 |
| 79 // Non-owned host resolver, which is to be operated on the origin thread. | 55 HostResolver* const host_resolver_; |
| 80 HostResolver* host_resolver_; | 56 NetLog* const net_log_; |
| 57 const ProxyResolver::LoadStateChangedCallback load_state_changed_callback_; |
| 58 const base::Callback<scoped_ptr<ProxyResolverErrorObserver>()> |
| 59 error_observer_factory_; |
| 81 | 60 |
| 82 scoped_ptr<ProxyResolverErrorObserver> error_observer_; | 61 std::set<CreateJob*> jobs_; |
| 83 NetLog* net_log_; | |
| 84 | 62 |
| 85 // The outstanding SetPacScript operation, or NULL. | 63 DISALLOW_COPY_AND_ASSIGN(ProxyResolverFactoryV8Tracing); |
| 86 scoped_refptr<Job> set_pac_script_job_; | |
| 87 | |
| 88 // The number of outstanding (non-cancelled) jobs. | |
| 89 int num_outstanding_callbacks_; | |
| 90 | |
| 91 // Invoked when the load state for a request changes. | |
| 92 const LoadStateChangedCallback on_load_state_changed_; | |
| 93 | |
| 94 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8Tracing); | |
| 95 }; | 64 }; |
| 96 | 65 |
| 97 } // namespace net | 66 } // namespace net |
| 98 | 67 |
| 99 #endif // NET_PROXY_PROXY_RESOLVER_V8_TRACING_H_ | 68 #endif // NET_PROXY_PROXY_RESOLVER_V8_TRACING_H_ |
| OLD | NEW |