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