| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_BROWSING_DATA_AUTOFILL_COUNTER_H_ | |
| 6 #define CHROME_BROWSER_BROWSING_DATA_AUTOFILL_COUNTER_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/threading/thread_checker.h" | |
| 10 #include "base/time/time.h" | |
| 11 #include "components/browsing_data/core/counters/browsing_data_counter.h" | |
| 12 #include "components/webdata/common/web_data_service_consumer.h" | |
| 13 | |
| 14 class Profile; | |
| 15 | |
| 16 namespace autofill { | |
| 17 class AutofillWebDataService; | |
| 18 } | |
| 19 | |
| 20 class AutofillCounter : public browsing_data::BrowsingDataCounter, | |
| 21 public WebDataServiceConsumer { | |
| 22 public: | |
| 23 class AutofillResult : public FinishedResult { | |
| 24 public: | |
| 25 AutofillResult(const AutofillCounter* source, | |
| 26 ResultInt num_suggestions, | |
| 27 ResultInt num_credit_cards, | |
| 28 ResultInt num_addresses); | |
| 29 ~AutofillResult() override; | |
| 30 | |
| 31 ResultInt num_credit_cards() const { return num_credit_cards_; } | |
| 32 ResultInt num_addresses() const { return num_addresses_; } | |
| 33 | |
| 34 private: | |
| 35 ResultInt num_credit_cards_; | |
| 36 ResultInt num_addresses_; | |
| 37 | |
| 38 DISALLOW_COPY_AND_ASSIGN(AutofillResult); | |
| 39 }; | |
| 40 | |
| 41 explicit AutofillCounter(Profile* profile); | |
| 42 ~AutofillCounter() override; | |
| 43 | |
| 44 // BrowsingDataCounter implementation. | |
| 45 void OnInitialized() override; | |
| 46 | |
| 47 // Whether the counting is in progress. | |
| 48 bool HasPendingQuery() { | |
| 49 return suggestions_query_ || credit_cards_query_ || addresses_query_; | |
| 50 } | |
| 51 | |
| 52 // Set the beginning of the time period for testing. AutofillTable does not | |
| 53 // allow us to set time explicitly, and BrowsingDataCounter recognizes | |
| 54 // only predefined time periods, out of which the lowest one is one hour. | |
| 55 // Obviously, the test cannot run that long. | |
| 56 // TODO(msramek): Consider changing BrowsingDataCounter to use arbitrary | |
| 57 // time periods instead of BrowsingDataRemover::TimePeriod. | |
| 58 void SetPeriodStartForTesting(const base::Time& period_start_for_testing); | |
| 59 | |
| 60 private: | |
| 61 Profile* profile_; | |
| 62 base::ThreadChecker thread_checker_; | |
| 63 | |
| 64 scoped_refptr<autofill::AutofillWebDataService> web_data_service_; | |
| 65 | |
| 66 WebDataServiceBase::Handle suggestions_query_; | |
| 67 WebDataServiceBase::Handle credit_cards_query_; | |
| 68 WebDataServiceBase::Handle addresses_query_; | |
| 69 | |
| 70 ResultInt num_suggestions_; | |
| 71 ResultInt num_credit_cards_; | |
| 72 ResultInt num_addresses_; | |
| 73 | |
| 74 base::Time period_start_for_testing_; | |
| 75 | |
| 76 void Count() override; | |
| 77 | |
| 78 // WebDataServiceConsumer implementation. | |
| 79 void OnWebDataServiceRequestDone(WebDataServiceBase::Handle handle, | |
| 80 const WDTypedResult* result) override; | |
| 81 | |
| 82 // Cancel all pending requests to AutofillWebdataService. | |
| 83 void CancelAllRequests(); | |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(AutofillCounter); | |
| 86 }; | |
| 87 | |
| 88 #endif // CHROME_BROWSER_BROWSING_DATA_AUTOFILL_COUNTER_H_ | |
| OLD | NEW |