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

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: Rebase Created 7 years, 8 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
« no previous file with comments | « components/autofill/browser/personal_data_manager.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/ref_counted.h"
12 #include "base/prefs/pref_service.h" 13 #include "base/prefs/pref_service.h"
13 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
14 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
15 #include "chrome/browser/webdata/autofill_web_data_service.h" 16 #include "chrome/browser/webdata/autofill_web_data_service.h"
16 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
17 #include "components/autofill/browser/autofill-inl.h" 18 #include "components/autofill/browser/autofill-inl.h"
18 #include "components/autofill/browser/autofill_country.h" 19 #include "components/autofill/browser/autofill_country.h"
19 #include "components/autofill/browser/autofill_field.h" 20 #include "components/autofill/browser/autofill_field.h"
20 #include "components/autofill/browser/autofill_metrics.h" 21 #include "components/autofill/browser/autofill_metrics.h"
21 #include "components/autofill/browser/form_group.h" 22 #include "components/autofill/browser/form_group.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 scoped_refptr<AutofillWebDataService> autofill_data( 125 scoped_refptr<AutofillWebDataService> autofill_data(
125 AutofillWebDataService::FromBrowserContext(browser_context_)); 126 AutofillWebDataService::FromBrowserContext(browser_context_));
126 127
127 // WebDataService may not be available in tests. 128 // WebDataService may not be available in tests.
128 if (!autofill_data.get()) 129 if (!autofill_data.get())
129 return; 130 return;
130 131
131 LoadProfiles(); 132 LoadProfiles();
132 LoadCreditCards(); 133 LoadCreditCards();
133 134
134 notification_registrar_.Add( 135 autofill_data->AddObserver(this);
135 this,
136 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED,
137 autofill_data->GetNotificationSource());
138 } 136 }
139 137
140 PersonalDataManager::~PersonalDataManager() { 138 PersonalDataManager::~PersonalDataManager() {
141 CancelPendingQuery(&pending_profiles_query_); 139 CancelPendingQuery(&pending_profiles_query_);
142 CancelPendingQuery(&pending_creditcards_query_); 140 CancelPendingQuery(&pending_creditcards_query_);
141
142 if (!browser_context_)
143 return;
144
145 scoped_refptr<AutofillWebDataService> autofill_data(
146 AutofillWebDataService::FromBrowserContext(browser_context_));
147 if (autofill_data.get())
148 autofill_data->RemoveObserver(this);
143 } 149 }
144 150
145 void PersonalDataManager::OnWebDataServiceRequestDone( 151 void PersonalDataManager::OnWebDataServiceRequestDone(
146 WebDataServiceBase::Handle h, 152 WebDataServiceBase::Handle h,
147 const WDTypedResult* result) { 153 const WDTypedResult* result) {
148 DCHECK(pending_profiles_query_ || pending_creditcards_query_); 154 DCHECK(pending_profiles_query_ || pending_creditcards_query_);
149 155
150 if (!result) { 156 if (!result) {
151 // Error from the web database. 157 // Error from the web database.
152 if (h == pending_creditcards_query_) 158 if (h == pending_creditcards_query_)
(...skipping 22 matching lines...) Expand all
175 is_data_loaded_ = true; 181 is_data_loaded_ = true;
176 std::vector<AutofillProfile*> profile_pointers(web_profiles_.size()); 182 std::vector<AutofillProfile*> profile_pointers(web_profiles_.size());
177 std::copy(web_profiles_.begin(), web_profiles_.end(), 183 std::copy(web_profiles_.begin(), web_profiles_.end(),
178 profile_pointers.begin()); 184 profile_pointers.begin());
179 AutofillProfile::AdjustInferredLabels(&profile_pointers); 185 AutofillProfile::AdjustInferredLabels(&profile_pointers);
180 FOR_EACH_OBSERVER(PersonalDataManagerObserver, observers_, 186 FOR_EACH_OBSERVER(PersonalDataManagerObserver, observers_,
181 OnPersonalDataChanged()); 187 OnPersonalDataChanged());
182 } 188 }
183 } 189 }
184 190
191 void PersonalDataManager::AutofillMultipleChanged() {
192 Refresh();
193 }
194
185 void PersonalDataManager::AddObserver(PersonalDataManagerObserver* observer) { 195 void PersonalDataManager::AddObserver(PersonalDataManagerObserver* observer) {
186 observers_.AddObserver(observer); 196 observers_.AddObserver(observer);
187 } 197 }
188 198
189 void PersonalDataManager::RemoveObserver( 199 void PersonalDataManager::RemoveObserver(
190 PersonalDataManagerObserver* observer) { 200 PersonalDataManagerObserver* observer) {
191 observers_.RemoveObserver(observer); 201 observers_.RemoveObserver(observer);
192 } 202 }
193 203
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_refptr<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( 204 bool PersonalDataManager::ImportFormData(
211 const FormStructure& form, 205 const FormStructure& form,
212 const CreditCard** imported_credit_card) { 206 const CreditCard** imported_credit_card) {
213 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile); 207 scoped_ptr<AutofillProfile> imported_profile(new AutofillProfile);
214 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard); 208 scoped_ptr<CreditCard> local_imported_credit_card(new CreditCard);
215 209
216 // Parse the form and construct a profile based on the information that is 210 // Parse the form and construct a profile based on the information that is
217 // possible to import. 211 // possible to import.
218 int importable_credit_card_fields = 0; 212 int importable_credit_card_fields = 0;
219 213
(...skipping 743 matching lines...) Expand 10 before | Expand all | Expand 10 after
963 957
964 void PersonalDataManager::set_metric_logger( 958 void PersonalDataManager::set_metric_logger(
965 const AutofillMetrics* metric_logger) { 959 const AutofillMetrics* metric_logger) {
966 metric_logger_.reset(metric_logger); 960 metric_logger_.reset(metric_logger);
967 } 961 }
968 962
969 void PersonalDataManager::set_browser_context( 963 void PersonalDataManager::set_browser_context(
970 content::BrowserContext* context) { 964 content::BrowserContext* context) {
971 browser_context_ = context; 965 browser_context_ = context;
972 } 966 }
OLDNEW
« no previous file with comments | « components/autofill/browser/personal_data_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698