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