[sql] Remove _HAS_EXCEPTIONS=0 from build info.
[chromium-blink-merge.git] / chrome / browser / browsing_data / browsing_data_counter.cc
blob07700a9864784137b4bf5aac6afb3e2b1a50c413
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
3 // found in the LICENSE file.
5 #include "chrome/browser/browsing_data/browsing_data_counter.h"
7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/profiles/profile.h"
10 BrowsingDataCounter::BrowsingDataCounter()
11 : counting_(false),
12 initialized_(false) {
15 BrowsingDataCounter::~BrowsingDataCounter() {
18 void BrowsingDataCounter::Init(
19 Profile* profile,
20 const Callback& callback) {
21 DCHECK(!initialized_);
22 profile_ = profile;
23 callback_ = callback;
24 pref_.Init(
25 GetPrefName(),
26 profile_->GetPrefs(),
27 base::Bind(&BrowsingDataCounter::OnPrefChanged,
28 base::Unretained(this)));
30 initialized_ = true;
31 OnPrefChanged();
34 void BrowsingDataCounter::OnPrefChanged() {
35 DCHECK(initialized_);
37 // If this data type was unchecked for deletion, we do not need to count it.
38 if (!profile_->GetPrefs()->GetBoolean(GetPrefName()))
39 return;
41 // If counting is already in progress, do not restart it.
42 if (counting_)
43 return;
45 callback_.Run(false, 0u);
47 counting_ = true;
48 Count();
51 // virtual
52 void BrowsingDataCounter::Count() {
55 void BrowsingDataCounter::ReportResult(uint32 value) {
56 DCHECK(initialized_);
57 DCHECK(counting_);
58 counting_ = false;
59 callback_.Run(true, value);