Chromium Code Reviews| 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 #include "net/proxy/proxy_resolver_v8_tracing.h" | 5 #include "net/proxy/proxy_resolver_v8_tracing.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/synchronization/cancellation_flag.h" | 14 #include "base/synchronization/cancellation_flag.h" |
| 15 #include "base/synchronization/waitable_event.h" | 15 #include "base/synchronization/waitable_event.h" |
| 16 #include "base/thread_task_runner_handle.h" | 16 #include "base/thread_task_runner_handle.h" |
| 17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 18 #include "base/threading/thread_restrictions.h" | 18 #include "base/threading/thread_restrictions.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
|
eroman
2015/06/26 15:37:25
Can this be deleted now?
Sam McNally
2015/06/29 01:33:51
Done.
| |
| 20 #include "net/base/address_list.h" | 20 #include "net/base/address_list.h" |
| 21 #include "net/base/net_errors.h" | 21 #include "net/base/net_errors.h" |
| 22 #include "net/dns/host_resolver.h" | 22 #include "net/dns/host_resolver.h" |
| 23 #include "net/log/net_log.h" | 23 #include "net/log/net_log.h" |
|
eroman
2015/06/26 15:37:25
can this be deleted?
Sam McNally
2015/06/29 01:33:51
Done.
| |
| 24 #include "net/proxy/proxy_info.h" | 24 #include "net/proxy/proxy_info.h" |
| 25 #include "net/proxy/proxy_resolver_error_observer.h" | 25 #include "net/proxy/proxy_resolver_error_observer.h" |
| 26 #include "net/proxy/proxy_resolver_v8.h" | 26 #include "net/proxy/proxy_resolver_v8.h" |
| 27 | 27 |
| 28 // The intent of this class is explained in the design document: | 28 // The intent of this class is explained in the design document: |
| 29 // https://docs.google.com/a/chromium.org/document/d/16Ij5OcVnR3s0MH4Z5XkhI9VTPo MJdaBn9rKreAmGOdE/edit | 29 // https://docs.google.com/a/chromium.org/document/d/16Ij5OcVnR3s0MH4Z5XkhI9VTPo MJdaBn9rKreAmGOdE/edit |
| 30 // | 30 // |
| 31 // In a nutshell, PAC scripts are Javascript programs and may depend on | 31 // In a nutshell, PAC scripts are Javascript programs and may depend on |
| 32 // network I/O, by calling functions like dnsResolve(). | 32 // network I/O, by calling functions like dnsResolve(). |
| 33 // | 33 // |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 51 // number of DNS resolves, as well as scripts which are misbehaving | 51 // number of DNS resolves, as well as scripts which are misbehaving |
| 52 // under the tracing optimization. It is not expected to hit this normally. | 52 // under the tracing optimization. It is not expected to hit this normally. |
| 53 const size_t kMaxUniqueResolveDnsPerExec = 20; | 53 const size_t kMaxUniqueResolveDnsPerExec = 20; |
| 54 | 54 |
| 55 // Approximate number of bytes to use for buffering alerts() and errors. | 55 // Approximate number of bytes to use for buffering alerts() and errors. |
| 56 // This is a failsafe in case repeated executions of the script causes | 56 // This is a failsafe in case repeated executions of the script causes |
| 57 // too much memory bloat. It is not expected for well behaved scripts to | 57 // too much memory bloat. It is not expected for well behaved scripts to |
| 58 // hit this. (In fact normal scripts should not even have alerts() or errors). | 58 // hit this. (In fact normal scripts should not even have alerts() or errors). |
| 59 const size_t kMaxAlertsAndErrorsBytes = 2048; | 59 const size_t kMaxAlertsAndErrorsBytes = 2048; |
| 60 | 60 |
| 61 // Returns event parameters for a PAC error message (line number + message). | |
| 62 scoped_ptr<base::Value> NetLogErrorCallback( | |
| 63 int line_number, | |
| 64 const base::string16* message, | |
| 65 NetLogCaptureMode /* capture_mode */) { | |
| 66 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | |
| 67 dict->SetInteger("line_number", line_number); | |
| 68 dict->SetString("message", *message); | |
| 69 return dict.Pass(); | |
| 70 } | |
| 71 | |
| 72 // The Job class is responsible for executing GetProxyForURL() and | 61 // The Job class is responsible for executing GetProxyForURL() and |
| 73 // creating ProxyResolverV8 instances, since both of these operations share | 62 // creating ProxyResolverV8 instances, since both of these operations share |
| 74 // similar code. | 63 // similar code. |
| 75 // | 64 // |
| 76 // The DNS for these operations can operate in either blocking or | 65 // The DNS for these operations can operate in either blocking or |
| 77 // non-blocking mode. Blocking mode is used as a fallback when the PAC script | 66 // non-blocking mode. Blocking mode is used as a fallback when the PAC script |
| 78 // seems to be misbehaving under the tracing optimization. | 67 // seems to be misbehaving under the tracing optimization. |
| 79 // | 68 // |
| 80 // Note that this class runs on both the origin thread and a worker | 69 // Note that this class runs on both the origin thread and a worker |
| 81 // thread. Most methods are expected to be used exclusively on one thread | 70 // thread. Most methods are expected to be used exclusively on one thread |
| 82 // or the other. | 71 // or the other. |
| 83 // | 72 // |
| 84 // The lifetime of Jobs does not exceed that of the ProxyResolverV8Tracing that | 73 // The lifetime of Jobs does not exceed that of the ProxyResolverV8TracingImpl |
| 85 // spawned it. Destruction might happen on either the origin thread or the | 74 // that spawned it. Destruction might happen on either the origin thread or the |
| 86 // worker thread. | 75 // worker thread. |
| 87 class Job : public base::RefCountedThreadSafe<Job>, | 76 class Job : public base::RefCountedThreadSafe<Job>, |
| 88 public ProxyResolverV8::JSBindings { | 77 public ProxyResolverV8::JSBindings { |
| 89 public: | 78 public: |
| 90 struct Params { | 79 struct Params { |
| 91 Params( | 80 Params( |
| 92 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner, | 81 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner, |
| 93 HostResolver* host_resolver, | |
| 94 ProxyResolverErrorObserver* error_observer, | |
| 95 NetLog* net_log, | |
| 96 ProxyResolver::LoadStateChangedCallback on_load_state_changed, | |
| 97 int* num_outstanding_callbacks) | 82 int* num_outstanding_callbacks) |
| 98 : v8_resolver(nullptr), | 83 : v8_resolver(nullptr), |
| 99 worker_task_runner(worker_task_runner), | 84 worker_task_runner(worker_task_runner), |
| 100 host_resolver(host_resolver), | |
| 101 error_observer(error_observer), | |
| 102 net_log(net_log), | |
| 103 on_load_state_changed(on_load_state_changed), | |
| 104 num_outstanding_callbacks(num_outstanding_callbacks) {} | 85 num_outstanding_callbacks(num_outstanding_callbacks) {} |
| 105 | 86 |
| 106 ProxyResolverV8* v8_resolver; | 87 ProxyResolverV8* v8_resolver; |
| 107 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner; | 88 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner; |
| 108 HostResolver* host_resolver; | |
| 109 ProxyResolverErrorObserver* error_observer; | |
| 110 NetLog* net_log; | |
| 111 ProxyResolver::LoadStateChangedCallback on_load_state_changed; | |
| 112 int* num_outstanding_callbacks; | 89 int* num_outstanding_callbacks; |
| 113 }; | 90 }; |
| 114 // |params| is non-owned. It contains the parameters for this Job, and must | 91 // |params| is non-owned. It contains the parameters for this Job, and must |
| 115 // outlive it. | 92 // outlive it. |
| 116 explicit Job(const Params* params); | 93 Job(const Params* params, |
| 94 scoped_ptr<ProxyResolverV8Tracing::Bindings> bindings); | |
| 117 | 95 |
| 118 // Called from origin thread. | 96 // Called from origin thread. |
| 119 void StartCreateV8Resolver( | 97 void StartCreateV8Resolver( |
| 120 const scoped_refptr<ProxyResolverScriptData>& script_data, | 98 const scoped_refptr<ProxyResolverScriptData>& script_data, |
| 121 scoped_ptr<ProxyResolverV8>* resolver, | 99 scoped_ptr<ProxyResolverV8>* resolver, |
| 122 const CompletionCallback& callback); | 100 const CompletionCallback& callback); |
| 123 | 101 |
| 124 // Called from origin thread. | 102 // Called from origin thread. |
| 125 void StartGetProxyForURL(const GURL& url, | 103 void StartGetProxyForURL(const GURL& url, |
| 126 ProxyInfo* results, | 104 ProxyInfo* results, |
| 127 const BoundNetLog& net_log, | |
| 128 const CompletionCallback& callback); | 105 const CompletionCallback& callback); |
| 129 | 106 |
| 130 // Called from origin thread. | 107 // Called from origin thread. |
| 131 void Cancel(); | 108 void Cancel(); |
| 132 | 109 |
| 133 // Called from origin thread. | 110 // Called from origin thread. |
| 134 LoadState GetLoadState() const; | 111 LoadState GetLoadState() const; |
| 135 | 112 |
| 136 private: | 113 private: |
| 137 typedef std::map<std::string, std::string> DnsCache; | 114 typedef std::map<std::string, std::string> DnsCache; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 152 | 129 |
| 153 void CheckIsOnWorkerThread() const; | 130 void CheckIsOnWorkerThread() const; |
| 154 void CheckIsOnOriginThread() const; | 131 void CheckIsOnOriginThread() const; |
| 155 | 132 |
| 156 void SetCallback(const CompletionCallback& callback); | 133 void SetCallback(const CompletionCallback& callback); |
| 157 void ReleaseCallback(); | 134 void ReleaseCallback(); |
| 158 | 135 |
| 159 ProxyResolverV8* v8_resolver(); | 136 ProxyResolverV8* v8_resolver(); |
| 160 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner(); | 137 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner(); |
| 161 HostResolver* host_resolver(); | 138 HostResolver* host_resolver(); |
| 162 ProxyResolverErrorObserver* error_observer(); | |
| 163 NetLog* net_log(); | |
| 164 | 139 |
| 165 // Invokes the user's callback. | 140 // Invokes the user's callback. |
| 166 void NotifyCaller(int result); | 141 void NotifyCaller(int result); |
| 167 void NotifyCallerOnOriginLoop(int result); | 142 void NotifyCallerOnOriginLoop(int result); |
| 168 | 143 |
| 169 void Start(Operation op, bool blocking_dns, | 144 void Start(Operation op, bool blocking_dns, |
| 170 const CompletionCallback& callback); | 145 const CompletionCallback& callback); |
| 171 | 146 |
| 172 void ExecuteBlocking(); | 147 void ExecuteBlocking(); |
| 173 void ExecuteNonBlocking(); | 148 void ExecuteNonBlocking(); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 216 // convenience, to avoid defining custom comparators. | 191 // convenience, to avoid defining custom comparators. |
| 217 static std::string MakeDnsCacheKey(const std::string& host, | 192 static std::string MakeDnsCacheKey(const std::string& host, |
| 218 ResolveDnsOperation op); | 193 ResolveDnsOperation op); |
| 219 | 194 |
| 220 void HandleAlertOrError(bool is_alert, int line_number, | 195 void HandleAlertOrError(bool is_alert, int line_number, |
| 221 const base::string16& message); | 196 const base::string16& message); |
| 222 void DispatchBufferedAlertsAndErrors(); | 197 void DispatchBufferedAlertsAndErrors(); |
| 223 void DispatchAlertOrError(bool is_alert, int line_number, | 198 void DispatchAlertOrError(bool is_alert, int line_number, |
| 224 const base::string16& message); | 199 const base::string16& message); |
| 225 | 200 |
| 226 void LogEventToCurrentRequestAndGlobally( | 201 // The thread which called into ProxyResolverV8TracingImpl, and on which the |
| 227 NetLog::EventType type, | |
| 228 const NetLog::ParametersCallback& parameters_callback); | |
| 229 | |
| 230 // The thread which called into ProxyResolverV8Tracing, and on which the | |
| 231 // completion callback is expected to run. | 202 // completion callback is expected to run. |
| 232 scoped_refptr<base::SingleThreadTaskRunner> origin_runner_; | 203 scoped_refptr<base::SingleThreadTaskRunner> origin_runner_; |
| 233 | 204 |
| 234 // The Parameters for this Job. | 205 // The Parameters for this Job. |
| 235 // Initialized on origin thread and then accessed from both threads. | 206 // Initialized on origin thread and then accessed from both threads. |
| 236 const Params* const params_; | 207 const Params* const params_; |
| 237 | 208 |
| 209 scoped_ptr<ProxyResolverV8Tracing::Bindings> bindings_; | |
| 210 | |
| 238 // The callback to run (on the origin thread) when the Job finishes. | 211 // The callback to run (on the origin thread) when the Job finishes. |
| 239 // Should only be accessed from origin thread. | 212 // Should only be accessed from origin thread. |
| 240 CompletionCallback callback_; | 213 CompletionCallback callback_; |
| 241 | 214 |
| 242 // Flag to indicate whether the request has been cancelled. | 215 // Flag to indicate whether the request has been cancelled. |
| 243 base::CancellationFlag cancelled_; | 216 base::CancellationFlag cancelled_; |
| 244 | 217 |
| 245 // The operation that this Job is running. | 218 // The operation that this Job is running. |
| 246 // Initialized on origin thread and then accessed from both threads. | 219 // Initialized on origin thread and then accessed from both threads. |
| 247 Operation operation_; | 220 Operation operation_; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 270 scoped_refptr<ProxyResolverScriptData> script_data_; | 243 scoped_refptr<ProxyResolverScriptData> script_data_; |
| 271 scoped_ptr<ProxyResolverV8>* resolver_out_; | 244 scoped_ptr<ProxyResolverV8>* resolver_out_; |
| 272 | 245 |
| 273 // ------------------------------------------------------- | 246 // ------------------------------------------------------- |
| 274 // State specific to GET_PROXY_FOR_URL. | 247 // State specific to GET_PROXY_FOR_URL. |
| 275 // ------------------------------------------------------- | 248 // ------------------------------------------------------- |
| 276 | 249 |
| 277 ProxyInfo* user_results_; // Owned by caller, lives on origin thread. | 250 ProxyInfo* user_results_; // Owned by caller, lives on origin thread. |
| 278 GURL url_; | 251 GURL url_; |
| 279 ProxyInfo results_; | 252 ProxyInfo results_; |
| 280 BoundNetLog bound_net_log_; | |
| 281 | 253 |
| 282 // --------------------------------------------------------------------------- | 254 // --------------------------------------------------------------------------- |
| 283 // State for ExecuteNonBlocking() | 255 // State for ExecuteNonBlocking() |
| 284 // --------------------------------------------------------------------------- | 256 // --------------------------------------------------------------------------- |
| 285 // These variables are used exclusively on the worker thread and are only | 257 // These variables are used exclusively on the worker thread and are only |
| 286 // meaningful when executing inside of ExecuteNonBlocking(). | 258 // meaningful when executing inside of ExecuteNonBlocking(). |
| 287 | 259 |
| 288 // Whether this execution was abandoned due to a missing DNS dependency. | 260 // Whether this execution was abandoned due to a missing DNS dependency. |
| 289 bool abandoned_; | 261 bool abandoned_; |
| 290 | 262 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 317 // These are the inputs to DoDnsOperation(). Written on the worker thread, | 289 // These are the inputs to DoDnsOperation(). Written on the worker thread, |
| 318 // read by the origin thread. | 290 // read by the origin thread. |
| 319 std::string pending_dns_host_; | 291 std::string pending_dns_host_; |
| 320 ResolveDnsOperation pending_dns_op_; | 292 ResolveDnsOperation pending_dns_op_; |
| 321 | 293 |
| 322 // This contains the resolved address list that DoDnsOperation() fills in. | 294 // This contains the resolved address list that DoDnsOperation() fills in. |
| 323 // Used exclusively on the origin thread. | 295 // Used exclusively on the origin thread. |
| 324 AddressList pending_dns_addresses_; | 296 AddressList pending_dns_addresses_; |
| 325 }; | 297 }; |
| 326 | 298 |
| 327 class ProxyResolverV8Tracing : public ProxyResolver, | 299 class ProxyResolverV8TracingImpl : public ProxyResolverV8Tracing, |
| 328 public base::NonThreadSafe { | 300 public base::NonThreadSafe { |
| 329 public: | 301 public: |
| 330 // Constructs a ProxyResolver that will issue DNS requests through | 302 ProxyResolverV8TracingImpl(scoped_ptr<base::Thread> thread, |
| 331 // |job_params->host_resolver|, forward Javascript errors through | 303 scoped_ptr<ProxyResolverV8> resolver, |
| 332 // |error_observer|, and log Javascript errors and alerts to | 304 scoped_ptr<Job::Params> job_params); |
| 333 // |job_params->net_log|. When the LoadState for a request changes, | |
| 334 // |job_params->on_load_state_changed| will be invoked with the RequestHandle | |
| 335 // for that request with the new LoadState. | |
| 336 // | |
| 337 // Note that the constructor takes ownership of |error_observer|, whereas | |
| 338 // |job_params->host_resolver| and |job_params->net_log| are expected to | |
| 339 // outlive |this|. | |
| 340 ProxyResolverV8Tracing(scoped_ptr<ProxyResolverErrorObserver> error_observer, | |
| 341 scoped_ptr<base::Thread> thread, | |
| 342 scoped_ptr<ProxyResolverV8> resolver, | |
| 343 scoped_ptr<Job::Params> job_params); | |
| 344 | 305 |
| 345 ~ProxyResolverV8Tracing() override; | 306 ~ProxyResolverV8TracingImpl() override; |
| 346 | 307 |
| 347 // ProxyResolver implementation: | 308 // ProxyResolverV8Tracing overrides. |
| 348 int GetProxyForURL(const GURL& url, | 309 void GetProxyForURL(const GURL& url, |
| 349 ProxyInfo* results, | 310 ProxyInfo* results, |
| 350 const CompletionCallback& callback, | 311 const CompletionCallback& callback, |
| 351 RequestHandle* request, | 312 ProxyResolver::RequestHandle* request, |
| 352 const BoundNetLog& net_log) override; | 313 scoped_ptr<Bindings> bindings) override; |
| 353 void CancelRequest(RequestHandle request) override; | 314 void CancelRequest(ProxyResolver::RequestHandle request) override; |
| 354 LoadState GetLoadState(RequestHandle request) const override; | 315 LoadState GetLoadState(ProxyResolver::RequestHandle request) const override; |
| 355 | 316 |
| 356 private: | 317 private: |
| 357 // The worker thread on which the ProxyResolverV8 will be run. | 318 // The worker thread on which the ProxyResolverV8 will be run. |
| 358 scoped_ptr<base::Thread> thread_; | 319 scoped_ptr<base::Thread> thread_; |
| 359 scoped_ptr<ProxyResolverV8> v8_resolver_; | 320 scoped_ptr<ProxyResolverV8> v8_resolver_; |
| 360 | 321 |
| 361 scoped_ptr<ProxyResolverErrorObserver> error_observer_; | |
| 362 | |
| 363 scoped_ptr<Job::Params> job_params_; | 322 scoped_ptr<Job::Params> job_params_; |
| 364 | 323 |
| 365 // The number of outstanding (non-cancelled) jobs. | 324 // The number of outstanding (non-cancelled) jobs. |
| 366 int num_outstanding_callbacks_; | 325 int num_outstanding_callbacks_; |
| 367 | 326 |
| 368 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8Tracing); | 327 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8TracingImpl); |
| 369 }; | 328 }; |
| 370 | 329 |
| 371 Job::Job(const Job::Params* params) | 330 Job::Job(const Job::Params* params, |
| 331 scoped_ptr<ProxyResolverV8Tracing::Bindings> bindings) | |
| 372 : origin_runner_(base::ThreadTaskRunnerHandle::Get()), | 332 : origin_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 373 params_(params), | 333 params_(params), |
| 334 bindings_(bindings.Pass()), | |
| 374 event_(true, false), | 335 event_(true, false), |
| 375 last_num_dns_(0), | 336 last_num_dns_(0), |
| 376 pending_dns_(NULL) { | 337 pending_dns_(NULL) { |
| 377 CheckIsOnOriginThread(); | 338 CheckIsOnOriginThread(); |
| 378 } | 339 } |
| 379 | 340 |
| 380 void Job::StartCreateV8Resolver( | 341 void Job::StartCreateV8Resolver( |
| 381 const scoped_refptr<ProxyResolverScriptData>& script_data, | 342 const scoped_refptr<ProxyResolverScriptData>& script_data, |
| 382 scoped_ptr<ProxyResolverV8>* resolver, | 343 scoped_ptr<ProxyResolverV8>* resolver, |
| 383 const CompletionCallback& callback) { | 344 const CompletionCallback& callback) { |
| 384 CheckIsOnOriginThread(); | 345 CheckIsOnOriginThread(); |
| 385 | 346 |
| 386 resolver_out_ = resolver; | 347 resolver_out_ = resolver; |
| 387 script_data_ = script_data; | 348 script_data_ = script_data; |
| 388 | 349 |
| 389 // Script initialization uses blocking DNS since there isn't any | 350 // Script initialization uses blocking DNS since there isn't any |
| 390 // advantage to using non-blocking mode here. That is because the | 351 // advantage to using non-blocking mode here. That is because the |
| 391 // parent ProxyService can't submit any ProxyResolve requests until | 352 // parent ProxyService can't submit any ProxyResolve requests until |
| 392 // initialization has completed successfully! | 353 // initialization has completed successfully! |
| 393 Start(CREATE_V8_RESOLVER, true /*blocking*/, callback); | 354 Start(CREATE_V8_RESOLVER, true /*blocking*/, callback); |
| 394 } | 355 } |
| 395 | 356 |
| 396 void Job::StartGetProxyForURL(const GURL& url, | 357 void Job::StartGetProxyForURL(const GURL& url, |
| 397 ProxyInfo* results, | 358 ProxyInfo* results, |
| 398 const BoundNetLog& net_log, | |
| 399 const CompletionCallback& callback) { | 359 const CompletionCallback& callback) { |
| 400 CheckIsOnOriginThread(); | 360 CheckIsOnOriginThread(); |
| 401 | 361 |
| 402 url_ = url; | 362 url_ = url; |
| 403 user_results_ = results; | 363 user_results_ = results; |
| 404 bound_net_log_ = net_log; | |
| 405 | 364 |
| 406 Start(GET_PROXY_FOR_URL, false /*non-blocking*/, callback); | 365 Start(GET_PROXY_FOR_URL, false /*non-blocking*/, callback); |
| 407 } | 366 } |
| 408 | 367 |
| 409 void Job::Cancel() { | 368 void Job::Cancel() { |
| 410 CheckIsOnOriginThread(); | 369 CheckIsOnOriginThread(); |
| 411 | 370 |
| 412 // There are several possibilities to consider for cancellation: | 371 // There are several possibilities to consider for cancellation: |
| 413 // (a) The job has been posted to the worker thread, however script execution | 372 // (a) The job has been posted to the worker thread, however script execution |
| 414 // has not yet started. | 373 // has not yet started. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 | 442 |
| 484 ProxyResolverV8* Job::v8_resolver() { | 443 ProxyResolverV8* Job::v8_resolver() { |
| 485 return params_->v8_resolver; | 444 return params_->v8_resolver; |
| 486 } | 445 } |
| 487 | 446 |
| 488 const scoped_refptr<base::SingleThreadTaskRunner>& Job::worker_task_runner() { | 447 const scoped_refptr<base::SingleThreadTaskRunner>& Job::worker_task_runner() { |
| 489 return params_->worker_task_runner; | 448 return params_->worker_task_runner; |
| 490 } | 449 } |
| 491 | 450 |
| 492 HostResolver* Job::host_resolver() { | 451 HostResolver* Job::host_resolver() { |
| 493 return params_->host_resolver; | 452 return bindings_->GetHostResolver(); |
| 494 } | |
| 495 | |
| 496 ProxyResolverErrorObserver* Job::error_observer() { | |
| 497 return params_->error_observer; | |
| 498 } | |
| 499 | |
| 500 NetLog* Job::net_log() { | |
| 501 return params_->net_log; | |
| 502 } | 453 } |
| 503 | 454 |
| 504 void Job::NotifyCaller(int result) { | 455 void Job::NotifyCaller(int result) { |
| 505 CheckIsOnWorkerThread(); | 456 CheckIsOnWorkerThread(); |
| 506 | 457 |
| 507 origin_runner_->PostTask( | 458 origin_runner_->PostTask( |
| 508 FROM_HERE, base::Bind(&Job::NotifyCallerOnOriginLoop, this, result)); | 459 FROM_HERE, base::Bind(&Job::NotifyCallerOnOriginLoop, this, result)); |
| 509 } | 460 } |
| 510 | 461 |
| 511 void Job::NotifyCallerOnOriginLoop(int result) { | 462 void Job::NotifyCallerOnOriginLoop(int result) { |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 739 | 690 |
| 740 void Job::DoDnsOperation() { | 691 void Job::DoDnsOperation() { |
| 741 CheckIsOnOriginThread(); | 692 CheckIsOnOriginThread(); |
| 742 DCHECK(!pending_dns_); | 693 DCHECK(!pending_dns_); |
| 743 | 694 |
| 744 if (cancelled_.IsSet()) | 695 if (cancelled_.IsSet()) |
| 745 return; | 696 return; |
| 746 | 697 |
| 747 HostResolver::RequestHandle dns_request = NULL; | 698 HostResolver::RequestHandle dns_request = NULL; |
| 748 int result = host_resolver()->Resolve( | 699 int result = host_resolver()->Resolve( |
| 749 MakeDnsRequestInfo(pending_dns_host_, pending_dns_op_), | 700 MakeDnsRequestInfo(pending_dns_host_, pending_dns_op_), DEFAULT_PRIORITY, |
| 750 DEFAULT_PRIORITY, | 701 &pending_dns_addresses_, base::Bind(&Job::OnDnsOperationComplete, this), |
| 751 &pending_dns_addresses_, | 702 &dns_request, bindings_->GetBoundNetLog()); |
| 752 base::Bind(&Job::OnDnsOperationComplete, this), | |
| 753 &dns_request, | |
| 754 bound_net_log_); | |
| 755 | 703 |
| 756 pending_dns_completed_synchronously_ = result != ERR_IO_PENDING; | 704 pending_dns_completed_synchronously_ = result != ERR_IO_PENDING; |
| 757 | 705 |
| 758 // Check if the request was cancelled as a side-effect of calling into the | 706 // Check if the request was cancelled as a side-effect of calling into the |
| 759 // HostResolver. This isn't the ordinary execution flow, however it is | 707 // HostResolver. This isn't the ordinary execution flow, however it is |
| 760 // exercised by unit-tests. | 708 // exercised by unit-tests. |
| 761 if (cancelled_.IsSet()) { | 709 if (cancelled_.IsSet()) { |
| 762 if (!pending_dns_completed_synchronously_) | 710 if (!pending_dns_completed_synchronously_) |
| 763 host_resolver()->CancelRequest(dns_request); | 711 host_resolver()->CancelRequest(dns_request); |
| 764 return; | 712 return; |
| 765 } | 713 } |
| 766 | 714 |
| 767 if (pending_dns_completed_synchronously_) { | 715 if (pending_dns_completed_synchronously_) { |
| 768 OnDnsOperationComplete(result); | 716 OnDnsOperationComplete(result); |
| 769 } else { | 717 } else { |
| 770 DCHECK(dns_request); | 718 DCHECK(dns_request); |
| 771 pending_dns_ = dns_request; | 719 pending_dns_ = dns_request; |
| 772 if (!params_->on_load_state_changed.is_null()) { | |
| 773 params_->on_load_state_changed.Run( | |
| 774 this, LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT); | |
| 775 } | |
| 776 // OnDnsOperationComplete() will be called by host resolver on completion. | 720 // OnDnsOperationComplete() will be called by host resolver on completion. |
| 777 } | 721 } |
| 778 | 722 |
| 779 if (!blocking_dns_) { | 723 if (!blocking_dns_) { |
| 780 // The worker thread always blocks waiting to see if the result can be | 724 // The worker thread always blocks waiting to see if the result can be |
| 781 // serviced from cache before restarting. | 725 // serviced from cache before restarting. |
| 782 event_.Signal(); | 726 event_.Signal(); |
| 783 } | 727 } |
| 784 } | 728 } |
| 785 | 729 |
| 786 void Job::OnDnsOperationComplete(int result) { | 730 void Job::OnDnsOperationComplete(int result) { |
| 787 CheckIsOnOriginThread(); | 731 CheckIsOnOriginThread(); |
| 788 | 732 |
| 789 DCHECK(!cancelled_.IsSet()); | 733 DCHECK(!cancelled_.IsSet()); |
| 790 DCHECK(pending_dns_completed_synchronously_ == (pending_dns_ == NULL)); | 734 DCHECK(pending_dns_completed_synchronously_ == (pending_dns_ == NULL)); |
| 791 | 735 |
| 792 SaveDnsToLocalCache(pending_dns_host_, pending_dns_op_, result, | 736 SaveDnsToLocalCache(pending_dns_host_, pending_dns_op_, result, |
| 793 pending_dns_addresses_); | 737 pending_dns_addresses_); |
| 794 pending_dns_ = NULL; | 738 pending_dns_ = NULL; |
| 795 | 739 |
| 796 if (!params_->on_load_state_changed.is_null() && | |
| 797 !pending_dns_completed_synchronously_ && !cancelled_.IsSet()) { | |
| 798 params_->on_load_state_changed.Run(this, | |
| 799 LOAD_STATE_RESOLVING_PROXY_FOR_URL); | |
| 800 } | |
| 801 | |
| 802 if (blocking_dns_) { | 740 if (blocking_dns_) { |
| 803 event_.Signal(); | 741 event_.Signal(); |
| 804 return; | 742 return; |
| 805 } | 743 } |
| 806 | 744 |
| 807 if (!blocking_dns_ && !pending_dns_completed_synchronously_) { | 745 if (!blocking_dns_ && !pending_dns_completed_synchronously_) { |
| 808 // Restart. This time it should make more progress due to having | 746 // Restart. This time it should make more progress due to having |
| 809 // cached items. | 747 // cached items. |
| 810 worker_task_runner()->PostTask(FROM_HERE, | 748 worker_task_runner()->PostTask(FROM_HERE, |
| 811 base::Bind(&Job::ExecuteNonBlocking, this)); | 749 base::Bind(&Job::ExecuteNonBlocking, this)); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 942 | 880 |
| 943 void Job::DispatchAlertOrError(bool is_alert, | 881 void Job::DispatchAlertOrError(bool is_alert, |
| 944 int line_number, | 882 int line_number, |
| 945 const base::string16& message) { | 883 const base::string16& message) { |
| 946 CheckIsOnWorkerThread(); | 884 CheckIsOnWorkerThread(); |
| 947 | 885 |
| 948 // Note that the handling of cancellation is racy with regard to | 886 // Note that the handling of cancellation is racy with regard to |
| 949 // alerts/errors. The request might get cancelled shortly after this | 887 // alerts/errors. The request might get cancelled shortly after this |
| 950 // check! (There is no lock being held to guarantee otherwise). | 888 // check! (There is no lock being held to guarantee otherwise). |
| 951 // | 889 // |
| 952 // If this happens, then some information will get written to the NetLog | 890 // If this happens, then some information will be logged needlessly, however |
| 953 // needlessly, however the NetLog will still be alive so it shouldn't cause | 891 // the Bindings are responsible for handling this case so it shouldn't cause |
| 954 // problems. | 892 // problems. |
| 955 if (cancelled_.IsSet()) | 893 if (cancelled_.IsSet()) |
| 956 return; | 894 return; |
| 957 | 895 |
| 958 if (is_alert) { | 896 if (is_alert) { |
| 959 // ------------------- | 897 // ------------------- |
| 960 // alert | 898 // alert |
| 961 // ------------------- | 899 // ------------------- |
| 962 VLOG(1) << "PAC-alert: " << message; | 900 VLOG(1) << "PAC-alert: " << message; |
| 963 | 901 |
| 964 // Send to the NetLog. | 902 bindings_->Alert(message); |
| 965 LogEventToCurrentRequestAndGlobally( | |
| 966 NetLog::TYPE_PAC_JAVASCRIPT_ALERT, | |
| 967 NetLog::StringCallback("message", &message)); | |
| 968 } else { | 903 } else { |
| 969 // ------------------- | 904 // ------------------- |
| 970 // error | 905 // error |
| 971 // ------------------- | 906 // ------------------- |
| 972 if (line_number == -1) | 907 if (line_number == -1) |
| 973 VLOG(1) << "PAC-error: " << message; | 908 VLOG(1) << "PAC-error: " << message; |
| 974 else | 909 else |
| 975 VLOG(1) << "PAC-error: " << "line: " << line_number << ": " << message; | 910 VLOG(1) << "PAC-error: " << "line: " << line_number << ": " << message; |
| 976 | 911 |
| 977 // Send the error to the NetLog. | 912 bindings_->OnError(line_number, message); |
| 978 LogEventToCurrentRequestAndGlobally( | |
| 979 NetLog::TYPE_PAC_JAVASCRIPT_ERROR, | |
| 980 base::Bind(&NetLogErrorCallback, line_number, &message)); | |
| 981 | |
| 982 if (error_observer()) | |
| 983 error_observer()->OnPACScriptError(line_number, message); | |
| 984 } | 913 } |
| 985 } | 914 } |
| 986 | 915 |
| 987 void Job::LogEventToCurrentRequestAndGlobally( | 916 ProxyResolverV8TracingImpl::ProxyResolverV8TracingImpl( |
| 988 NetLog::EventType type, | |
| 989 const NetLog::ParametersCallback& parameters_callback) { | |
| 990 CheckIsOnWorkerThread(); | |
| 991 bound_net_log_.AddEvent(type, parameters_callback); | |
| 992 | |
| 993 // Emit to the global NetLog event stream. | |
| 994 if (net_log()) | |
| 995 net_log()->AddGlobalEntry(type, parameters_callback); | |
| 996 } | |
| 997 | |
| 998 ProxyResolverV8Tracing::ProxyResolverV8Tracing( | |
| 999 scoped_ptr<ProxyResolverErrorObserver> error_observer, | |
| 1000 scoped_ptr<base::Thread> thread, | 917 scoped_ptr<base::Thread> thread, |
| 1001 scoped_ptr<ProxyResolverV8> resolver, | 918 scoped_ptr<ProxyResolverV8> resolver, |
| 1002 scoped_ptr<Job::Params> job_params) | 919 scoped_ptr<Job::Params> job_params) |
| 1003 : thread_(thread.Pass()), | 920 : thread_(thread.Pass()), |
| 1004 v8_resolver_(resolver.Pass()), | 921 v8_resolver_(resolver.Pass()), |
| 1005 error_observer_(error_observer.Pass()), | |
| 1006 job_params_(job_params.Pass()), | 922 job_params_(job_params.Pass()), |
| 1007 num_outstanding_callbacks_(0) { | 923 num_outstanding_callbacks_(0) { |
| 1008 job_params_->num_outstanding_callbacks = &num_outstanding_callbacks_; | 924 job_params_->num_outstanding_callbacks = &num_outstanding_callbacks_; |
| 1009 } | 925 } |
| 1010 | 926 |
| 1011 ProxyResolverV8Tracing::~ProxyResolverV8Tracing() { | 927 ProxyResolverV8TracingImpl::~ProxyResolverV8TracingImpl() { |
| 1012 // Note, all requests should have been cancelled. | 928 // Note, all requests should have been cancelled. |
| 1013 CHECK_EQ(0, num_outstanding_callbacks_); | 929 CHECK_EQ(0, num_outstanding_callbacks_); |
| 1014 | 930 |
| 1015 // Join the worker thread. See http://crbug.com/69710. | 931 // Join the worker thread. See http://crbug.com/69710. |
| 1016 base::ThreadRestrictions::ScopedAllowIO allow_io; | 932 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 1017 thread_.reset(); | 933 thread_.reset(); |
| 1018 } | 934 } |
| 1019 | 935 |
| 1020 int ProxyResolverV8Tracing::GetProxyForURL(const GURL& url, | 936 void ProxyResolverV8TracingImpl::GetProxyForURL( |
| 1021 ProxyInfo* results, | 937 const GURL& url, |
| 1022 const CompletionCallback& callback, | 938 ProxyInfo* results, |
| 1023 RequestHandle* request, | 939 const CompletionCallback& callback, |
| 1024 const BoundNetLog& net_log) { | 940 ProxyResolver::RequestHandle* request, |
| 941 scoped_ptr<Bindings> bindings) { | |
| 1025 DCHECK(CalledOnValidThread()); | 942 DCHECK(CalledOnValidThread()); |
| 1026 DCHECK(!callback.is_null()); | 943 DCHECK(!callback.is_null()); |
| 1027 | 944 |
| 1028 scoped_refptr<Job> job = new Job(job_params_.get()); | 945 scoped_refptr<Job> job = new Job(job_params_.get(), bindings.Pass()); |
| 1029 | 946 |
| 1030 if (request) | 947 if (request) |
| 1031 *request = job.get(); | 948 *request = job.get(); |
| 1032 | 949 |
| 1033 job->StartGetProxyForURL(url, results, net_log, callback); | 950 job->StartGetProxyForURL(url, results, callback); |
| 1034 return ERR_IO_PENDING; | |
| 1035 } | 951 } |
| 1036 | 952 |
| 1037 void ProxyResolverV8Tracing::CancelRequest(RequestHandle request) { | 953 void ProxyResolverV8TracingImpl::CancelRequest( |
| 954 ProxyResolver::RequestHandle request) { | |
| 1038 Job* job = reinterpret_cast<Job*>(request); | 955 Job* job = reinterpret_cast<Job*>(request); |
| 1039 job->Cancel(); | 956 job->Cancel(); |
| 1040 } | 957 } |
| 1041 | 958 |
| 1042 LoadState ProxyResolverV8Tracing::GetLoadState(RequestHandle request) const { | 959 LoadState ProxyResolverV8TracingImpl::GetLoadState( |
| 960 ProxyResolver::RequestHandle request) const { | |
| 1043 Job* job = reinterpret_cast<Job*>(request); | 961 Job* job = reinterpret_cast<Job*>(request); |
| 1044 return job->GetLoadState(); | 962 return job->GetLoadState(); |
| 1045 } | 963 } |
| 1046 | 964 |
| 1047 } // namespace | 965 class ProxyResolverV8TracingFactoryImpl : public ProxyResolverV8TracingFactory { |
| 966 public: | |
| 967 ProxyResolverV8TracingFactoryImpl(); | |
| 968 ~ProxyResolverV8TracingFactoryImpl() override; | |
| 1048 | 969 |
| 1049 class ProxyResolverFactoryV8Tracing::CreateJob | 970 void CreateProxyResolverV8Tracing( |
| 971 const scoped_refptr<ProxyResolverScriptData>& pac_script, | |
| 972 scoped_ptr<ProxyResolverV8Tracing::Bindings> bindings, | |
| 973 scoped_ptr<ProxyResolverV8Tracing>* resolver, | |
| 974 const CompletionCallback& callback, | |
| 975 scoped_ptr<ProxyResolverFactory::Request>* request) override; | |
| 976 | |
| 977 private: | |
| 978 class CreateJob; | |
| 979 | |
| 980 void RemoveJob(CreateJob* job); | |
| 981 | |
| 982 std::set<CreateJob*> jobs_; | |
| 983 | |
| 984 DISALLOW_COPY_AND_ASSIGN(ProxyResolverV8TracingFactoryImpl); | |
| 985 }; | |
| 986 | |
| 987 class ProxyResolverV8TracingFactoryImpl::CreateJob | |
| 1050 : public ProxyResolverFactory::Request { | 988 : public ProxyResolverFactory::Request { |
| 1051 public: | 989 public: |
| 1052 CreateJob(ProxyResolverFactoryV8Tracing* factory, | 990 CreateJob(ProxyResolverV8TracingFactoryImpl* factory, |
| 1053 HostResolver* host_resolver, | 991 scoped_ptr<ProxyResolverV8Tracing::Bindings> bindings, |
| 1054 scoped_ptr<ProxyResolverErrorObserver> error_observer, | |
| 1055 NetLog* net_log, | |
| 1056 const ProxyResolver::LoadStateChangedCallback& | |
| 1057 load_state_changed_callback, | |
| 1058 const scoped_refptr<ProxyResolverScriptData>& pac_script, | 992 const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 1059 scoped_ptr<ProxyResolver>* resolver_out, | 993 scoped_ptr<ProxyResolverV8Tracing>* resolver_out, |
| 1060 const CompletionCallback& callback) | 994 const CompletionCallback& callback) |
| 1061 : factory_(factory), | 995 : factory_(factory), |
| 1062 thread_(new base::Thread("Proxy Resolver")), | 996 thread_(new base::Thread("Proxy Resolver")), |
| 1063 error_observer_(error_observer.Pass()), | |
| 1064 resolver_out_(resolver_out), | 997 resolver_out_(resolver_out), |
| 1065 callback_(callback), | 998 callback_(callback), |
| 1066 num_outstanding_callbacks_(0) { | 999 num_outstanding_callbacks_(0) { |
| 1067 // Start up the thread. | 1000 // Start up the thread. |
| 1068 base::Thread::Options options; | 1001 base::Thread::Options options; |
| 1069 options.timer_slack = base::TIMER_SLACK_MAXIMUM; | 1002 options.timer_slack = base::TIMER_SLACK_MAXIMUM; |
| 1070 CHECK(thread_->StartWithOptions(options)); | 1003 CHECK(thread_->StartWithOptions(options)); |
| 1071 job_params_.reset(new Job::Params( | 1004 job_params_.reset( |
| 1072 thread_->task_runner(), host_resolver, error_observer_.get(), net_log, | 1005 new Job::Params(thread_->task_runner(), &num_outstanding_callbacks_)); |
| 1073 load_state_changed_callback, &num_outstanding_callbacks_)); | 1006 create_resolver_job_ = new Job(job_params_.get(), bindings.Pass()); |
| 1074 create_resolver_job_ = new Job(job_params_.get()); | |
| 1075 create_resolver_job_->StartCreateV8Resolver( | 1007 create_resolver_job_->StartCreateV8Resolver( |
| 1076 pac_script, &v8_resolver_, | 1008 pac_script, &v8_resolver_, |
| 1077 base::Bind( | 1009 base::Bind( |
| 1078 &ProxyResolverFactoryV8Tracing::CreateJob::OnV8ResolverCreated, | 1010 &ProxyResolverV8TracingFactoryImpl::CreateJob::OnV8ResolverCreated, |
| 1079 base::Unretained(this))); | 1011 base::Unretained(this))); |
| 1080 } | 1012 } |
| 1081 | 1013 |
| 1082 ~CreateJob() override { | 1014 ~CreateJob() override { |
| 1083 if (factory_) { | 1015 if (factory_) { |
| 1084 factory_->RemoveJob(this); | 1016 factory_->RemoveJob(this); |
| 1085 DCHECK(create_resolver_job_); | 1017 DCHECK(create_resolver_job_); |
| 1086 create_resolver_job_->Cancel(); | 1018 create_resolver_job_->Cancel(); |
| 1087 StopWorkerThread(); | 1019 StopWorkerThread(); |
| 1088 } | 1020 } |
| 1089 DCHECK_EQ(0, num_outstanding_callbacks_); | 1021 DCHECK_EQ(0, num_outstanding_callbacks_); |
| 1090 } | 1022 } |
| 1091 | 1023 |
| 1092 void FactoryDestroyed() { | 1024 void FactoryDestroyed() { |
| 1093 factory_ = nullptr; | 1025 factory_ = nullptr; |
| 1094 create_resolver_job_->Cancel(); | 1026 create_resolver_job_->Cancel(); |
| 1095 create_resolver_job_ = nullptr; | 1027 create_resolver_job_ = nullptr; |
| 1096 StopWorkerThread(); | 1028 StopWorkerThread(); |
| 1097 } | 1029 } |
| 1098 | 1030 |
| 1099 private: | 1031 private: |
| 1100 void OnV8ResolverCreated(int error) { | 1032 void OnV8ResolverCreated(int error) { |
| 1101 DCHECK(factory_); | 1033 DCHECK(factory_); |
| 1102 if (error == OK) { | 1034 if (error == OK) { |
| 1103 job_params_->v8_resolver = v8_resolver_.get(); | 1035 job_params_->v8_resolver = v8_resolver_.get(); |
| 1104 resolver_out_->reset( | 1036 resolver_out_->reset(new ProxyResolverV8TracingImpl( |
| 1105 new ProxyResolverV8Tracing(error_observer_.Pass(), thread_.Pass(), | 1037 thread_.Pass(), v8_resolver_.Pass(), job_params_.Pass())); |
| 1106 v8_resolver_.Pass(), job_params_.Pass())); | |
| 1107 } else { | 1038 } else { |
| 1108 StopWorkerThread(); | 1039 StopWorkerThread(); |
| 1109 } | 1040 } |
| 1110 | 1041 |
| 1111 factory_->RemoveJob(this); | 1042 factory_->RemoveJob(this); |
| 1112 factory_ = nullptr; | 1043 factory_ = nullptr; |
| 1113 create_resolver_job_ = nullptr; | 1044 create_resolver_job_ = nullptr; |
| 1114 callback_.Run(error); | 1045 callback_.Run(error); |
| 1115 } | 1046 } |
| 1116 | 1047 |
| 1117 void StopWorkerThread() { | 1048 void StopWorkerThread() { |
| 1118 // Join the worker thread. See http://crbug.com/69710. | 1049 // Join the worker thread. See http://crbug.com/69710. |
| 1119 base::ThreadRestrictions::ScopedAllowIO allow_io; | 1050 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 1120 thread_.reset(); | 1051 thread_.reset(); |
| 1121 } | 1052 } |
| 1122 | 1053 |
| 1123 ProxyResolverFactoryV8Tracing* factory_; | 1054 ProxyResolverV8TracingFactoryImpl* factory_; |
| 1124 scoped_ptr<base::Thread> thread_; | 1055 scoped_ptr<base::Thread> thread_; |
| 1125 scoped_ptr<ProxyResolverErrorObserver> error_observer_; | |
| 1126 scoped_ptr<Job::Params> job_params_; | 1056 scoped_ptr<Job::Params> job_params_; |
| 1127 scoped_refptr<Job> create_resolver_job_; | 1057 scoped_refptr<Job> create_resolver_job_; |
| 1128 scoped_ptr<ProxyResolverV8> v8_resolver_; | 1058 scoped_ptr<ProxyResolverV8> v8_resolver_; |
| 1129 scoped_ptr<ProxyResolver>* resolver_out_; | 1059 scoped_ptr<ProxyResolverV8Tracing>* resolver_out_; |
| 1130 const CompletionCallback callback_; | 1060 const CompletionCallback callback_; |
| 1131 int num_outstanding_callbacks_; | 1061 int num_outstanding_callbacks_; |
| 1132 | 1062 |
| 1133 DISALLOW_COPY_AND_ASSIGN(CreateJob); | 1063 DISALLOW_COPY_AND_ASSIGN(CreateJob); |
| 1134 }; | 1064 }; |
| 1135 | 1065 |
| 1136 ProxyResolverFactoryV8Tracing::ProxyResolverFactoryV8Tracing( | 1066 ProxyResolverV8TracingFactoryImpl::ProxyResolverV8TracingFactoryImpl() { |
| 1137 HostResolver* host_resolver, | |
| 1138 NetLog* net_log, | |
| 1139 const ProxyResolver::LoadStateChangedCallback& callback, | |
| 1140 const base::Callback<scoped_ptr<ProxyResolverErrorObserver>()>& | |
| 1141 error_observer_factory) | |
| 1142 : ProxyResolverFactory(true), | |
| 1143 host_resolver_(host_resolver), | |
| 1144 net_log_(net_log), | |
| 1145 load_state_changed_callback_(callback), | |
| 1146 error_observer_factory_(error_observer_factory) { | |
| 1147 } | 1067 } |
| 1148 | 1068 |
| 1149 ProxyResolverFactoryV8Tracing::~ProxyResolverFactoryV8Tracing() { | 1069 ProxyResolverV8TracingFactoryImpl::~ProxyResolverV8TracingFactoryImpl() { |
| 1150 for (auto job : jobs_) { | 1070 for (auto job : jobs_) { |
| 1151 job->FactoryDestroyed(); | 1071 job->FactoryDestroyed(); |
| 1152 } | 1072 } |
| 1153 } | 1073 } |
| 1154 | 1074 |
| 1155 // ProxyResolverFactory override. | 1075 void ProxyResolverV8TracingFactoryImpl::CreateProxyResolverV8Tracing( |
| 1156 int ProxyResolverFactoryV8Tracing::CreateProxyResolver( | |
| 1157 const scoped_refptr<ProxyResolverScriptData>& pac_script, | 1076 const scoped_refptr<ProxyResolverScriptData>& pac_script, |
| 1158 scoped_ptr<ProxyResolver>* resolver, | 1077 scoped_ptr<ProxyResolverV8Tracing::Bindings> bindings, |
| 1078 scoped_ptr<ProxyResolverV8Tracing>* resolver, | |
| 1159 const CompletionCallback& callback, | 1079 const CompletionCallback& callback, |
| 1160 scoped_ptr<Request>* request) { | 1080 scoped_ptr<ProxyResolverFactory::Request>* request) { |
| 1161 scoped_ptr<CreateJob> job(new CreateJob( | 1081 scoped_ptr<CreateJob> job( |
| 1162 this, host_resolver_, | 1082 new CreateJob(this, bindings.Pass(), pac_script, resolver, callback)); |
| 1163 error_observer_factory_.is_null() ? nullptr | |
| 1164 : error_observer_factory_.Run(), | |
| 1165 net_log_, load_state_changed_callback_, pac_script, resolver, callback)); | |
| 1166 jobs_.insert(job.get()); | 1083 jobs_.insert(job.get()); |
| 1167 *request = job.Pass(); | 1084 *request = job.Pass(); |
| 1168 return ERR_IO_PENDING; | |
| 1169 } | 1085 } |
| 1170 | 1086 |
| 1171 void ProxyResolverFactoryV8Tracing::RemoveJob( | 1087 void ProxyResolverV8TracingFactoryImpl::RemoveJob( |
| 1172 ProxyResolverFactoryV8Tracing::CreateJob* job) { | 1088 ProxyResolverV8TracingFactoryImpl::CreateJob* job) { |
| 1173 size_t erased = jobs_.erase(job); | 1089 size_t erased = jobs_.erase(job); |
| 1174 DCHECK_EQ(1u, erased); | 1090 DCHECK_EQ(1u, erased); |
| 1175 } | 1091 } |
| 1176 | 1092 |
| 1093 } // namespace | |
| 1094 | |
| 1095 // static | |
| 1096 scoped_ptr<ProxyResolverV8TracingFactory> | |
| 1097 ProxyResolverV8TracingFactory::Create() { | |
| 1098 return make_scoped_ptr(new ProxyResolverV8TracingFactoryImpl()); | |
| 1099 } | |
| 1100 | |
| 1177 } // namespace net | 1101 } // namespace net |
| OLD | NEW |