| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/browsing_data/core/counters/browsing_data_counter.h" | 5 #include "components/browsing_data/core/counters/browsing_data_counter.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "components/browsing_data/core/browsing_data_utils.h" | 10 #include "components/browsing_data/core/browsing_data_utils.h" |
| 11 #include "components/browsing_data/core/pref_names.h" | 11 #include "components/browsing_data/core/pref_names.h" |
| 12 #include "components/prefs/pref_service.h" | 12 #include "components/prefs/pref_service.h" |
| 13 | 13 |
| 14 namespace browsing_data { | 14 namespace browsing_data { |
| 15 | 15 |
| 16 BrowsingDataCounter::BrowsingDataCounter(const std::string& pref_name) | 16 BrowsingDataCounter::BrowsingDataCounter() {} |
| 17 : pref_name_(pref_name) {} | |
| 18 | 17 |
| 19 BrowsingDataCounter::~BrowsingDataCounter() {} | 18 BrowsingDataCounter::~BrowsingDataCounter() {} |
| 20 | 19 |
| 21 void BrowsingDataCounter::Init(PrefService* pref_service, | 20 void BrowsingDataCounter::Init(PrefService* pref_service, |
| 22 const Callback& callback) { | 21 const Callback& callback) { |
| 23 DCHECK(!initialized_); | 22 DCHECK(!initialized_); |
| 24 callback_ = callback; | 23 callback_ = callback; |
| 25 pref_service_ = pref_service; | 24 pref_service_ = pref_service; |
| 26 pref_.Init(GetPrefName(), pref_service_, | 25 pref_.Init(GetPrefName(), pref_service_, |
| 27 base::Bind(&BrowsingDataCounter::Restart, base::Unretained(this))); | 26 base::Bind(&BrowsingDataCounter::Restart, base::Unretained(this))); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 54 void BrowsingDataCounter::ReportResult(ResultInt value) { | 53 void BrowsingDataCounter::ReportResult(ResultInt value) { |
| 55 DCHECK(initialized_); | 54 DCHECK(initialized_); |
| 56 callback_.Run(base::WrapUnique(new FinishedResult(this, value))); | 55 callback_.Run(base::WrapUnique(new FinishedResult(this, value))); |
| 57 } | 56 } |
| 58 | 57 |
| 59 void BrowsingDataCounter::ReportResult(std::unique_ptr<Result> result) { | 58 void BrowsingDataCounter::ReportResult(std::unique_ptr<Result> result) { |
| 60 DCHECK(initialized_); | 59 DCHECK(initialized_); |
| 61 callback_.Run(std::move(result)); | 60 callback_.Run(std::move(result)); |
| 62 } | 61 } |
| 63 | 62 |
| 64 const std::string& BrowsingDataCounter::GetPrefName() const { | |
| 65 return pref_name_; | |
| 66 } | |
| 67 | |
| 68 PrefService* BrowsingDataCounter::GetPrefs() const { | 63 PrefService* BrowsingDataCounter::GetPrefs() const { |
| 69 return pref_service_; | 64 return pref_service_; |
| 70 } | 65 } |
| 71 | 66 |
| 72 // BrowsingDataCounter::Result ------------------------------------------------- | 67 // BrowsingDataCounter::Result ------------------------------------------------- |
| 73 | 68 |
| 74 BrowsingDataCounter::Result::Result(const BrowsingDataCounter* source) | 69 BrowsingDataCounter::Result::Result(const BrowsingDataCounter* source) |
| 75 : source_(source) {} | 70 : source_(source) {} |
| 76 | 71 |
| 77 BrowsingDataCounter::Result::~Result() {} | 72 BrowsingDataCounter::Result::~Result() {} |
| (...skipping 14 matching lines...) Expand all Loading... |
| 92 bool BrowsingDataCounter::FinishedResult::Finished() const { | 87 bool BrowsingDataCounter::FinishedResult::Finished() const { |
| 93 return true; | 88 return true; |
| 94 } | 89 } |
| 95 | 90 |
| 96 BrowsingDataCounter::ResultInt BrowsingDataCounter::FinishedResult::Value() | 91 BrowsingDataCounter::ResultInt BrowsingDataCounter::FinishedResult::Value() |
| 97 const { | 92 const { |
| 98 return value_; | 93 return value_; |
| 99 } | 94 } |
| 100 | 95 |
| 101 } // namespace browsing_data | 96 } // namespace browsing_data |
| OLD | NEW |