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

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

Issue 2403773002: Remove stl_util's STLDeleteContainerPointers from autofill. (Closed)
Patch Set: rebase Created 4 years, 2 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 #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/scoped_vector.h"
12 #include "components/autofill/core/browser/autofill_profile.h" 11 #include "components/autofill/core/browser/autofill_profile.h"
13 #include "components/autofill/core/browser/credit_card.h" 12 #include "components/autofill/core/browser/credit_card.h"
14 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h" 13 #include "components/autofill/core/browser/webdata/autofill_webdata_service.h"
15 #include "components/browsing_data/core/pref_names.h" 14 #include "components/browsing_data/core/pref_names.h"
16 15
17 namespace browsing_data { 16 namespace browsing_data {
18 17
19 AutofillCounter::AutofillCounter( 18 AutofillCounter::AutofillCounter(
20 scoped_refptr<autofill::AutofillWebDataService> web_data_service) 19 scoped_refptr<autofill::AutofillWebDataService> web_data_service)
21 : web_data_service_(web_data_service), 20 : web_data_service_(web_data_service),
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 72
74 // Count the credit cards. 73 // Count the credit cards.
75 credit_cards_query_ = web_data_service_->GetCreditCards(this); 74 credit_cards_query_ = web_data_service_->GetCreditCards(this);
76 75
77 // Count the addresses. 76 // Count the addresses.
78 addresses_query_ = web_data_service_->GetAutofillProfiles(this); 77 addresses_query_ = web_data_service_->GetAutofillProfiles(this);
79 } 78 }
80 79
81 void AutofillCounter::OnWebDataServiceRequestDone( 80 void AutofillCounter::OnWebDataServiceRequestDone(
82 WebDataServiceBase::Handle handle, 81 WebDataServiceBase::Handle handle,
83 const WDTypedResult* result) { 82 std::unique_ptr<WDTypedResult> result) {
84 DCHECK(thread_checker_.CalledOnValidThread()); 83 DCHECK(thread_checker_.CalledOnValidThread());
85 if (!result) { 84 if (!result) {
86 CancelAllRequests(); 85 CancelAllRequests();
87 return; 86 return;
88 } 87 }
89 88
90 const base::Time start = period_start_for_testing_.is_null() 89 const base::Time start = period_start_for_testing_.is_null()
91 ? GetPeriodStart() 90 ? GetPeriodStart()
92 : period_start_for_testing_; 91 : period_start_for_testing_;
93 92
94 if (handle == suggestions_query_) { 93 if (handle == suggestions_query_) {
95 // Autocomplete suggestions. 94 // Autocomplete suggestions.
96 DCHECK_EQ(AUTOFILL_VALUE_RESULT, result->GetType()); 95 DCHECK_EQ(AUTOFILL_VALUE_RESULT, result->GetType());
97 num_suggestions_ = static_cast<const WDResult<int>*>(result)->GetValue(); 96 num_suggestions_ =
97 static_cast<const WDResult<int>*>(result.get())->GetValue();
98 suggestions_query_ = 0; 98 suggestions_query_ = 0;
99 99
100 } else if (handle == credit_cards_query_) { 100 } else if (handle == credit_cards_query_) {
101 // Credit cards. 101 // Credit cards.
102 DCHECK_EQ(AUTOFILL_CREDITCARDS_RESULT, result->GetType()); 102 DCHECK_EQ(AUTOFILL_CREDITCARDS_RESULT, result->GetType());
103 const std::vector<autofill::CreditCard*> credit_cards = 103 auto credit_cards =
104 static_cast<const WDResult<std::vector<autofill::CreditCard*>>*>(result) 104 static_cast<
105 WDResult<std::vector<std::unique_ptr<autofill::CreditCard>>>*>(
106 result.get())
105 ->GetValue(); 107 ->GetValue();
106 108
107 // We own the result from this query. Make sure it will be deleted.
108 ScopedVector<const autofill::CreditCard> owned_result;
109 owned_result.assign(credit_cards.begin(), credit_cards.end());
110
111 num_credit_cards_ = std::count_if( 109 num_credit_cards_ = std::count_if(
112 credit_cards.begin(), 110 credit_cards.begin(), credit_cards.end(),
113 credit_cards.end(), 111 [start](const std::unique_ptr<autofill::CreditCard>& card) {
114 [start](const autofill::CreditCard* card) {
115 return card->modification_date() >= start; 112 return card->modification_date() >= start;
116 }); 113 });
117 credit_cards_query_ = 0; 114 credit_cards_query_ = 0;
118 115
119 } else if (handle == addresses_query_) { 116 } else if (handle == addresses_query_) {
120 // Addresses. 117 // Addresses.
121 DCHECK_EQ(AUTOFILL_PROFILES_RESULT, result->GetType()); 118 DCHECK_EQ(AUTOFILL_PROFILES_RESULT, result->GetType());
122 const std::vector<autofill::AutofillProfile*> addresses = 119 auto addresses =
123 static_cast<const WDResult<std::vector<autofill::AutofillProfile*>>*>( 120 static_cast<
124 result) 121 WDResult<std::vector<std::unique_ptr<autofill::AutofillProfile>>>*>(
122 result.get())
125 ->GetValue(); 123 ->GetValue();
126 124
127 // We own the result from this query. Make sure it will be deleted. 125 num_addresses_ = std::count_if(
128 ScopedVector<const autofill::AutofillProfile> owned_result; 126 addresses.begin(), addresses.end(),
129 owned_result.assign(addresses.begin(), addresses.end()); 127 [start](const std::unique_ptr<autofill::AutofillProfile>& address) {
130 128 return address->modification_date() >= start;
131 num_addresses_ = 129 });
132 std::count_if(addresses.begin(), addresses.end(),
133 [start](const autofill::AutofillProfile* address) {
134 return address->modification_date() >= start;
135 });
136 addresses_query_ = 0; 130 addresses_query_ = 0;
137 131
138 } else { 132 } else {
139 NOTREACHED() << "No such query: " << handle; 133 NOTREACHED() << "No such query: " << handle;
140 } 134 }
141 135
142 // If we still have pending queries, do not report data yet. 136 // If we still have pending queries, do not report data yet.
143 if (HasPendingQuery()) 137 if (HasPendingQuery())
144 return; 138 return;
145 139
(...skipping 17 matching lines...) Expand all
163 ResultInt num_suggestions, 157 ResultInt num_suggestions,
164 ResultInt num_credit_cards, 158 ResultInt num_credit_cards,
165 ResultInt num_addresses) 159 ResultInt num_addresses)
166 : FinishedResult(source, num_suggestions), 160 : FinishedResult(source, num_suggestions),
167 num_credit_cards_(num_credit_cards), 161 num_credit_cards_(num_credit_cards),
168 num_addresses_(num_addresses) {} 162 num_addresses_(num_addresses) {}
169 163
170 AutofillCounter::AutofillResult::~AutofillResult() {} 164 AutofillCounter::AutofillResult::~AutofillResult() {}
171 165
172 } // namespace browsing_data 166 } // namespace browsing_data
OLDNEW
« no previous file with comments | « components/browsing_data/core/counters/autofill_counter.h ('k') | components/search_engines/template_url_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698