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" |
11 | 11 |
12 #if defined(OS_ANDROID) | |
13 #include "chrome/browser/android/offline_pages/offline_page_utils.h" | |
14 #endif // OS_ANDROID | |
15 | |
12 CacheCounter::CacheResult::CacheResult(const CacheCounter* source, | 16 CacheCounter::CacheResult::CacheResult(const CacheCounter* source, |
13 int64_t cache_size, | 17 int64_t cache_size, |
14 bool is_upper_limit) | 18 bool is_upper_limit) |
15 : FinishedResult(source, cache_size), | 19 : FinishedResult(source, cache_size), |
16 cache_size_(cache_size), | 20 cache_size_(cache_size), |
17 is_upper_limit_(is_upper_limit) {} | 21 is_upper_limit_(is_upper_limit) {} |
18 | 22 |
19 CacheCounter::CacheResult::~CacheResult() {} | 23 CacheCounter::CacheResult::~CacheResult() {} |
20 | 24 |
21 CacheCounter::CacheCounter(Profile* profile) | 25 CacheCounter::CacheCounter(Profile* profile) |
(...skipping 14 matching lines...) Expand all Loading... | |
36 weak_ptr_factory_.InvalidateWeakPtrs(); | 40 weak_ptr_factory_.InvalidateWeakPtrs(); |
37 base::WeakPtr<browsing_data::ConditionalCacheCountingHelper> counter = | 41 base::WeakPtr<browsing_data::ConditionalCacheCountingHelper> counter = |
38 browsing_data::ConditionalCacheCountingHelper::CreateForRange( | 42 browsing_data::ConditionalCacheCountingHelper::CreateForRange( |
39 content::BrowserContext::GetDefaultStoragePartition(profile_), | 43 content::BrowserContext::GetDefaultStoragePartition(profile_), |
40 GetPeriodStart(), base::Time::Max()) | 44 GetPeriodStart(), base::Time::Max()) |
41 ->CountAndDestroySelfWhenFinished( | 45 ->CountAndDestroySelfWhenFinished( |
42 base::Bind(&CacheCounter::OnCacheSizeCalculated, | 46 base::Bind(&CacheCounter::OnCacheSizeCalculated, |
43 weak_ptr_factory_.GetWeakPtr())); | 47 weak_ptr_factory_.GetWeakPtr())); |
44 } | 48 } |
45 | 49 |
46 void CacheCounter::OnCacheSizeCalculated(int64_t result_bytes, | 50 void CacheCounter::OnCacheSizeCalculated(int64_t cache_bytes, |
dewittj
2017/05/09 01:29:54
nit: rename to OnBrowsingDataCacheSizeCalculated
romax
2017/05/09 21:08:45
Done.
| |
47 bool is_upper_limit) { | 51 bool is_upper_limit) { |
48 // A value less than 0 means a net error code. | 52 // A value less than 0 means a net error code. |
49 if (result_bytes < 0) | 53 if (cache_bytes < 0) |
50 return; | 54 return; |
dewittj
2017/05/09 01:29:53
It's not clear that we should return here anymore.
romax
2017/05/09 21:08:45
if this value is <0, it means there was an error d
| |
55 | |
56 #if defined(OS_ANDROID) | |
57 if (offline_pages::OfflinePageUtils::GetCachedOfflinePageSizeBetween( | |
dullweber
2017/05/09 07:56:01
Could you start both cache calculations in paralle
romax
2017/05/09 21:08:45
Done.
But in order to reuse the callback I changed
| |
58 profile_, | |
59 base::Bind(&CacheCounter::OnOfflinePageSizeCalculated, | |
60 weak_ptr_factory_.GetWeakPtr(), cache_bytes, | |
61 is_upper_limit), | |
62 GetPeriodStart(), base::Time::Max())) { | |
63 return; | |
64 } | |
65 #endif // OS_ANDROID | |
51 auto result = | 66 auto result = |
52 base::MakeUnique<CacheResult>(this, result_bytes, is_upper_limit); | 67 base::MakeUnique<CacheResult>(this, cache_bytes, is_upper_limit); |
53 ReportResult(std::move(result)); | 68 ReportResult(std::move(result)); |
54 } | 69 } |
70 | |
71 #if defined(OS_ANDROID) | |
dewittj
2017/05/09 01:29:53
I'd not make this android-only, and just call it w
romax
2017/05/09 21:08:45
Done.
| |
72 void CacheCounter::OnOfflinePageSizeCalculated( | |
73 int64_t cache_bytes, | |
dewittj
2017/05/09 01:29:53
rename to cached_browsing_data_bytes
romax
2017/05/09 21:08:45
Done.
| |
74 bool is_upper_limit, | |
dewittj
2017/05/09 01:29:54
do we need to compute the upper limit? Why is thi
romax
2017/05/09 21:08:45
we don't need to compute it (or it can be always f
| |
75 int64_t cached_offline_page_bytes) { | |
76 auto result = base::MakeUnique<CacheResult>( | |
77 this, cached_offline_page_bytes + cache_bytes, is_upper_limit); | |
78 ReportResult(std::move(result)); | |
79 } | |
80 #endif // OS_ANDROID | |
OLD | NEW |