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