OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/http/http_cache.h" | 5 #include "net/http/http_cache.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 | 10 |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 | 127 |
128 // This class is a specialized type of CompletionCallback that allows us to | 128 // This class is a specialized type of CompletionCallback that allows us to |
129 // pass multiple arguments to the completion routine. | 129 // pass multiple arguments to the completion routine. |
130 class HttpCache::BackendCallback : public CallbackRunner<Tuple1<int> > { | 130 class HttpCache::BackendCallback : public CallbackRunner<Tuple1<int> > { |
131 public: | 131 public: |
132 BackendCallback(HttpCache* cache, PendingOp* pending_op) | 132 BackendCallback(HttpCache* cache, PendingOp* pending_op) |
133 : cache_(cache), pending_op_(pending_op) {} | 133 : cache_(cache), pending_op_(pending_op) {} |
134 ~BackendCallback() {} | 134 ~BackendCallback() {} |
135 | 135 |
136 virtual void RunWithParams(const Tuple1<int>& params) { | 136 virtual void RunWithParams(const Tuple1<int>& params) { |
137 cache_->OnIOComplete(params.a, pending_op_); | 137 if (cache_) |
| 138 cache_->OnIOComplete(params.a, pending_op_); |
138 delete this; | 139 delete this; |
139 } | 140 } |
140 | 141 |
| 142 void Cancel() { |
| 143 cache_ = NULL; |
| 144 } |
| 145 |
141 private: | 146 private: |
142 HttpCache* cache_; | 147 HttpCache* cache_; |
143 PendingOp* pending_op_; | 148 PendingOp* pending_op_; |
144 DISALLOW_COPY_AND_ASSIGN(BackendCallback); | 149 DISALLOW_COPY_AND_ASSIGN(BackendCallback); |
145 }; | 150 }; |
146 | 151 |
147 //----------------------------------------------------------------------------- | 152 //----------------------------------------------------------------------------- |
148 | 153 |
149 // This class encapsulates a transaction whose only purpose is to write metadata | 154 // This class encapsulates a transaction whose only purpose is to write metadata |
150 // to a given entry. | 155 // to a given entry. |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 } | 281 } |
277 | 282 |
278 STLDeleteElements(&doomed_entries_); | 283 STLDeleteElements(&doomed_entries_); |
279 | 284 |
280 PendingOpsMap::iterator pending_it = pending_ops_.begin(); | 285 PendingOpsMap::iterator pending_it = pending_ops_.begin(); |
281 for (; pending_it != pending_ops_.end(); ++pending_it) { | 286 for (; pending_it != pending_ops_.end(); ++pending_it) { |
282 // We are not notifying the transactions about the cache going away, even | 287 // We are not notifying the transactions about the cache going away, even |
283 // though they are waiting for a callback that will never fire. | 288 // though they are waiting for a callback that will never fire. |
284 PendingOp* pending_op = pending_it->second; | 289 PendingOp* pending_op = pending_it->second; |
285 delete pending_op->writer; | 290 delete pending_op->writer; |
286 delete pending_op->callback; | 291 if (building_backend_) { |
| 292 // If we don't have a backend, when its construction finishes it will |
| 293 // deliver the callbacks. |
| 294 BackendCallback* callback = |
| 295 static_cast<BackendCallback*>(pending_op->callback); |
| 296 callback->Cancel(); |
| 297 } else { |
| 298 delete pending_op->callback; |
| 299 } |
287 | 300 |
288 STLDeleteElements(&pending_op->pending_queue); | 301 STLDeleteElements(&pending_op->pending_queue); |
289 delete pending_op; | 302 delete pending_op; |
290 } | 303 } |
291 } | 304 } |
292 | 305 |
293 int HttpCache::GetBackend(disk_cache::Backend** backend, | 306 int HttpCache::GetBackend(disk_cache::Backend** backend, |
294 CompletionCallback* callback) { | 307 CompletionCallback* callback) { |
295 DCHECK(callback != NULL); | 308 DCHECK(callback != NULL); |
296 | 309 |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1001 // This could be an external caller or a transaction waiting on Start(). | 1014 // This could be an external caller or a transaction waiting on Start(). |
1002 pending_item->DoCallback(result, temp_backend_); | 1015 pending_item->DoCallback(result, temp_backend_); |
1003 pending_item->NotifyTransaction(result, NULL); | 1016 pending_item->NotifyTransaction(result, NULL); |
1004 } | 1017 } |
1005 | 1018 |
1006 DeletePendingOp(pending_op); | 1019 DeletePendingOp(pending_op); |
1007 building_backend_ = false; | 1020 building_backend_ = false; |
1008 } | 1021 } |
1009 | 1022 |
1010 } // namespace net | 1023 } // namespace net |
OLD | NEW |