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

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

Issue 2626223002: Show the exact cache size for time ranges if supported (Closed)
Patch Set: fix chromeos build Created 3 years, 11 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/conditional_cache_counting_helper.h" 5 #include "components/browsing_data/content/conditional_cache_counting_helper.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.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 "content/public/browser/browser_thread.h" 10 #include "content/public/browser/browser_thread.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 DCHECK_CURRENTLY_ON(BrowserThread::UI); 50 DCHECK_CURRENTLY_ON(BrowserThread::UI);
51 } 51 }
52 52
53 base::WeakPtr<ConditionalCacheCountingHelper> 53 base::WeakPtr<ConditionalCacheCountingHelper>
54 ConditionalCacheCountingHelper::CountAndDestroySelfWhenFinished( 54 ConditionalCacheCountingHelper::CountAndDestroySelfWhenFinished(
55 const CacheCountCallback& result_callback) { 55 const CacheCountCallback& result_callback) {
56 DCHECK_CURRENTLY_ON(BrowserThread::UI); 56 DCHECK_CURRENTLY_ON(BrowserThread::UI);
57 DCHECK(!result_callback.is_null()); 57 DCHECK(!result_callback.is_null());
58 result_callback_ = result_callback; 58 result_callback_ = result_callback;
59 calculation_result_ = 0; 59 calculation_result_ = 0;
60 is_upper_limit_ = false;
60 61
61 BrowserThread::PostTask( 62 BrowserThread::PostTask(
62 BrowserThread::IO, FROM_HERE, 63 BrowserThread::IO, FROM_HERE,
63 base::Bind(&ConditionalCacheCountingHelper::CountHttpCacheOnIOThread, 64 base::Bind(&ConditionalCacheCountingHelper::CountHttpCacheOnIOThread,
64 base::Unretained(this))); 65 base::Unretained(this)));
65 return weak_ptr_factory_.GetWeakPtr(); 66 return weak_ptr_factory_.GetWeakPtr();
66 } 67 }
67 68
68 bool ConditionalCacheCountingHelper::IsFinished() { 69 bool ConditionalCacheCountingHelper::IsFinished() {
69 return is_finished_; 70 return is_finished_;
70 } 71 }
71 72
72 void ConditionalCacheCountingHelper::Finished() { 73 void ConditionalCacheCountingHelper::Finished() {
73 DCHECK_CURRENTLY_ON(BrowserThread::UI); 74 DCHECK_CURRENTLY_ON(BrowserThread::UI);
74 DCHECK(!is_finished_); 75 DCHECK(!is_finished_);
75 is_finished_ = true; 76 is_finished_ = true;
76 result_callback_.Run(calculation_result_); 77 result_callback_.Run(calculation_result_, is_upper_limit_);
77 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this); 78 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, this);
78 } 79 }
79 80
80 void ConditionalCacheCountingHelper::CountHttpCacheOnIOThread() { 81 void ConditionalCacheCountingHelper::CountHttpCacheOnIOThread() {
81 DCHECK_CURRENTLY_ON(BrowserThread::IO); 82 DCHECK_CURRENTLY_ON(BrowserThread::IO);
82 next_cache_state_ = CacheState::NONE; 83 next_cache_state_ = CacheState::NONE;
83 DCHECK_EQ(CacheState::NONE, next_cache_state_); 84 DCHECK_EQ(CacheState::NONE, next_cache_state_);
84 DCHECK(main_context_getter_.get()); 85 DCHECK(main_context_getter_.get());
85 DCHECK(media_context_getter_.get()); 86 DCHECK(media_context_getter_.get());
86 87
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 ? CacheState::CREATE_MEDIA 135 ? CacheState::CREATE_MEDIA
135 : CacheState::DONE; 136 : CacheState::DONE;
136 137
137 // |cache_| can be null if it cannot be initialized. 138 // |cache_| can be null if it cannot be initialized.
138 if (cache_) { 139 if (cache_) {
139 if (begin_time_.is_null() && end_time_.is_max()) { 140 if (begin_time_.is_null() && end_time_.is_max()) {
140 rv = cache_->CalculateSizeOfAllEntries( 141 rv = cache_->CalculateSizeOfAllEntries(
141 base::Bind(&ConditionalCacheCountingHelper::DoCountCache, 142 base::Bind(&ConditionalCacheCountingHelper::DoCountCache,
142 base::Unretained(this))); 143 base::Unretained(this)));
143 } else { 144 } else {
144 // TODO(dullweber): Readd code for counting with timeout. 145 rv = cache_->CalculateSizeOfEntriesBetween(
msramek 2017/01/12 14:44:07 This is based on top of 2626173003, right? Please
dullweber 2017/01/12 15:03:42 Done.
145 // TODO(dullweber): Implement faster counting for SimpleBackendImpl. 146 begin_time_, end_time_,
146 rv = cache_->CalculateSizeOfAllEntries(
147 base::Bind(&ConditionalCacheCountingHelper::DoCountCache, 147 base::Bind(&ConditionalCacheCountingHelper::DoCountCache,
148 base::Unretained(this))); 148 base::Unretained(this)));
149 if (rv == net::ERR_NOT_IMPLEMENTED) {
150 is_upper_limit_ = true;
151 rv = cache_->CalculateSizeOfAllEntries(
152 base::Bind(&ConditionalCacheCountingHelper::DoCountCache,
153 base::Unretained(this)));
154 }
149 } 155 }
150 cache_ = NULL; 156 cache_ = NULL;
151 } 157 }
152 break; 158 break;
153 } 159 }
154 case CacheState::DONE: { 160 case CacheState::DONE: {
155 cache_ = NULL; 161 cache_ = NULL;
156 next_cache_state_ = CacheState::NONE; 162 next_cache_state_ = CacheState::NONE;
157 // Notify the UI thread that we are done. 163 // Notify the UI thread that we are done.
158 BrowserThread::PostTask( 164 BrowserThread::PostTask(
159 BrowserThread::UI, FROM_HERE, 165 BrowserThread::UI, FROM_HERE,
160 base::Bind(&ConditionalCacheCountingHelper::Finished, 166 base::Bind(&ConditionalCacheCountingHelper::Finished,
161 base::Unretained(this))); 167 base::Unretained(this)));
162 return; 168 return;
163 } 169 }
164 case CacheState::NONE: { 170 case CacheState::NONE: {
165 NOTREACHED() << "bad state"; 171 NOTREACHED() << "bad state";
166 return; 172 return;
167 } 173 }
168 } 174 }
169 } 175 }
170 } 176 }
171 177
172 } // namespace browsing_data 178 } // namespace browsing_data
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698