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

Side by Side Diff: components/browsing_data/content/storage_partition_http_cache_data_remover.cc

Issue 2768883002: Change MockBrowsingDataRemover to MockBrowsingDataRemoverDelegate (Closed)
Patch Set: MockDelegate Created 3 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 | « chrome/browser/chrome_content_browser_client_unittest.cc ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/browsing_data/content/storage_partition_http_cache_data_rem over.h" 5 #include "components/browsing_data/content/storage_partition_http_cache_data_rem over.h"
6 6
7 #include "base/location.h" 7 #include "base/location.h"
8 #include "base/single_thread_task_runner.h" 8 #include "base/single_thread_task_runner.h"
9 #include "base/threading/thread_task_runner_handle.h" 9 #include "base/threading/thread_task_runner_handle.h"
10 #include "components/browsing_data/content/conditional_cache_deletion_helper.h" 10 #include "components/browsing_data/content/conditional_cache_deletion_helper.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 BrowserThread::IO, FROM_HERE, 76 BrowserThread::IO, FROM_HERE,
77 base::Bind( 77 base::Bind(
78 &StoragePartitionHttpCacheDataRemover::ClearHttpCacheOnIOThread, 78 &StoragePartitionHttpCacheDataRemover::ClearHttpCacheOnIOThread,
79 base::Unretained(this))); 79 base::Unretained(this)));
80 } 80 }
81 81
82 void StoragePartitionHttpCacheDataRemover::ClearHttpCacheOnIOThread() { 82 void StoragePartitionHttpCacheDataRemover::ClearHttpCacheOnIOThread() {
83 DCHECK_CURRENTLY_ON(BrowserThread::IO); 83 DCHECK_CURRENTLY_ON(BrowserThread::IO);
84 next_cache_state_ = CacheState::NONE; 84 next_cache_state_ = CacheState::NONE;
85 DCHECK_EQ(CacheState::NONE, next_cache_state_); 85 DCHECK_EQ(CacheState::NONE, next_cache_state_);
86 DCHECK(main_context_getter_.get());
87 DCHECK(media_context_getter_.get());
88 86
89 next_cache_state_ = CacheState::CREATE_MAIN; 87 next_cache_state_ = CacheState::CREATE_MAIN;
90 DoClearCache(net::OK); 88 DoClearCache(net::OK);
91 } 89 }
92 90
93 void StoragePartitionHttpCacheDataRemover::ClearedHttpCache() { 91 void StoragePartitionHttpCacheDataRemover::ClearedHttpCache() {
94 DCHECK_CURRENTLY_ON(BrowserThread::UI); 92 DCHECK_CURRENTLY_ON(BrowserThread::UI);
95 done_callback_.Run(); 93 done_callback_.Run();
96 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); 94 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
97 } 95 }
98 96
99 // The expected state sequence is CacheState::NONE --> CacheState::CREATE_MAIN 97 // The expected state sequence is CacheState::NONE --> CacheState::CREATE_MAIN
100 // --> CacheState::PROCESS_MAIN --> CacheState::CREATE_MEDIA --> 98 // --> CacheState::PROCESS_MAIN --> CacheState::CREATE_MEDIA -->
engedy 2017/03/23 15:23:07 nit: Could you please propagate new names of state
msramek 2017/03/23 15:33:02 Done.
101 // CacheState::PROCESS_MEDIA --> CacheState::DONE, and any errors are ignored. 99 // CacheState::PROCESS_MEDIA --> CacheState::DONE, and any errors are ignored.
102 void StoragePartitionHttpCacheDataRemover::DoClearCache(int rv) { 100 void StoragePartitionHttpCacheDataRemover::DoClearCache(int rv) {
103 DCHECK_NE(CacheState::NONE, next_cache_state_); 101 DCHECK_NE(CacheState::NONE, next_cache_state_);
104 102
105 while (rv != net::ERR_IO_PENDING && next_cache_state_ != CacheState::NONE) { 103 while (rv != net::ERR_IO_PENDING && next_cache_state_ != CacheState::NONE) {
106 switch (next_cache_state_) { 104 switch (next_cache_state_) {
107 case CacheState::CREATE_MAIN: 105 case CacheState::CREATE_MAIN:
108 case CacheState::CREATE_MEDIA: { 106 case CacheState::CREATE_MEDIA: {
109 // Get a pointer to the cache. 107 // Get a pointer to the cache.
110 net::URLRequestContextGetter* getter = 108 net::URLRequestContextGetter* getter =
111 (next_cache_state_ == CacheState::CREATE_MAIN) 109 (next_cache_state_ == CacheState::CREATE_MAIN)
112 ? main_context_getter_.get() 110 ? main_context_getter_.get()
113 : media_context_getter_.get(); 111 : media_context_getter_.get();
112
113 // Caches might not exist in tests.
114 if (!getter) {
115 next_cache_state_ = (next_cache_state_ == CacheState::CREATE_MAIN)
116 ? CacheState::CREATE_MEDIA
117 : CacheState::DONE;
118 break;
119 }
120
114 net::HttpCache* http_cache = getter->GetURLRequestContext() 121 net::HttpCache* http_cache = getter->GetURLRequestContext()
115 ->http_transaction_factory() 122 ->http_transaction_factory()
116 ->GetCache(); 123 ->GetCache();
117 124
118 next_cache_state_ = (next_cache_state_ == CacheState::CREATE_MAIN) 125 next_cache_state_ = (next_cache_state_ == CacheState::CREATE_MAIN)
119 ? CacheState::DELETE_MAIN 126 ? CacheState::DELETE_MAIN
120 : CacheState::DELETE_MEDIA; 127 : CacheState::DELETE_MEDIA;
121 128
122 // Clear QUIC server information from memory and the disk cache. 129 // Clear QUIC server information from memory and the disk cache.
123 http_cache->GetSession() 130 http_cache->GetSession()
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 } 192 }
186 case CacheState::NONE: { 193 case CacheState::NONE: {
187 NOTREACHED() << "bad state"; 194 NOTREACHED() << "bad state";
188 return; 195 return;
189 } 196 }
190 } 197 }
191 } 198 }
192 } 199 }
193 200
194 } // namespace browsing_data 201 } // namespace browsing_data
OLDNEW
« no previous file with comments | « chrome/browser/chrome_content_browser_client_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698