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