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

Side by Side Diff: components/autofill/browser/personal_data_manager.cc

Issue 12476031: Refactor notifications of chrome/browser/webdata (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/autofill/browser/personal_data_manager.h" 5 #include "components/autofill/browser/personal_data_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <functional> 8 #include <functional>
9 #include <iterator> 9 #include <iterator>
10 10
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 scoped_ptr<AutofillWebDataService> autofill_data( 124 scoped_ptr<AutofillWebDataService> autofill_data(
125 AutofillWebDataService::FromBrowserContext(browser_context_)); 125 AutofillWebDataService::FromBrowserContext(browser_context_));
126 126
127 // WebDataService may not be available in tests. 127 // WebDataService may not be available in tests.
128 if (!autofill_data.get()) 128 if (!autofill_data.get())
129 return; 129 return;
130 130
131 LoadProfiles(); 131 LoadProfiles();
132 LoadCreditCards(); 132 LoadCreditCards();
133 133
134 notification_registrar_.Add( 134 autofill_data->AddObserver(this);
135 this,
136 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED,
137 autofill_data->GetNotificationSource());
138 } 135 }
139 136
140 PersonalDataManager::~PersonalDataManager() { 137 PersonalDataManager::~PersonalDataManager() {
141 CancelPendingQuery(&pending_profiles_query_); 138 CancelPendingQuery(&pending_profiles_query_);
142 CancelPendingQuery(&pending_creditcards_query_); 139 CancelPendingQuery(&pending_creditcards_query_);
140
141 if (!browser_context_)
142 return;
143
144 scoped_ptr<AutofillWebDataService> autofill_data(
145 AutofillWebDataService::FromBrowserContext(browser_context_));
146 if (autofill_data.get())
147 autofill_data->RemoveObserver(this);
143 } 148 }
144 149
145 void PersonalDataManager::OnWebDataServiceRequestDone( 150 void PersonalDataManager::OnWebDataServiceRequestDone(
146 WebDataServiceBase::Handle h, 151 WebDataServiceBase::Handle h,
147 const WDTypedResult* result) { 152 const WDTypedResult* result) {
148 DCHECK(pending_profiles_query_ || pending_creditcards_query_); 153 DCHECK(pending_profiles_query_ || pending_creditcards_query_);
149 154
150 if (!result) { 155 if (!result) {
151 // Error from the web database. 156 // Error from the web database.
152 if (h == pending_creditcards_query_) 157 if (h == pending_creditcards_query_)
(...skipping 22 matching lines...) Expand all
175 is_data_loaded_ = true; 180 is_data_loaded_ = true;
176 std::vector<AutofillProfile*> profile_pointers(web_profiles_.size()); 181 std::vector<AutofillProfile*> profile_pointers(web_profiles_.size());
177 std::copy(web_profiles_.begin(), web_profiles_.end(), 182 std::copy(web_profiles_.begin(), web_profiles_.end(),
178 profile_pointers.begin()); 183 profile_pointers.begin());
179 AutofillProfile::AdjustInferredLabels(&profile_pointers); 184 AutofillProfile::AdjustInferredLabels(&profile_pointers);
180 FOR_EACH_OBSERVER(PersonalDataManagerObserver, observers_, 185 FOR_EACH_OBSERVER(PersonalDataManagerObserver, observers_,
181 OnPersonalDataChanged()); 186 OnPersonalDataChanged());
182 } 187 }
183 } 188 }
184 189
190 void PersonalDataManager::AutofillMultipleChanged() {
191 Refresh();
192 }
193
185 void PersonalDataManager::AddObserver(PersonalDataManagerObserver* observer) { 194 void PersonalDataManager::AddObserver(PersonalDataManagerObserver* observer) {
186 observers_.AddObserver(observer); 195 observers_.AddObserver(observer);
187 } 196 }
188 197
189 void PersonalDataManager::RemoveObserver( 198 void PersonalDataManager::RemoveObserver(
190 PersonalDataManagerObserver* observer) { 199 PersonalDataManagerObserver* observer) {
191 observers_.RemoveObserver(observer); 200 observers_.RemoveObserver(observer);
192 } 201 }
193 202
194 void PersonalDataManager::Observe(int type,
195 const content::NotificationSource& source,
196 const content::NotificationDetails& details) {
197 DCHECK_EQ(type, chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED);
198
199 if (DCHECK_IS_ON()) {
200 scoped_ptr<AutofillWebDataService> autofill_data(
201 AutofillWebDataService::FromBrowserContext(browser_context_));
202
203 DCHECK(autofill_data.get() &&
204 autofill_data->GetNotificationSource() == source);
205 }
206
207 Refresh();
208 }
209
210 bool PersonalDataManager::ImportFormData( 203 bool PersonalDataManager::ImportFormData(
211 const FormStructure& form, 204 const FormStructure& form,
212 const CreditCard** imported_credit_card) { 205 const CreditCard** imported_credit_card) {
213 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile); 206 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile);
214 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard); 207 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard);
215 208
216 // Parse the form and construct a profile based on the information that is 209 // Parse the form and construct a profile based on the information that is
217 // possible to import. 210 // possible to import.
218 int importable_credit_card_fields = 0; 211 int importable_credit_card_fields = 0;
219 212
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 956
964 void PersonalDataManager::set_metric_logger( 957 void PersonalDataManager::set_metric_logger(
965 const AutofillMetrics* metric_logger) { 958 const AutofillMetrics* metric_logger) {
966 metric_logger_.reset(metric_logger); 959 metric_logger_.reset(metric_logger);
967 } 960 }
968 961
969 void PersonalDataManager::set_browser_context( 962 void PersonalDataManager::set_browser_context(
970 content::BrowserContext* context) { 963 content::BrowserContext* context) {
971 browser_context_ = context; 964 browser_context_ = context;
972 } 965 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698