OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "chrome/browser/browsing_data/cache_counter.h" | 5 #include "chrome/browser/browsing_data/cache_counter.h" |
6 #include "chrome/browser/profiles/profile.h" | 6 #include "chrome/browser/profiles/profile.h" |
7 #include "components/browsing_data/content/storage_partition_http_cache_data_rem
over.h" | 7 #include "components/browsing_data/content/conditional_cache_counting_helper.h" |
8 #include "components/browsing_data/core/pref_names.h" | 8 #include "components/browsing_data/core/pref_names.h" |
| 9 #include "content/public/browser/browser_thread.h" |
9 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
10 | 11 |
| 12 CacheCounter::CacheResult::CacheResult(const CacheCounter* source, |
| 13 int64_t cache_size, |
| 14 bool is_upper_limit) |
| 15 : FinishedResult(source, cache_size), |
| 16 cache_size_(cache_size), |
| 17 is_upper_limit_(is_upper_limit) {} |
| 18 |
| 19 CacheCounter::CacheResult::~CacheResult() {} |
| 20 |
11 CacheCounter::CacheCounter(Profile* profile) | 21 CacheCounter::CacheCounter(Profile* profile) |
12 : profile_(profile), | 22 : profile_(profile), |
13 pending_(false), | 23 pending_(false), |
14 weak_ptr_factory_(this) {} | 24 weak_ptr_factory_(this) {} |
15 | 25 |
16 CacheCounter::~CacheCounter() { | 26 CacheCounter::~CacheCounter() { |
17 } | 27 } |
18 | 28 |
19 const char* CacheCounter::GetPrefName() const { | 29 const char* CacheCounter::GetPrefName() const { |
20 return browsing_data::prefs::kDeleteCache; | 30 return browsing_data::prefs::kDeleteCache; |
21 } | 31 } |
22 | 32 |
23 void CacheCounter::Count() { | 33 void CacheCounter::Count() { |
24 // TODO(msramek): StoragePartitionHttpCacheDataRemover currently does not | 34 bool is_upper_limit = !GetPeriodStart().is_null(); |
25 // implement counting for subsets of cache, only for the entire cache. Thus, | 35 base::WeakPtr<browsing_data::ConditionalCacheCountingHelper> counter = |
26 // we ignore the time period setting and always request counting for | 36 browsing_data::ConditionalCacheCountingHelper::CreateForRange( |
27 // the unbounded time interval. It is up to the UI to interpret the results | 37 content::BrowserContext::GetDefaultStoragePartition(profile_), |
28 // for finite time intervals as upper estimates. | 38 base::Time(), base::Time::Max()) |
29 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange( | 39 ->CountAndDestroySelfWhenFinished( |
30 content::BrowserContext::GetDefaultStoragePartition(profile_), | 40 base::Bind(&CacheCounter::OnCacheSizeCalculated, |
31 base::Time(), base::Time::Max()) | 41 weak_ptr_factory_.GetWeakPtr(), is_upper_limit)); |
32 ->Count(base::Bind(&CacheCounter::OnCacheSizeCalculated, | |
33 weak_ptr_factory_.GetWeakPtr())); | |
34 pending_ = true; | 42 pending_ = true; |
35 } | 43 } |
36 | 44 |
37 void CacheCounter::OnCacheSizeCalculated(int64_t result_bytes) { | 45 void CacheCounter::OnCacheSizeCalculated(bool is_upper_limit, |
| 46 int64_t result_bytes) { |
38 pending_ = false; | 47 pending_ = false; |
39 | 48 |
40 // A value less than 0 means a net error code. | 49 // A value less than 0 means a net error code. |
41 if (result_bytes < 0) | 50 if (result_bytes < 0) |
42 return; | 51 return; |
43 | 52 auto result = |
44 ReportResult(result_bytes); | 53 base::MakeUnique<CacheResult>(this, result_bytes, is_upper_limit); |
| 54 ReportResult(std::move(result)); |
45 } | 55 } |
46 | 56 |
47 bool CacheCounter::Pending() { | 57 bool CacheCounter::Pending() { |
48 return pending_; | 58 return pending_; |
49 } | 59 } |
OLD | NEW |