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