Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1470)

Side by Side Diff: net/http/mock_http_cache.cc

Issue 181173003: Deactivate cache entry when caching is stopped. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/http/mock_http_cache.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/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/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "net/base/completion_callback.h" 9 #include "net/base/completion_callback.h"
10 #include "net/base/net_errors.h" 10 #include "net/base/net_errors.h"
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 if (soft_failures_) 377 if (soft_failures_)
378 it->second->set_fail_requests(); 378 it->second->set_fail_requests();
379 379
380 if (GetTestModeForEntry(key) & TEST_MODE_SYNC_CACHE_START) 380 if (GetTestModeForEntry(key) & TEST_MODE_SYNC_CACHE_START)
381 return net::OK; 381 return net::OK;
382 382
383 CallbackLater(callback, net::OK); 383 CallbackLater(callback, net::OK);
384 return net::ERR_IO_PENDING; 384 return net::ERR_IO_PENDING;
385 } 385 }
386 386
387 int MockDiskCache::OpenDoomedEntry(const std::string& key,
388 disk_cache::Entry** entry,
389 const net::CompletionCallback& callback) {
390 DCHECK(!callback.is_null());
391
392 EntryMap::iterator it = entries_.find(key);
393 if (it == entries_.end())
394 return net::ERR_CACHE_OPEN_FAILURE;
395 if (!it->second->is_doomed())
396 return net::ERR_CACHE_OPEN_FAILURE;
397
398 it->second->AddRef();
399 *entry = it->second;
400
401 CallbackLater(callback, net::OK);
402
403 return net::ERR_IO_PENDING;
404 }
405
387 int MockDiskCache::CreateEntry(const std::string& key, 406 int MockDiskCache::CreateEntry(const std::string& key,
388 disk_cache::Entry** entry, 407 disk_cache::Entry** entry,
389 const net::CompletionCallback& callback) { 408 const net::CompletionCallback& callback) {
390 DCHECK(!callback.is_null()); 409 DCHECK(!callback.is_null());
391 if (fail_requests_) 410 if (fail_requests_)
392 return net::ERR_CACHE_CREATE_FAILURE; 411 return net::ERR_CACHE_CREATE_FAILURE;
393 412
394 EntryMap::iterator it = entries_.find(key); 413 EntryMap::iterator it = entries_.find(key);
395 if (it != entries_.end()) { 414 if (it != entries_.end()) {
396 if (!it->second->is_doomed()) { 415 if (!it->second->is_doomed()) {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 return (rv == len); 568 return (rv == len);
550 } 569 }
551 570
552 bool MockHttpCache::OpenBackendEntry(const std::string& key, 571 bool MockHttpCache::OpenBackendEntry(const std::string& key,
553 disk_cache::Entry** entry) { 572 disk_cache::Entry** entry) {
554 net::TestCompletionCallback cb; 573 net::TestCompletionCallback cb;
555 int rv = disk_cache()->OpenEntry(key, entry, cb.callback()); 574 int rv = disk_cache()->OpenEntry(key, entry, cb.callback());
556 return (cb.GetResult(rv) == net::OK); 575 return (cb.GetResult(rv) == net::OK);
557 } 576 }
558 577
578 bool MockHttpCache::OpenBackendDoomedEntry(const std::string& key,
579 disk_cache::Entry** entry) {
580 net::TestCompletionCallback cb;
581 int rv = disk_cache()->OpenDoomedEntry(key, entry, cb.callback());
582 return (cb.GetResult(rv) == net::OK);
583 }
584
559 bool MockHttpCache::CreateBackendEntry(const std::string& key, 585 bool MockHttpCache::CreateBackendEntry(const std::string& key,
560 disk_cache::Entry** entry, 586 disk_cache::Entry** entry,
561 net::NetLog* net_log) { 587 net::NetLog* net_log) {
562 net::TestCompletionCallback cb; 588 net::TestCompletionCallback cb;
563 int rv = disk_cache()->CreateEntry(key, entry, cb.callback()); 589 int rv = disk_cache()->CreateEntry(key, entry, cb.callback());
564 return (cb.GetResult(rv) == net::OK); 590 return (cb.GetResult(rv) == net::OK);
565 } 591 }
566 592
567 // Static. 593 // Static.
568 int MockHttpCache::GetTestMode(int test_mode) { 594 int MockHttpCache::GetTestMode(int test_mode) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 void MockBlockingBackendFactory::FinishCreation() { 648 void MockBlockingBackendFactory::FinishCreation() {
623 block_ = false; 649 block_ = false;
624 if (!callback_.is_null()) { 650 if (!callback_.is_null()) {
625 if (!fail_) 651 if (!fail_)
626 backend_->reset(new MockDiskCache()); 652 backend_->reset(new MockDiskCache());
627 net::CompletionCallback cb = callback_; 653 net::CompletionCallback cb = callback_;
628 callback_.Reset(); 654 callback_.Reset();
629 cb.Run(Result()); // This object can be deleted here. 655 cb.Run(Result()); // This object can be deleted here.
630 } 656 }
631 } 657 }
OLDNEW
« no previous file with comments | « net/http/mock_http_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698