Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(659)

Side by Side Diff: components/browsing_data/core/counters/autofill_counter.h

Issue 2828083003: Show autofill sync status in CBD (Closed)
Patch Set: fix history test Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 COMPONENTS_BROWSING_DATA_CORE_COUNTERS_AUTOFILL_COUNTER_H_ 5 #ifndef COMPONENTS_BROWSING_DATA_CORE_COUNTERS_AUTOFILL_COUNTER_H_
6 #define COMPONENTS_BROWSING_DATA_CORE_COUNTERS_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/autofill/core/browser/webdata/autofill_webdata_service.h"
12 #include "components/browsing_data/core/counters/browsing_data_counter.h" 12 #include "components/browsing_data/core/counters/browsing_data_counter.h"
13 #include "components/sync/driver/sync_service_observer.h"
13 #include "components/webdata/common/web_data_service_consumer.h" 14 #include "components/webdata/common/web_data_service_consumer.h"
14 15
15 namespace autofill { 16 namespace autofill {
16 class AutofillWebDataService; 17 class AutofillWebDataService;
17 } 18 }
18 19
19 namespace browsing_data { 20 namespace browsing_data {
20 21
21 class AutofillCounter : public browsing_data::BrowsingDataCounter, 22 class AutofillCounter : public browsing_data::BrowsingDataCounter,
22 public WebDataServiceConsumer { 23 public WebDataServiceConsumer,
24 public syncer::SyncServiceObserver {
23 public: 25 public:
24 class AutofillResult : public FinishedResult { 26 class AutofillResult : public FinishedResult {
25 public: 27 public:
26 AutofillResult(const AutofillCounter* source, 28 AutofillResult(const AutofillCounter* source,
27 ResultInt num_suggestions, 29 ResultInt num_suggestions,
28 ResultInt num_credit_cards, 30 ResultInt num_credit_cards,
29 ResultInt num_addresses); 31 ResultInt num_addresses,
32 bool autofill_sync_enabled_);
30 ~AutofillResult() override; 33 ~AutofillResult() override;
31 34
32 ResultInt num_credit_cards() const { return num_credit_cards_; } 35 ResultInt num_credit_cards() const { return num_credit_cards_; }
33 ResultInt num_addresses() const { return num_addresses_; } 36 ResultInt num_addresses() const { return num_addresses_; }
37 bool autofill_sync_enabled() const { return autofill_sync_enabled_; }
34 38
35 private: 39 private:
36 ResultInt num_credit_cards_; 40 ResultInt num_credit_cards_;
37 ResultInt num_addresses_; 41 ResultInt num_addresses_;
42 bool autofill_sync_enabled_;
38 43
39 DISALLOW_COPY_AND_ASSIGN(AutofillResult); 44 DISALLOW_COPY_AND_ASSIGN(AutofillResult);
40 }; 45 };
41 46
42 explicit AutofillCounter( 47 explicit AutofillCounter(
43 scoped_refptr<autofill::AutofillWebDataService> web_data_service); 48 scoped_refptr<autofill::AutofillWebDataService> web_data_service,
49 syncer::SyncService* sync_service);
44 ~AutofillCounter() override; 50 ~AutofillCounter() override;
45 51
46 // BrowsingDataCounter implementation. 52 // BrowsingDataCounter implementation.
47 void OnInitialized() override; 53 void OnInitialized() override;
48 54
49 const char* GetPrefName() const override; 55 const char* GetPrefName() const override;
50 56
51 // Set the beginning of the time period for testing. AutofillTable does not 57 // Set the beginning of the time period for testing. AutofillTable does not
52 // allow us to set time explicitly, and BrowsingDataCounter recognizes 58 // allow us to set time explicitly, and BrowsingDataCounter recognizes
53 // only predefined time periods, out of which the lowest one is one hour. 59 // only predefined time periods, out of which the lowest one is one hour.
54 // Obviously, the test cannot run that long. 60 // Obviously, the test cannot run that long.
55 // TODO(msramek): Consider changing BrowsingDataCounter to use arbitrary 61 // TODO(msramek): Consider changing BrowsingDataCounter to use arbitrary
56 // time periods instead of BrowsingDataRemover::TimePeriod. 62 // time periods instead of BrowsingDataRemover::TimePeriod.
57 void SetPeriodStartForTesting(const base::Time& period_start_for_testing); 63 void SetPeriodStartForTesting(const base::Time& period_start_for_testing);
58 64
59 private: 65 private:
60 void Count() override; 66 void Count() override;
61 67
62 // WebDataServiceConsumer implementation. 68 // WebDataServiceConsumer implementation.
63 void OnWebDataServiceRequestDone( 69 void OnWebDataServiceRequestDone(
64 WebDataServiceBase::Handle handle, 70 WebDataServiceBase::Handle handle,
65 std::unique_ptr<WDTypedResult> result) override; 71 std::unique_ptr<WDTypedResult> result) override;
66 72
73 // SyncServiceObserver implementation.
74 void OnStateChanged(syncer::SyncService* sync) override;
75
67 // Cancel all pending requests to AutofillWebdataService. 76 // Cancel all pending requests to AutofillWebdataService.
68 void CancelAllRequests(); 77 void CancelAllRequests();
69 78
70 base::ThreadChecker thread_checker_; 79 base::ThreadChecker thread_checker_;
71 80
72 scoped_refptr<autofill::AutofillWebDataService> web_data_service_; 81 scoped_refptr<autofill::AutofillWebDataService> web_data_service_;
82 syncer::SyncService* sync_service_;
73 83
74 WebDataServiceBase::Handle suggestions_query_; 84 WebDataServiceBase::Handle suggestions_query_;
75 WebDataServiceBase::Handle credit_cards_query_; 85 WebDataServiceBase::Handle credit_cards_query_;
76 WebDataServiceBase::Handle addresses_query_; 86 WebDataServiceBase::Handle addresses_query_;
77 87
78 ResultInt num_suggestions_; 88 ResultInt num_suggestions_;
79 ResultInt num_credit_cards_; 89 ResultInt num_credit_cards_;
80 ResultInt num_addresses_; 90 ResultInt num_addresses_;
91 bool autofill_sync_enabled_;
81 92
82 base::Time period_start_for_testing_; 93 base::Time period_start_for_testing_;
83 94
84 DISALLOW_COPY_AND_ASSIGN(AutofillCounter); 95 DISALLOW_COPY_AND_ASSIGN(AutofillCounter);
85 }; 96 };
86 97
87 } // namespace browsing_data 98 } // namespace browsing_data
88 99
89 #endif // COMPONENTS_BROWSING_DATA_CORE_COUNTERS_AUTOFILL_COUNTER_H_ 100 #endif // COMPONENTS_BROWSING_DATA_CORE_COUNTERS_AUTOFILL_COUNTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698