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/storage_partition_http_cache_data_rem
over.h" |
8 #include "components/browsing_data/core/pref_names.h" | 8 #include "components/browsing_data/core/pref_names.h" |
9 #include "net/base/net_errors.h" | 9 #include "net/base/net_errors.h" |
10 | 10 |
11 CacheCounter::CacheCounter(Profile* profile) | 11 CacheCounter::CacheCounter(Profile* profile) |
12 : BrowsingDataCounter(browsing_data::prefs::kDeleteCache), | 12 : profile_(profile), |
13 profile_(profile), | |
14 pending_(false), | 13 pending_(false), |
15 weak_ptr_factory_(this) {} | 14 weak_ptr_factory_(this) {} |
16 | 15 |
17 CacheCounter::~CacheCounter() { | 16 CacheCounter::~CacheCounter() { |
18 } | 17 } |
19 | 18 |
| 19 const char* CacheCounter::GetPrefName() const { |
| 20 return browsing_data::prefs::kDeleteCache; |
| 21 } |
| 22 |
20 void CacheCounter::Count() { | 23 void CacheCounter::Count() { |
21 // TODO(msramek): StoragePartitionHttpCacheDataRemover currently does not | 24 // TODO(msramek): StoragePartitionHttpCacheDataRemover currently does not |
22 // implement counting for subsets of cache, only for the entire cache. Thus, | 25 // implement counting for subsets of cache, only for the entire cache. Thus, |
23 // we ignore the time period setting and always request counting for | 26 // we ignore the time period setting and always request counting for |
24 // the unbounded time interval. It is up to the UI to interpret the results | 27 // the unbounded time interval. It is up to the UI to interpret the results |
25 // for finite time intervals as upper estimates. | 28 // for finite time intervals as upper estimates. |
26 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange( | 29 browsing_data::StoragePartitionHttpCacheDataRemover::CreateForRange( |
27 content::BrowserContext::GetDefaultStoragePartition(profile_), | 30 content::BrowserContext::GetDefaultStoragePartition(profile_), |
28 base::Time(), base::Time::Max()) | 31 base::Time(), base::Time::Max()) |
29 ->Count(base::Bind(&CacheCounter::OnCacheSizeCalculated, | 32 ->Count(base::Bind(&CacheCounter::OnCacheSizeCalculated, |
30 weak_ptr_factory_.GetWeakPtr())); | 33 weak_ptr_factory_.GetWeakPtr())); |
31 pending_ = true; | 34 pending_ = true; |
32 } | 35 } |
33 | 36 |
34 void CacheCounter::OnCacheSizeCalculated(int64_t result_bytes) { | 37 void CacheCounter::OnCacheSizeCalculated(int64_t result_bytes) { |
35 pending_ = false; | 38 pending_ = false; |
36 | 39 |
37 // A value less than 0 means a net error code. | 40 // A value less than 0 means a net error code. |
38 if (result_bytes < 0) | 41 if (result_bytes < 0) |
39 return; | 42 return; |
40 | 43 |
41 ReportResult(result_bytes); | 44 ReportResult(result_bytes); |
42 } | 45 } |
43 | 46 |
44 bool CacheCounter::Pending() { | 47 bool CacheCounter::Pending() { |
45 return pending_; | 48 return pending_; |
46 } | 49 } |
OLD | NEW |