| 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/conditional_cache_counting_helper.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 "content/public/browser/browser_thread.h" |
| 10 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 weak_ptr_factory_(this) {} | 23 weak_ptr_factory_(this) {} |
| 24 | 24 |
| 25 CacheCounter::~CacheCounter() { | 25 CacheCounter::~CacheCounter() { |
| 26 } | 26 } |
| 27 | 27 |
| 28 const char* CacheCounter::GetPrefName() const { | 28 const char* CacheCounter::GetPrefName() const { |
| 29 return browsing_data::prefs::kDeleteCache; | 29 return browsing_data::prefs::kDeleteCache; |
| 30 } | 30 } |
| 31 | 31 |
| 32 void CacheCounter::Count() { | 32 void CacheCounter::Count() { |
| 33 bool is_upper_limit = !GetPeriodStart().is_null(); | |
| 34 base::WeakPtr<browsing_data::ConditionalCacheCountingHelper> counter = | 33 base::WeakPtr<browsing_data::ConditionalCacheCountingHelper> counter = |
| 35 browsing_data::ConditionalCacheCountingHelper::CreateForRange( | 34 browsing_data::ConditionalCacheCountingHelper::CreateForRange( |
| 36 content::BrowserContext::GetDefaultStoragePartition(profile_), | 35 content::BrowserContext::GetDefaultStoragePartition(profile_), |
| 37 base::Time(), base::Time::Max()) | 36 GetPeriodStart(), base::Time::Max()) |
| 38 ->CountAndDestroySelfWhenFinished( | 37 ->CountAndDestroySelfWhenFinished( |
| 39 base::Bind(&CacheCounter::OnCacheSizeCalculated, | 38 base::Bind(&CacheCounter::OnCacheSizeCalculated, |
| 40 weak_ptr_factory_.GetWeakPtr(), is_upper_limit)); | 39 weak_ptr_factory_.GetWeakPtr())); |
| 41 } | 40 } |
| 42 | 41 |
| 43 void CacheCounter::OnCacheSizeCalculated(bool is_upper_limit, | 42 void CacheCounter::OnCacheSizeCalculated(int64_t result_bytes, |
| 44 int64_t result_bytes) { | 43 bool is_upper_limit) { |
| 45 // A value less than 0 means a net error code. | 44 // A value less than 0 means a net error code. |
| 46 if (result_bytes < 0) | 45 if (result_bytes < 0) |
| 47 return; | 46 return; |
| 48 auto result = | 47 auto result = |
| 49 base::MakeUnique<CacheResult>(this, result_bytes, is_upper_limit); | 48 base::MakeUnique<CacheResult>(this, result_bytes, is_upper_limit); |
| 50 ReportResult(std::move(result)); | 49 ReportResult(std::move(result)); |
| 51 } | 50 } |
| OLD | NEW |