Chromium Code Reviews| Index: components/browsing_data/core/counters/autofill_counter.cc |
| diff --git a/chrome/browser/browsing_data/autofill_counter.cc b/components/browsing_data/core/counters/autofill_counter.cc |
| similarity index 74% |
| rename from chrome/browser/browsing_data/autofill_counter.cc |
| rename to components/browsing_data/core/counters/autofill_counter.cc |
| index 4da1de3ea18a536596afb637f3daf2efaa71815e..4874fa00adbdd0c22e02ac1f753871e64e67e98c 100644 |
| --- a/chrome/browser/browsing_data/autofill_counter.cc |
| +++ b/components/browsing_data/core/counters/autofill_counter.cc |
| @@ -2,24 +2,24 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "chrome/browser/browsing_data/autofill_counter.h" |
| +#include "components/browsing_data/core/counters/autofill_counter.h" |
| #include <algorithm> |
| #include <utility> |
| #include <vector> |
| #include "base/memory/scoped_vector.h" |
| -#include "chrome/browser/profiles/profile.h" |
| -#include "chrome/browser/web_data_service_factory.h" |
| #include "components/autofill/core/browser/autofill_profile.h" |
| #include "components/autofill/core/browser/credit_card.h" |
| #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
| #include "components/browsing_data/core/pref_names.h" |
| -AutofillCounter::AutofillCounter(Profile* profile) |
| - : BrowsingDataCounter(browsing_data::prefs::kDeleteFormData), |
| - profile_(profile), |
| - web_data_service_(nullptr), |
| +namespace browsing_data { |
| + |
| +AutofillCounter::AutofillCounter( |
| + scoped_refptr<autofill::AutofillWebDataService> web_data_service) |
| + : pref_name_(browsing_data::prefs::kDeleteFormData), |
| + web_data_service_(web_data_service), |
| suggestions_query_(0), |
| credit_cards_query_(0), |
| addresses_query_(0), |
| @@ -32,11 +32,13 @@ AutofillCounter::~AutofillCounter() { |
| } |
| void AutofillCounter::OnInitialized() { |
| - web_data_service_ = WebDataServiceFactory::GetAutofillWebDataForProfile( |
| - profile_, ServiceAccessType::EXPLICIT_ACCESS); |
| DCHECK(web_data_service_); |
| } |
| +const std::string& AutofillCounter::GetPrefName() const { |
| + return pref_name_; |
|
msramek
2016/07/20 13:41:16
|pref_name_| is now only used in this method, so w
ioanap
2016/07/20 17:50:36
True. Changed it to return the pref name directly
|
| +} |
| + |
| void AutofillCounter::SetPeriodStartForTesting( |
| const base::Time& period_start_for_testing) { |
| period_start_for_testing_ = period_start_for_testing; |
| @@ -44,8 +46,8 @@ void AutofillCounter::SetPeriodStartForTesting( |
| void AutofillCounter::Count() { |
| const base::Time start = period_start_for_testing_.is_null() |
| - ? GetPeriodStart() |
| - : period_start_for_testing_; |
| + ? GetPeriodStart() |
| + : period_start_for_testing_; |
| CancelAllRequests(); |
| @@ -78,7 +80,8 @@ void AutofillCounter::Count() { |
| } |
| void AutofillCounter::OnWebDataServiceRequestDone( |
| - WebDataServiceBase::Handle handle, const WDTypedResult* result) { |
| + WebDataServiceBase::Handle handle, |
| + const WDTypedResult* result) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| if (!result) { |
| CancelAllRequests(); |
| @@ -86,8 +89,8 @@ void AutofillCounter::OnWebDataServiceRequestDone( |
| } |
| const base::Time start = period_start_for_testing_.is_null() |
| - ? GetPeriodStart() |
| - : period_start_for_testing_; |
| + ? GetPeriodStart() |
| + : period_start_for_testing_; |
| if (handle == suggestions_query_) { |
| // Autocomplete suggestions. |
| @@ -99,19 +102,18 @@ void AutofillCounter::OnWebDataServiceRequestDone( |
| // Credit cards. |
| DCHECK_EQ(AUTOFILL_CREDITCARDS_RESULT, result->GetType()); |
| const std::vector<autofill::CreditCard*> credit_cards = |
| - static_cast<const WDResult<std::vector<autofill::CreditCard*>>*>( |
| - result)->GetValue(); |
| + static_cast<const WDResult<std::vector<autofill::CreditCard*>>*>(result) |
| + ->GetValue(); |
| // We own the result from this query. Make sure it will be deleted. |
| ScopedVector<const autofill::CreditCard> owned_result; |
| owned_result.assign(credit_cards.begin(), credit_cards.end()); |
| - num_credit_cards_ = std::count_if( |
| - credit_cards.begin(), |
| - credit_cards.end(), |
| - [start](const autofill::CreditCard* card) { |
| - return card->modification_date() >= start; |
| - }); |
| + num_credit_cards_ = |
| + std::count_if(credit_cards.begin(), credit_cards.end(), |
|
msramek
2016/07/20 13:41:16
Is this git cl format? *grumble* *grumble* it's le
ioanap
2016/07/20 17:50:36
Oups, I didn't see this one. Yes, it's because of
|
| + [start](const autofill::CreditCard* card) { |
| + return card->modification_date() >= start; |
| + }); |
| credit_cards_query_ = 0; |
| } else if (handle == addresses_query_) { |
| @@ -119,18 +121,18 @@ void AutofillCounter::OnWebDataServiceRequestDone( |
| DCHECK_EQ(AUTOFILL_PROFILES_RESULT, result->GetType()); |
| const std::vector<autofill::AutofillProfile*> addresses = |
| static_cast<const WDResult<std::vector<autofill::AutofillProfile*>>*>( |
| - result)->GetValue(); |
| + result) |
| + ->GetValue(); |
| // We own the result from this query. Make sure it will be deleted. |
| ScopedVector<const autofill::AutofillProfile> owned_result; |
| owned_result.assign(addresses.begin(), addresses.end()); |
| - num_addresses_ = std::count_if( |
| - addresses.begin(), |
| - addresses.end(), |
| - [start](const autofill::AutofillProfile* address) { |
| - return address->modification_date() >= start; |
| - }); |
| + num_addresses_ = |
| + std::count_if(addresses.begin(), addresses.end(), |
| + [start](const autofill::AutofillProfile* address) { |
| + return address->modification_date() >= start; |
| + }); |
| addresses_query_ = 0; |
| } else { |
| @@ -157,15 +159,14 @@ void AutofillCounter::CancelAllRequests() { |
| // AutofillCounter::AutofillResult --------------------------------------------- |
| -AutofillCounter::AutofillResult::AutofillResult( |
| - const AutofillCounter* source, |
| - ResultInt num_suggestions, |
| - ResultInt num_credit_cards, |
| - ResultInt num_addresses) |
| +AutofillCounter::AutofillResult::AutofillResult(const AutofillCounter* source, |
| + ResultInt num_suggestions, |
| + ResultInt num_credit_cards, |
| + ResultInt num_addresses) |
| : FinishedResult(source, num_suggestions), |
| num_credit_cards_(num_credit_cards), |
| - num_addresses_(num_addresses) { |
| -} |
| + num_addresses_(num_addresses) {} |
| -AutofillCounter::AutofillResult::~AutofillResult() { |
| -} |
| +AutofillCounter::AutofillResult::~AutofillResult() {} |
| + |
| +} // namespace browsing_data |