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 #include "components/browsing_data/core/counters/autofill_counter.h" | 5 #include "components/browsing_data/core/counters/autofill_counter.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/ptr_util.h" | |
11 #include "components/autofill/core/browser/autofill_profile.h" | 12 #include "components/autofill/core/browser/autofill_profile.h" |
12 #include "components/autofill/core/browser/credit_card.h" | 13 #include "components/autofill/core/browser/credit_card.h" |
13 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" | 14 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" |
14 #include "components/browsing_data/core/pref_names.h" | 15 #include "components/browsing_data/core/pref_names.h" |
16 #include "components/sync/driver/sync_service.h" | |
17 | |
18 namespace { | |
19 | |
20 bool IsAutofillSyncEnabled(const syncer::SyncService* sync_service) { | |
21 return sync_service && sync_service->IsFirstSetupComplete() && | |
22 sync_service->IsSyncActive() && | |
23 sync_service->GetActiveDataTypes().Has(syncer::AUTOFILL); | |
24 } | |
25 | |
26 } // namespace | |
15 | 27 |
16 namespace browsing_data { | 28 namespace browsing_data { |
17 | 29 |
18 AutofillCounter::AutofillCounter( | 30 AutofillCounter::AutofillCounter( |
19 scoped_refptr<autofill::AutofillWebDataService> web_data_service) | 31 scoped_refptr<autofill::AutofillWebDataService> web_data_service, |
32 syncer::SyncService* sync_service) | |
20 : web_data_service_(web_data_service), | 33 : web_data_service_(web_data_service), |
34 sync_service_(sync_service), | |
21 suggestions_query_(0), | 35 suggestions_query_(0), |
22 credit_cards_query_(0), | 36 credit_cards_query_(0), |
23 addresses_query_(0), | 37 addresses_query_(0), |
24 num_suggestions_(0), | 38 num_suggestions_(0), |
25 num_credit_cards_(0), | 39 num_credit_cards_(0), |
26 num_addresses_(0) {} | 40 num_addresses_(0), |
41 autofill_sync_enabled_() {} | |
27 | 42 |
28 AutofillCounter::~AutofillCounter() { | 43 AutofillCounter::~AutofillCounter() { |
29 CancelAllRequests(); | 44 CancelAllRequests(); |
45 if (sync_service_) | |
46 sync_service_->RemoveObserver(this); | |
30 } | 47 } |
31 | 48 |
32 void AutofillCounter::OnInitialized() { | 49 void AutofillCounter::OnInitialized() { |
33 DCHECK(web_data_service_); | 50 DCHECK(web_data_service_); |
51 if (sync_service_) | |
52 sync_service_->AddObserver(this); | |
53 autofill_sync_enabled_ = IsAutofillSyncEnabled(sync_service_); | |
34 } | 54 } |
35 | 55 |
36 const char* AutofillCounter::GetPrefName() const { | 56 const char* AutofillCounter::GetPrefName() const { |
37 return browsing_data::prefs::kDeleteFormData; | 57 return browsing_data::prefs::kDeleteFormData; |
38 } | 58 } |
39 | 59 |
40 void AutofillCounter::SetPeriodStartForTesting( | 60 void AutofillCounter::SetPeriodStartForTesting( |
41 const base::Time& period_start_for_testing) { | 61 const base::Time& period_start_for_testing) { |
42 period_start_for_testing_ = period_start_for_testing; | 62 period_start_for_testing_ = period_start_for_testing; |
43 } | 63 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 addresses_query_ = 0; | 163 addresses_query_ = 0; |
144 | 164 |
145 } else { | 165 } else { |
146 NOTREACHED() << "No such query: " << handle; | 166 NOTREACHED() << "No such query: " << handle; |
147 } | 167 } |
148 | 168 |
149 // If we still have pending queries, do not report data yet. | 169 // If we still have pending queries, do not report data yet. |
150 if (suggestions_query_ || credit_cards_query_ || addresses_query_) | 170 if (suggestions_query_ || credit_cards_query_ || addresses_query_) |
151 return; | 171 return; |
152 | 172 |
153 std::unique_ptr<Result> reported_result(new AutofillResult( | 173 auto reported_result = base::MakeUnique<AutofillResult>( |
154 this, num_suggestions_, num_credit_cards_, num_addresses_)); | 174 this, num_suggestions_, num_credit_cards_, num_addresses_, |
175 autofill_sync_enabled_); | |
155 ReportResult(std::move(reported_result)); | 176 ReportResult(std::move(reported_result)); |
156 } | 177 } |
157 | 178 |
158 void AutofillCounter::CancelAllRequests() { | 179 void AutofillCounter::CancelAllRequests() { |
159 if (suggestions_query_) | 180 if (suggestions_query_) |
160 web_data_service_->CancelRequest(suggestions_query_); | 181 web_data_service_->CancelRequest(suggestions_query_); |
161 if (credit_cards_query_) | 182 if (credit_cards_query_) |
162 web_data_service_->CancelRequest(credit_cards_query_); | 183 web_data_service_->CancelRequest(credit_cards_query_); |
163 if (addresses_query_) | 184 if (addresses_query_) |
164 web_data_service_->CancelRequest(addresses_query_); | 185 web_data_service_->CancelRequest(addresses_query_); |
165 } | 186 } |
166 | 187 |
188 void AutofillCounter::OnStateChanged(syncer::SyncService* sync) { | |
msramek
2017/04/28 19:13:13
Ditto here. We may be able to start moving things
| |
189 bool sync_enabled_new = IsAutofillSyncEnabled(sync); | |
190 if (autofill_sync_enabled_ != sync_enabled_new) { | |
191 autofill_sync_enabled_ = sync_enabled_new; | |
192 Restart(); | |
193 } | |
194 } | |
195 | |
167 // AutofillCounter::AutofillResult --------------------------------------------- | 196 // AutofillCounter::AutofillResult --------------------------------------------- |
168 | 197 |
169 AutofillCounter::AutofillResult::AutofillResult(const AutofillCounter* source, | 198 AutofillCounter::AutofillResult::AutofillResult(const AutofillCounter* source, |
170 ResultInt num_suggestions, | 199 ResultInt num_suggestions, |
171 ResultInt num_credit_cards, | 200 ResultInt num_credit_cards, |
172 ResultInt num_addresses) | 201 ResultInt num_addresses, |
202 bool autofill_sync_enabled_) | |
173 : FinishedResult(source, num_suggestions), | 203 : FinishedResult(source, num_suggestions), |
174 num_credit_cards_(num_credit_cards), | 204 num_credit_cards_(num_credit_cards), |
175 num_addresses_(num_addresses) {} | 205 num_addresses_(num_addresses), |
206 autofill_sync_enabled_(autofill_sync_enabled_) {} | |
176 | 207 |
177 AutofillCounter::AutofillResult::~AutofillResult() {} | 208 AutofillCounter::AutofillResult::~AutofillResult() {} |
178 | 209 |
179 } // namespace browsing_data | 210 } // namespace browsing_data |
OLD | NEW |