| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/single_threaded_proxy_resolver.h" | 5 #include "net/proxy/single_threaded_proxy_resolver.h" |
| 6 | 6 |
| 7 #include "base/thread.h" | 7 #include "base/thread.h" |
| 8 #include "net/base/load_log.h" | 8 #include "net/base/load_log.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "net/proxy/proxy_info.h" | 10 #include "net/proxy/proxy_info.h" |
| 11 | 11 |
| 12 namespace net { | 12 namespace net { |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 class PurgeMemoryTask : public base::RefCountedThreadSafe<PurgeMemoryTask> { | 16 class PurgeMemoryTask : public base::RefCountedThreadSafe<PurgeMemoryTask> { |
| 17 public: | 17 public: |
| 18 explicit PurgeMemoryTask(ProxyResolver* resolver) : resolver_(resolver) {} | 18 explicit PurgeMemoryTask(ProxyResolver* resolver) : resolver_(resolver) {} |
| 19 void PurgeMemory() { resolver_->PurgeMemory(); } | 19 void PurgeMemory() { resolver_->PurgeMemory(); } |
| 20 private: | 20 private: |
| 21 friend class base::RefCountedThreadSafe<PurgeMemoryTask>; |
| 22 ~PurgeMemoryTask() {} |
| 21 ProxyResolver* resolver_; | 23 ProxyResolver* resolver_; |
| 22 }; | 24 }; |
| 23 | 25 |
| 24 } | 26 } |
| 25 | 27 |
| 26 // SingleThreadedProxyResolver::SetPacScriptTask ------------------------------ | 28 // SingleThreadedProxyResolver::SetPacScriptTask ------------------------------ |
| 27 | 29 |
| 28 // Runs on the worker thread to call ProxyResolver::SetPacScript. | 30 // Runs on the worker thread to call ProxyResolver::SetPacScript. |
| 29 class SingleThreadedProxyResolver::SetPacScriptTask | 31 class SingleThreadedProxyResolver::SetPacScriptTask |
| 30 : public base::RefCountedThreadSafe< | 32 : public base::RefCountedThreadSafe< |
| (...skipping 22 matching lines...) Expand all Loading... |
| 53 // Clear these to inform RequestComplete that it should not try to | 55 // Clear these to inform RequestComplete that it should not try to |
| 54 // access them. | 56 // access them. |
| 55 coordinator_ = NULL; | 57 coordinator_ = NULL; |
| 56 callback_ = NULL; | 58 callback_ = NULL; |
| 57 } | 59 } |
| 58 | 60 |
| 59 // Returns true if Cancel() has been called. | 61 // Returns true if Cancel() has been called. |
| 60 bool was_cancelled() const { return callback_ == NULL; } | 62 bool was_cancelled() const { return callback_ == NULL; } |
| 61 | 63 |
| 62 private: | 64 private: |
| 65 friend class base::RefCountedThreadSafe< |
| 66 SingleThreadedProxyResolver::SetPacScriptTask>; |
| 67 |
| 68 ~SetPacScriptTask() {} |
| 69 |
| 63 // Runs on the worker thread. | 70 // Runs on the worker thread. |
| 64 void DoRequest(ProxyResolver* resolver) { | 71 void DoRequest(ProxyResolver* resolver) { |
| 65 int rv = resolver->expects_pac_bytes() ? | 72 int rv = resolver->expects_pac_bytes() ? |
| 66 resolver->SetPacScriptByData(pac_bytes_, NULL) : | 73 resolver->SetPacScriptByData(pac_bytes_, NULL) : |
| 67 resolver->SetPacScriptByUrl(pac_url_, NULL); | 74 resolver->SetPacScriptByUrl(pac_url_, NULL); |
| 68 | 75 |
| 69 DCHECK_NE(rv, ERR_IO_PENDING); | 76 DCHECK_NE(rv, ERR_IO_PENDING); |
| 70 origin_loop_->PostTask(FROM_HERE, | 77 origin_loop_->PostTask(FROM_HERE, |
| 71 NewRunnableMethod(this, &SetPacScriptTask::RequestComplete, rv)); | 78 NewRunnableMethod(this, &SetPacScriptTask::RequestComplete, rv)); |
| 72 } | 79 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 // access them. | 137 // access them. |
| 131 coordinator_ = NULL; | 138 coordinator_ = NULL; |
| 132 callback_ = NULL; | 139 callback_ = NULL; |
| 133 results_ = NULL; | 140 results_ = NULL; |
| 134 } | 141 } |
| 135 | 142 |
| 136 // Returns true if Cancel() has been called. | 143 // Returns true if Cancel() has been called. |
| 137 bool was_cancelled() const { return callback_ == NULL; } | 144 bool was_cancelled() const { return callback_ == NULL; } |
| 138 | 145 |
| 139 private: | 146 private: |
| 147 friend class base::RefCountedThreadSafe<SingleThreadedProxyResolver::Job>; |
| 148 |
| 149 ~Job() {} |
| 150 |
| 140 // Runs on the worker thread. | 151 // Runs on the worker thread. |
| 141 void DoQuery(ProxyResolver* resolver) { | 152 void DoQuery(ProxyResolver* resolver) { |
| 142 LoadLog* worker_log = new LoadLog; | 153 LoadLog* worker_log = new LoadLog; |
| 143 worker_log->AddRef(); // Balanced in QueryComplete. | 154 worker_log->AddRef(); // Balanced in QueryComplete. |
| 144 | 155 |
| 145 int rv = resolver->GetProxyForURL(url_, &results_buf_, NULL, NULL, | 156 int rv = resolver->GetProxyForURL(url_, &results_buf_, NULL, NULL, |
| 146 worker_log); | 157 worker_log); |
| 147 DCHECK_NE(rv, ERR_IO_PENDING); | 158 DCHECK_NE(rv, ERR_IO_PENDING); |
| 148 | 159 |
| 149 origin_loop_->PostTask(FROM_HERE, | 160 origin_loop_->PostTask(FROM_HERE, |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 ProcessPendingJobs(); | 321 ProcessPendingJobs(); |
| 311 } | 322 } |
| 312 | 323 |
| 313 void SingleThreadedProxyResolver::RemoveOutstandingSetPacScriptTask( | 324 void SingleThreadedProxyResolver::RemoveOutstandingSetPacScriptTask( |
| 314 SetPacScriptTask* task) { | 325 SetPacScriptTask* task) { |
| 315 DCHECK_EQ(outstanding_set_pac_script_task_.get(), task); | 326 DCHECK_EQ(outstanding_set_pac_script_task_.get(), task); |
| 316 outstanding_set_pac_script_task_ = NULL; | 327 outstanding_set_pac_script_task_ = NULL; |
| 317 } | 328 } |
| 318 | 329 |
| 319 } // namespace net | 330 } // namespace net |
| OLD | NEW |