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

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

Issue 2623033003: Always show counters in the material design Clear Browsing Data dialog. (Closed)
Patch Set: iOS fix #2 Created 3 years, 11 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 CacheCounter::CacheResult::CacheResult(const CacheCounter* source, 12 CacheCounter::CacheResult::CacheResult(const CacheCounter* source,
13 int64_t cache_size, 13 int64_t cache_size,
14 bool is_upper_limit) 14 bool is_upper_limit)
15 : FinishedResult(source, cache_size), 15 : FinishedResult(source, cache_size),
16 cache_size_(cache_size), 16 cache_size_(cache_size),
17 is_upper_limit_(is_upper_limit) {} 17 is_upper_limit_(is_upper_limit) {}
18 18
19 CacheCounter::CacheResult::~CacheResult() {} 19 CacheCounter::CacheResult::~CacheResult() {}
20 20
21 CacheCounter::CacheCounter(Profile* profile) 21 CacheCounter::CacheCounter(Profile* profile)
22 : profile_(profile), 22 : profile_(profile),
23 pending_(false),
24 weak_ptr_factory_(this) {} 23 weak_ptr_factory_(this) {}
25 24
26 CacheCounter::~CacheCounter() { 25 CacheCounter::~CacheCounter() {
27 } 26 }
28 27
29 const char* CacheCounter::GetPrefName() const { 28 const char* CacheCounter::GetPrefName() const {
30 return browsing_data::prefs::kDeleteCache; 29 return browsing_data::prefs::kDeleteCache;
31 } 30 }
32 31
33 void CacheCounter::Count() { 32 void CacheCounter::Count() {
34 bool is_upper_limit = !GetPeriodStart().is_null(); 33 bool is_upper_limit = !GetPeriodStart().is_null();
35 base::WeakPtr<browsing_data::ConditionalCacheCountingHelper> counter = 34 base::WeakPtr<browsing_data::ConditionalCacheCountingHelper> counter =
36 browsing_data::ConditionalCacheCountingHelper::CreateForRange( 35 browsing_data::ConditionalCacheCountingHelper::CreateForRange(
37 content::BrowserContext::GetDefaultStoragePartition(profile_), 36 content::BrowserContext::GetDefaultStoragePartition(profile_),
38 base::Time(), base::Time::Max()) 37 base::Time(), base::Time::Max())
39 ->CountAndDestroySelfWhenFinished( 38 ->CountAndDestroySelfWhenFinished(
40 base::Bind(&CacheCounter::OnCacheSizeCalculated, 39 base::Bind(&CacheCounter::OnCacheSizeCalculated,
41 weak_ptr_factory_.GetWeakPtr(), is_upper_limit)); 40 weak_ptr_factory_.GetWeakPtr(), is_upper_limit));
42 pending_ = true;
43 } 41 }
44 42
45 void CacheCounter::OnCacheSizeCalculated(bool is_upper_limit, 43 void CacheCounter::OnCacheSizeCalculated(bool is_upper_limit,
46 int64_t result_bytes) { 44 int64_t result_bytes) {
47 pending_ = false;
48
49 // A value less than 0 means a net error code. 45 // A value less than 0 means a net error code.
50 if (result_bytes < 0) 46 if (result_bytes < 0)
51 return; 47 return;
52 auto result = 48 auto result =
53 base::MakeUnique<CacheResult>(this, result_bytes, is_upper_limit); 49 base::MakeUnique<CacheResult>(this, result_bytes, is_upper_limit);
54 ReportResult(std::move(result)); 50 ReportResult(std::move(result));
55 } 51 }
56
57 bool CacheCounter::Pending() {
58 return pending_;
59 }
OLDNEW
« no previous file with comments | « chrome/browser/browsing_data/cache_counter.h ('k') | chrome/browser/browsing_data/cache_counter_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698