Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/mock_http_cache.h" | 5 #include "net/http/mock_http_cache.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 } | 334 } |
| 335 | 335 |
| 336 private: | 336 private: |
| 337 net::OldCompletionCallback* callback_; | 337 net::OldCompletionCallback* callback_; |
| 338 int result_; | 338 int result_; |
| 339 DISALLOW_COPY_AND_ASSIGN(CallbackRunner); | 339 DISALLOW_COPY_AND_ASSIGN(CallbackRunner); |
| 340 }; | 340 }; |
| 341 | 341 |
| 342 MockDiskCache::MockDiskCache() | 342 MockDiskCache::MockDiskCache() |
| 343 : open_count_(0), create_count_(0), fail_requests_(false), | 343 : open_count_(0), create_count_(0), fail_requests_(false), |
| 344 soft_failures_(false) { | 344 soft_failures_(false), double_create_check_(true) { |
| 345 } | 345 } |
| 346 | 346 |
| 347 MockDiskCache::~MockDiskCache() { | 347 MockDiskCache::~MockDiskCache() { |
| 348 ReleaseAll(); | 348 ReleaseAll(); |
| 349 } | 349 } |
| 350 | 350 |
| 351 int32 MockDiskCache::GetEntryCount() const { | 351 int32 MockDiskCache::GetEntryCount() const { |
| 352 return static_cast<int32>(entries_.size()); | 352 return static_cast<int32>(entries_.size()); |
| 353 } | 353 } |
| 354 | 354 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 385 | 385 |
| 386 int MockDiskCache::CreateEntry(const std::string& key, | 386 int MockDiskCache::CreateEntry(const std::string& key, |
| 387 disk_cache::Entry** entry, | 387 disk_cache::Entry** entry, |
| 388 net::OldCompletionCallback* callback) { | 388 net::OldCompletionCallback* callback) { |
| 389 DCHECK(callback); | 389 DCHECK(callback); |
| 390 if (fail_requests_) | 390 if (fail_requests_) |
| 391 return net::ERR_CACHE_CREATE_FAILURE; | 391 return net::ERR_CACHE_CREATE_FAILURE; |
| 392 | 392 |
| 393 EntryMap::iterator it = entries_.find(key); | 393 EntryMap::iterator it = entries_.find(key); |
| 394 if (it != entries_.end()) { | 394 if (it != entries_.end()) { |
| 395 DCHECK(it->second->is_doomed()); | 395 if (!it->second->is_doomed()) { |
| 396 if (double_create_check_) | |
| 397 NOTREACHED(); | |
| 398 else | |
| 399 return net::ERR_CACHE_CREATE_FAILURE; | |
|
wtc
2011/11/30 00:22:09
Nit: add curly braces?
rvargas (doing something else)
2011/11/30 01:05:24
Sorry, I missed this comment. Before I change it,
wtc
2011/11/30 01:36:40
You can ignore this change request.
When I first
| |
| 400 } | |
| 396 it->second->Release(); | 401 it->second->Release(); |
| 397 entries_.erase(it); | 402 entries_.erase(it); |
| 398 } | 403 } |
| 399 | 404 |
| 400 create_count_++; | 405 create_count_++; |
| 401 | 406 |
| 402 MockDiskEntry* new_entry = new MockDiskEntry(key); | 407 MockDiskEntry* new_entry = new MockDiskEntry(key); |
| 403 | 408 |
| 404 new_entry->AddRef(); | 409 new_entry->AddRef(); |
| 405 entries_[key] = new_entry; | 410 entries_[key] = new_entry; |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 void MockBlockingBackendFactory::FinishCreation() { | 609 void MockBlockingBackendFactory::FinishCreation() { |
| 605 block_ = false; | 610 block_ = false; |
| 606 if (callback_) { | 611 if (callback_) { |
| 607 if (!fail_) | 612 if (!fail_) |
| 608 *backend_ = new MockDiskCache(); | 613 *backend_ = new MockDiskCache(); |
| 609 net::OldCompletionCallback* cb = callback_; | 614 net::OldCompletionCallback* cb = callback_; |
| 610 callback_ = NULL; | 615 callback_ = NULL; |
| 611 cb->Run(Result()); // This object can be deleted here. | 616 cb->Run(Result()); // This object can be deleted here. |
| 612 } | 617 } |
| 613 } | 618 } |
| OLD | NEW |