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

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: 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_model_factory.h"
14 #include "components/offline_pages/core/cached_offline_page_utils.h"
15 #endif // OS_ANDROID
16
12 CacheCounter::CacheResult::CacheResult(const CacheCounter* source, 17 CacheCounter::CacheResult::CacheResult(const CacheCounter* source,
13 int64_t cache_size, 18 int64_t cache_size,
14 bool is_upper_limit) 19 bool is_upper_limit)
15 : FinishedResult(source, cache_size), 20 : FinishedResult(source, cache_size),
16 cache_size_(cache_size), 21 cache_size_(cache_size),
17 is_upper_limit_(is_upper_limit) {} 22 is_upper_limit_(is_upper_limit) {}
18 23
19 CacheCounter::CacheResult::~CacheResult() {} 24 CacheCounter::CacheResult::~CacheResult() {}
20 25
21 CacheCounter::CacheCounter(Profile* profile) 26 CacheCounter::CacheCounter(Profile* profile)
(...skipping 12 matching lines...) Expand all
34 void CacheCounter::Count() { 39 void CacheCounter::Count() {
35 base::WeakPtr<browsing_data::ConditionalCacheCountingHelper> counter = 40 base::WeakPtr<browsing_data::ConditionalCacheCountingHelper> counter =
36 browsing_data::ConditionalCacheCountingHelper::CreateForRange( 41 browsing_data::ConditionalCacheCountingHelper::CreateForRange(
37 content::BrowserContext::GetDefaultStoragePartition(profile_), 42 content::BrowserContext::GetDefaultStoragePartition(profile_),
38 GetPeriodStart(), base::Time::Max()) 43 GetPeriodStart(), base::Time::Max())
39 ->CountAndDestroySelfWhenFinished( 44 ->CountAndDestroySelfWhenFinished(
40 base::Bind(&CacheCounter::OnCacheSizeCalculated, 45 base::Bind(&CacheCounter::OnCacheSizeCalculated,
41 weak_ptr_factory_.GetWeakPtr())); 46 weak_ptr_factory_.GetWeakPtr()));
42 } 47 }
43 48
44 void CacheCounter::OnCacheSizeCalculated(int64_t result_bytes, 49 void CacheCounter::OnCacheSizeCalculated(int64_t cache_bytes,
45 bool is_upper_limit) { 50 bool is_upper_limit) {
46 // A value less than 0 means a net error code. 51 // A value less than 0 means a net error code.
47 if (result_bytes < 0) 52 if (cache_bytes < 0)
48 return; 53 return;
54
55 #if defined(OS_ANDROID)
56 offline_pages::OfflinePageModel* offline_page_model =
57 offline_pages::OfflinePageModelFactory::GetForBrowserContext(profile_);
58 if (offline_page_model) {
59 offline_pages::CachedOfflinePageUtils::GetCachedOfflinePageSizeBetween(
60 offline_page_model,
61 base::Bind(&CacheCounter::OnOfflinePageSizeCalculated,
62 weak_ptr_factory_.GetWeakPtr(), cache_bytes, is_upper_limit),
63 GetPeriodStart(), base::Time::Max());
64 return;
65 }
66 #endif // OS_ANDROID
49 auto result = 67 auto result =
50 base::MakeUnique<CacheResult>(this, result_bytes, is_upper_limit); 68 base::MakeUnique<CacheResult>(this, cache_bytes, is_upper_limit);
51 ReportResult(std::move(result)); 69 ReportResult(std::move(result));
52 } 70 }
71
72 #if defined(OS_ANDROID)
73 void CacheCounter::OnOfflinePageSizeCalculated(
74 int64_t cache_bytes,
75 bool is_upper_limit,
76 int64_t cached_offline_page_bytes) {
77 auto result = base::MakeUnique<CacheResult>(
78 this, offline_page_cache_bytes + cache_bytes, is_upper_limit);
79 ReportResult(std::move(result));
80 }
81 #endif // OS_ANDROID
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698