| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/multi_threaded_proxy_resolver.h" | 5 #include "net/proxy/multi_threaded_proxy_resolver.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 public: | 168 public: |
| 169 SetPacScriptJob(const scoped_refptr<ProxyResolverScriptData>& script_data, | 169 SetPacScriptJob(const scoped_refptr<ProxyResolverScriptData>& script_data, |
| 170 const CompletionCallback& callback) | 170 const CompletionCallback& callback) |
| 171 : Job(!callback.is_null() ? TYPE_SET_PAC_SCRIPT : | 171 : Job(!callback.is_null() ? TYPE_SET_PAC_SCRIPT : |
| 172 TYPE_SET_PAC_SCRIPT_INTERNAL, | 172 TYPE_SET_PAC_SCRIPT_INTERNAL, |
| 173 callback), | 173 callback), |
| 174 script_data_(script_data) { | 174 script_data_(script_data) { |
| 175 } | 175 } |
| 176 | 176 |
| 177 // Runs on the worker thread. | 177 // Runs on the worker thread. |
| 178 virtual void Run(scoped_refptr<base::MessageLoopProxy> origin_loop) override { | 178 void Run(scoped_refptr<base::MessageLoopProxy> origin_loop) override { |
| 179 ProxyResolver* resolver = executor()->resolver(); | 179 ProxyResolver* resolver = executor()->resolver(); |
| 180 int rv = resolver->SetPacScript(script_data_, CompletionCallback()); | 180 int rv = resolver->SetPacScript(script_data_, CompletionCallback()); |
| 181 | 181 |
| 182 DCHECK_NE(rv, ERR_IO_PENDING); | 182 DCHECK_NE(rv, ERR_IO_PENDING); |
| 183 origin_loop->PostTask( | 183 origin_loop->PostTask( |
| 184 FROM_HERE, | 184 FROM_HERE, |
| 185 base::Bind(&SetPacScriptJob::RequestComplete, this, rv)); | 185 base::Bind(&SetPacScriptJob::RequestComplete, this, rv)); |
| 186 } | 186 } |
| 187 | 187 |
| 188 protected: | 188 protected: |
| 189 virtual ~SetPacScriptJob() {} | 189 ~SetPacScriptJob() override {} |
| 190 | 190 |
| 191 private: | 191 private: |
| 192 // Runs the completion callback on the origin thread. | 192 // Runs the completion callback on the origin thread. |
| 193 void RequestComplete(int result_code) { | 193 void RequestComplete(int result_code) { |
| 194 // The task may have been cancelled after it was started. | 194 // The task may have been cancelled after it was started. |
| 195 if (!was_cancelled() && has_user_callback()) { | 195 if (!was_cancelled() && has_user_callback()) { |
| 196 RunUserCallback(result_code); | 196 RunUserCallback(result_code); |
| 197 } | 197 } |
| 198 OnJobCompleted(); | 198 OnJobCompleted(); |
| 199 } | 199 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 215 : Job(TYPE_GET_PROXY_FOR_URL, callback), | 215 : Job(TYPE_GET_PROXY_FOR_URL, callback), |
| 216 results_(results), | 216 results_(results), |
| 217 net_log_(net_log), | 217 net_log_(net_log), |
| 218 url_(url), | 218 url_(url), |
| 219 was_waiting_for_thread_(false) { | 219 was_waiting_for_thread_(false) { |
| 220 DCHECK(!callback.is_null()); | 220 DCHECK(!callback.is_null()); |
| 221 } | 221 } |
| 222 | 222 |
| 223 BoundNetLog* net_log() { return &net_log_; } | 223 BoundNetLog* net_log() { return &net_log_; } |
| 224 | 224 |
| 225 virtual void WaitingForThread() override { | 225 void WaitingForThread() override { |
| 226 was_waiting_for_thread_ = true; | 226 was_waiting_for_thread_ = true; |
| 227 net_log_.BeginEvent(NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD); | 227 net_log_.BeginEvent(NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD); |
| 228 } | 228 } |
| 229 | 229 |
| 230 virtual void FinishedWaitingForThread() override { | 230 void FinishedWaitingForThread() override { |
| 231 DCHECK(executor()); | 231 DCHECK(executor()); |
| 232 | 232 |
| 233 if (was_waiting_for_thread_) { | 233 if (was_waiting_for_thread_) { |
| 234 net_log_.EndEvent(NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD); | 234 net_log_.EndEvent(NetLog::TYPE_WAITING_FOR_PROXY_RESOLVER_THREAD); |
| 235 } | 235 } |
| 236 | 236 |
| 237 net_log_.AddEvent( | 237 net_log_.AddEvent( |
| 238 NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, | 238 NetLog::TYPE_SUBMITTED_TO_RESOLVER_THREAD, |
| 239 NetLog::IntegerCallback("thread_number", executor()->thread_number())); | 239 NetLog::IntegerCallback("thread_number", executor()->thread_number())); |
| 240 } | 240 } |
| 241 | 241 |
| 242 // Runs on the worker thread. | 242 // Runs on the worker thread. |
| 243 virtual void Run(scoped_refptr<base::MessageLoopProxy> origin_loop) override { | 243 void Run(scoped_refptr<base::MessageLoopProxy> origin_loop) override { |
| 244 ProxyResolver* resolver = executor()->resolver(); | 244 ProxyResolver* resolver = executor()->resolver(); |
| 245 int rv = resolver->GetProxyForURL( | 245 int rv = resolver->GetProxyForURL( |
| 246 url_, &results_buf_, CompletionCallback(), NULL, net_log_); | 246 url_, &results_buf_, CompletionCallback(), NULL, net_log_); |
| 247 DCHECK_NE(rv, ERR_IO_PENDING); | 247 DCHECK_NE(rv, ERR_IO_PENDING); |
| 248 | 248 |
| 249 origin_loop->PostTask( | 249 origin_loop->PostTask( |
| 250 FROM_HERE, | 250 FROM_HERE, |
| 251 base::Bind(&GetProxyForURLJob::QueryComplete, this, rv)); | 251 base::Bind(&GetProxyForURLJob::QueryComplete, this, rv)); |
| 252 } | 252 } |
| 253 | 253 |
| 254 protected: | 254 protected: |
| 255 virtual ~GetProxyForURLJob() {} | 255 ~GetProxyForURLJob() override {} |
| 256 | 256 |
| 257 private: | 257 private: |
| 258 // Runs the completion callback on the origin thread. | 258 // Runs the completion callback on the origin thread. |
| 259 void QueryComplete(int result_code) { | 259 void QueryComplete(int result_code) { |
| 260 // The Job may have been cancelled after it was started. | 260 // The Job may have been cancelled after it was started. |
| 261 if (!was_cancelled()) { | 261 if (!was_cancelled()) { |
| 262 if (result_code >= OK) { // Note: unit-tests use values > 0. | 262 if (result_code >= OK) { // Note: unit-tests use values > 0. |
| 263 results_->Use(results_buf_); | 263 results_->Use(results_buf_); |
| 264 } | 264 } |
| 265 RunUserCallback(result_code); | 265 RunUserCallback(result_code); |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 return; | 531 return; |
| 532 | 532 |
| 533 // Get the next job to process (FIFO). Transfer it from the pending queue | 533 // Get the next job to process (FIFO). Transfer it from the pending queue |
| 534 // to the executor. | 534 // to the executor. |
| 535 scoped_refptr<Job> job = pending_jobs_.front(); | 535 scoped_refptr<Job> job = pending_jobs_.front(); |
| 536 pending_jobs_.pop_front(); | 536 pending_jobs_.pop_front(); |
| 537 executor->StartJob(job.get()); | 537 executor->StartJob(job.get()); |
| 538 } | 538 } |
| 539 | 539 |
| 540 } // namespace net | 540 } // namespace net |
| OLD | NEW |