Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: chrome/browser/browsing_data/cache_counter.cc

Issue 2860573004: [Offline Pages] Add cached offline page utils and show usage in settings. (Closed)
Patch Set: fixed unit tests but CBD tests flaky. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 12 matching lines...) Expand all
34 void CacheCounter::Count() { 38 void CacheCounter::Count() {
35 base::WeakPtr<browsing_data::ConditionalCacheCountingHelper> counter = 39 base::WeakPtr<browsing_data::ConditionalCacheCountingHelper> counter =
36 browsing_data::ConditionalCacheCountingHelper::CreateForRange( 40 browsing_data::ConditionalCacheCountingHelper::CreateForRange(
37 content::BrowserContext::GetDefaultStoragePartition(profile_), 41 content::BrowserContext::GetDefaultStoragePartition(profile_),
38 GetPeriodStart(), base::Time::Max()) 42 GetPeriodStart(), base::Time::Max())
39 ->CountAndDestroySelfWhenFinished( 43 ->CountAndDestroySelfWhenFinished(
40 base::Bind(&CacheCounter::OnCacheSizeCalculated, 44 base::Bind(&CacheCounter::OnCacheSizeCalculated,
41 weak_ptr_factory_.GetWeakPtr())); 45 weak_ptr_factory_.GetWeakPtr()));
42 } 46 }
43 47
44 void CacheCounter::OnCacheSizeCalculated(int64_t result_bytes, 48 void CacheCounter::OnCacheSizeCalculated(int64_t cache_bytes,
45 bool is_upper_limit) { 49 bool is_upper_limit) {
46 // A value less than 0 means a net error code. 50 // A value less than 0 means a net error code.
47 if (result_bytes < 0) 51 if (cache_bytes < 0)
48 return; 52 return;
53
54 #if defined(OS_ANDROID)
55 if (offline_pages::OfflinePageUtils::GetCachedOfflinePageSizeBetween(
56 profile_,
57 base::Bind(&CacheCounter::OnOfflinePageSizeCalculated,
58 weak_ptr_factory_.GetWeakPtr(), cache_bytes,
59 is_upper_limit),
60 GetPeriodStart(), base::Time::Max())) {
61 return;
62 }
63 #endif // OS_ANDROID
49 auto result = 64 auto result =
50 base::MakeUnique<CacheResult>(this, result_bytes, is_upper_limit); 65 base::MakeUnique<CacheResult>(this, cache_bytes, is_upper_limit);
51 ReportResult(std::move(result)); 66 ReportResult(std::move(result));
52 } 67 }
68
69 #if defined(OS_ANDROID)
70 void CacheCounter::OnOfflinePageSizeCalculated(
71 int64_t cache_bytes,
72 bool is_upper_limit,
73 int64_t cached_offline_page_bytes) {
74 auto result = base::MakeUnique<CacheResult>(
75 this, cached_offline_page_bytes + cache_bytes, is_upper_limit);
76 ReportResult(std::move(result));
77 }
78 #endif // OS_ANDROID
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698