| 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 14 matching lines...) Expand all Loading... |
| 25 CacheCounter::~CacheCounter() { | 25 CacheCounter::~CacheCounter() { |
| 26 } | 26 } |
| 27 | 27 |
| 28 const char* CacheCounter::GetPrefName() const { | 28 const char* CacheCounter::GetPrefName() const { |
| 29 return GetTab() == browsing_data::ClearBrowsingDataTab::BASIC | 29 return GetTab() == browsing_data::ClearBrowsingDataTab::BASIC |
| 30 ? browsing_data::prefs::kDeleteCacheBasic | 30 ? browsing_data::prefs::kDeleteCacheBasic |
| 31 : browsing_data::prefs::kDeleteCache; | 31 : browsing_data::prefs::kDeleteCache; |
| 32 } | 32 } |
| 33 | 33 |
| 34 void CacheCounter::Count() { | 34 void CacheCounter::Count() { |
| 35 // Cancel existing requests. |
| 36 weak_ptr_factory_.InvalidateWeakPtrs(); |
| 35 base::WeakPtr<browsing_data::ConditionalCacheCountingHelper> counter = | 37 base::WeakPtr<browsing_data::ConditionalCacheCountingHelper> counter = |
| 36 browsing_data::ConditionalCacheCountingHelper::CreateForRange( | 38 browsing_data::ConditionalCacheCountingHelper::CreateForRange( |
| 37 content::BrowserContext::GetDefaultStoragePartition(profile_), | 39 content::BrowserContext::GetDefaultStoragePartition(profile_), |
| 38 GetPeriodStart(), base::Time::Max()) | 40 GetPeriodStart(), base::Time::Max()) |
| 39 ->CountAndDestroySelfWhenFinished( | 41 ->CountAndDestroySelfWhenFinished( |
| 40 base::Bind(&CacheCounter::OnCacheSizeCalculated, | 42 base::Bind(&CacheCounter::OnCacheSizeCalculated, |
| 41 weak_ptr_factory_.GetWeakPtr())); | 43 weak_ptr_factory_.GetWeakPtr())); |
| 42 } | 44 } |
| 43 | 45 |
| 44 void CacheCounter::OnCacheSizeCalculated(int64_t result_bytes, | 46 void CacheCounter::OnCacheSizeCalculated(int64_t result_bytes, |
| 45 bool is_upper_limit) { | 47 bool is_upper_limit) { |
| 46 // A value less than 0 means a net error code. | 48 // A value less than 0 means a net error code. |
| 47 if (result_bytes < 0) | 49 if (result_bytes < 0) |
| 48 return; | 50 return; |
| 49 auto result = | 51 auto result = |
| 50 base::MakeUnique<CacheResult>(this, result_bytes, is_upper_limit); | 52 base::MakeUnique<CacheResult>(this, result_bytes, is_upper_limit); |
| 51 ReportResult(std::move(result)); | 53 ReportResult(std::move(result)); |
| 52 } | 54 } |
| OLD | NEW |