| OLD | NEW |
| 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 "chrome/browser/webdata/autofill_web_data_service.h" | 5 #include "chrome/browser/webdata/autofill_web_data_service.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "chrome/browser/webdata/autofill_change.h" | 9 #include "chrome/browser/webdata/autofill_change.h" |
| 10 #include "chrome/browser/webdata/autofill_entry.h" | 10 #include "chrome/browser/webdata/autofill_entry.h" |
| 11 #include "chrome/browser/webdata/autofill_table.h" | 11 #include "chrome/browser/webdata/autofill_table.h" |
| 12 #include "chrome/browser/webdata/autofill_web_data_service_observer.h" |
| 12 #include "chrome/browser/webdata/web_database_service.h" | 13 #include "chrome/browser/webdata/web_database_service.h" |
| 13 #include "chrome/common/chrome_notification_types.h" | |
| 14 #include "components/autofill/browser/autofill_country.h" | 14 #include "components/autofill/browser/autofill_country.h" |
| 15 #include "components/autofill/browser/autofill_profile.h" | 15 #include "components/autofill/browser/autofill_profile.h" |
| 16 #include "components/autofill/browser/credit_card.h" | 16 #include "components/autofill/browser/credit_card.h" |
| 17 #include "components/autofill/common/form_field_data.h" | 17 #include "components/autofill/common/form_field_data.h" |
| 18 #include "content/public/browser/notification_details.h" | |
| 19 #include "content/public/browser/notification_service.h" | |
| 20 #include "content/public/browser/notification_source.h" | |
| 21 | 18 |
| 22 using base::Bind; | 19 using base::Bind; |
| 23 using base::Time; | 20 using base::Time; |
| 24 using content::BrowserThread; | 21 using content::BrowserThread; |
| 25 | 22 |
| 26 namespace { | |
| 27 | |
| 28 // A task used by AutofillWebDataService (for Sync mainly) to inform the | |
| 29 // PersonalDataManager living on the UI thread that it needs to refresh. | |
| 30 void NotifyOfMultipleAutofillChangesTask( | |
| 31 const scoped_refptr<AutofillWebDataService>& web_data_service) { | |
| 32 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 33 | |
| 34 content::NotificationService::current()->Notify( | |
| 35 chrome::NOTIFICATION_AUTOFILL_MULTIPLE_CHANGED, | |
| 36 content::Source<AutofillWebDataService>(web_data_service.get()), | |
| 37 content::NotificationService::NoDetails()); | |
| 38 } | |
| 39 } | |
| 40 | |
| 41 // static | 23 // static |
| 42 void AutofillWebDataService::NotifyOfMultipleAutofillChanges( | 24 void AutofillWebDataService::NotifyOfMultipleAutofillChanges( |
| 43 AutofillWebDataService* web_data_service) { | 25 AutofillWebDataService* web_data_service) { |
| 44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 45 | 27 |
| 46 if (!web_data_service) | 28 if (!web_data_service) |
| 47 return; | 29 return; |
| 48 | 30 |
| 49 BrowserThread::PostTask( | 31 BrowserThread::PostTask( |
| 50 BrowserThread::UI, FROM_HERE, | 32 BrowserThread::UI, FROM_HERE, |
| 51 Bind(&NotifyOfMultipleAutofillChangesTask, | 33 Bind(&AutofillWebDataService::NotifyAutofillMultipleChangedOnUIThread, |
| 52 make_scoped_refptr(web_data_service))); | 34 make_scoped_refptr(web_data_service))); |
| 53 } | 35 } |
| 54 | 36 |
| 55 AutofillWebDataService::AutofillWebDataService( | 37 AutofillWebDataService::AutofillWebDataService( |
| 56 scoped_refptr<WebDatabaseService> wdbs, | 38 scoped_refptr<WebDatabaseService> wdbs, |
| 57 const ProfileErrorCallback& callback) | 39 const ProfileErrorCallback& callback) |
| 58 : WebDataServiceBase(wdbs, callback) { | 40 : WebDataServiceBase(wdbs, callback) { |
| 59 } | 41 } |
| 60 | 42 |
| 61 AutofillWebDataService::AutofillWebDataService() | 43 AutofillWebDataService::AutofillWebDataService() |
| 62 : WebDataServiceBase(NULL, | 44 : WebDataServiceBase(NULL, |
| 63 WebDataServiceBase::ProfileErrorCallback()) { | 45 WebDataServiceBase::ProfileErrorCallback()) { |
| 64 } | 46 } |
| 65 | 47 |
| 66 content::NotificationSource AutofillWebDataService::GetNotificationSource() { | |
| 67 return content::Source<AutofillWebDataService>(this); | |
| 68 } | |
| 69 | |
| 70 void AutofillWebDataService::AddFormFields( | 48 void AutofillWebDataService::AddFormFields( |
| 71 const std::vector<FormFieldData>& fields) { | 49 const std::vector<FormFieldData>& fields) { |
| 72 wdbs_->ScheduleDBTask(FROM_HERE, | 50 wdbs_->ScheduleDBTask(FROM_HERE, |
| 73 Bind(&AutofillWebDataService::AddFormElementsImpl, this, fields)); | 51 Bind(&AutofillWebDataService::AddFormElementsImpl, this, fields)); |
| 74 } | 52 } |
| 75 | 53 |
| 76 WebDataServiceBase::Handle AutofillWebDataService::GetFormValuesForElementName( | 54 WebDataServiceBase::Handle AutofillWebDataService::GetFormValuesForElementName( |
| 77 const string16& name, const string16& prefix, int limit, | 55 const string16& name, const string16& prefix, int limit, |
| 78 WebDataServiceConsumer* consumer) { | 56 WebDataServiceConsumer* consumer) { |
| 79 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, | 57 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 } | 98 } |
| 121 | 99 |
| 122 WebDataServiceBase::Handle AutofillWebDataService::GetAutofillProfiles( | 100 WebDataServiceBase::Handle AutofillWebDataService::GetAutofillProfiles( |
| 123 WebDataServiceConsumer* consumer) { | 101 WebDataServiceConsumer* consumer) { |
| 124 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, | 102 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, |
| 125 Bind(&AutofillWebDataService::GetAutofillProfilesImpl, this), | 103 Bind(&AutofillWebDataService::GetAutofillProfilesImpl, this), |
| 126 consumer); | 104 consumer); |
| 127 } | 105 } |
| 128 | 106 |
| 129 void AutofillWebDataService::AddCreditCard(const CreditCard& credit_card) { | 107 void AutofillWebDataService::AddCreditCard(const CreditCard& credit_card) { |
| 130 wdbs_->ScheduleDBTask(FROM_HERE, | 108 wdbs_->ScheduleDBTask( |
| 109 FROM_HERE, |
| 131 Bind(&AutofillWebDataService::AddCreditCardImpl, this, credit_card)); | 110 Bind(&AutofillWebDataService::AddCreditCardImpl, this, credit_card)); |
| 132 } | 111 } |
| 133 | 112 |
| 134 void AutofillWebDataService::UpdateCreditCard( | 113 void AutofillWebDataService::UpdateCreditCard( |
| 135 const CreditCard& credit_card) { | 114 const CreditCard& credit_card) { |
| 136 wdbs_->ScheduleDBTask(FROM_HERE, | 115 wdbs_->ScheduleDBTask( |
| 137 Bind(&AutofillWebDataService::UpdateCreditCardImpl, this, | 116 FROM_HERE, |
| 138 credit_card)); | 117 Bind(&AutofillWebDataService::UpdateCreditCardImpl, this, credit_card)); |
| 139 } | 118 } |
| 140 | 119 |
| 141 void AutofillWebDataService::RemoveCreditCard(const std::string& guid) { | 120 void AutofillWebDataService::RemoveCreditCard(const std::string& guid) { |
| 142 wdbs_->ScheduleDBTask(FROM_HERE, | 121 wdbs_->ScheduleDBTask( |
| 122 FROM_HERE, |
| 143 Bind(&AutofillWebDataService::RemoveCreditCardImpl, this, guid)); | 123 Bind(&AutofillWebDataService::RemoveCreditCardImpl, this, guid)); |
| 144 } | 124 } |
| 145 | 125 |
| 146 WebDataServiceBase::Handle AutofillWebDataService::GetCreditCards( | 126 WebDataServiceBase::Handle AutofillWebDataService::GetCreditCards( |
| 147 WebDataServiceConsumer* consumer) { | 127 WebDataServiceConsumer* consumer) { |
| 148 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, | 128 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, |
| 149 Bind(&AutofillWebDataService::GetCreditCardsImpl, this), consumer); | 129 Bind(&AutofillWebDataService::GetCreditCardsImpl, this), consumer); |
| 150 } | 130 } |
| 151 | 131 |
| 152 void AutofillWebDataService::RemoveAutofillDataModifiedBetween( | 132 void AutofillWebDataService::RemoveAutofillDataModifiedBetween( |
| 153 const Time& delete_begin, const Time& delete_end) { | 133 const Time& delete_begin, |
| 154 wdbs_->ScheduleDBTask(FROM_HERE, Bind( | 134 const Time& delete_end) { |
| 155 &AutofillWebDataService::RemoveAutofillDataModifiedBetweenImpl, | 135 wdbs_->ScheduleDBTask( |
| 156 this, delete_begin, delete_end)); | 136 FROM_HERE, |
| 137 Bind(&AutofillWebDataService::RemoveAutofillDataModifiedBetweenImpl, |
| 138 this, delete_begin, delete_end)); |
| 157 } | 139 } |
| 158 | 140 |
| 159 AutofillWebDataService::~AutofillWebDataService() { | 141 void AutofillWebDataService::AddObserver( |
| 142 AutofillWebDataServiceObserverOnDBThread* observer) { |
| 143 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 144 db_observer_list_.AddObserver(observer); |
| 145 } |
| 146 |
| 147 void AutofillWebDataService::RemoveObserver( |
| 148 AutofillWebDataServiceObserverOnDBThread* observer) { |
| 149 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 150 db_observer_list_.RemoveObserver(observer); |
| 151 } |
| 152 |
| 153 void AutofillWebDataService::AddObserver( |
| 154 AutofillWebDataServiceObserverOnUIThread* observer) { |
| 155 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 156 ui_observer_list_.AddObserver(observer); |
| 157 } |
| 158 |
| 159 void AutofillWebDataService::RemoveObserver( |
| 160 AutofillWebDataServiceObserverOnUIThread* observer) { |
| 161 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 162 ui_observer_list_.RemoveObserver(observer); |
| 163 } |
| 164 |
| 165 AutofillWebDataService::~AutofillWebDataService() {} |
| 166 |
| 167 void AutofillWebDataService::NotifyDatabaseLoadedOnUIThread() { |
| 168 // Notify that the database has been initialized. |
| 169 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnUIThread, |
| 170 ui_observer_list_, |
| 171 WebDatabaseLoaded()); |
| 160 } | 172 } |
| 161 | 173 |
| 162 //////////////////////////////////////////////////////////////////////////////// | 174 //////////////////////////////////////////////////////////////////////////////// |
| 163 // | 175 // |
| 164 // Autofill implementation. | 176 // Autofill implementation. |
| 165 // | 177 // |
| 166 //////////////////////////////////////////////////////////////////////////////// | 178 //////////////////////////////////////////////////////////////////////////////// |
| 167 | 179 |
| 168 WebDatabase::State AutofillWebDataService::AddFormElementsImpl( | 180 WebDatabase::State AutofillWebDataService::AddFormElementsImpl( |
| 169 const std::vector<FormFieldData>& fields, WebDatabase* db) { | 181 const std::vector<FormFieldData>& fields, WebDatabase* db) { |
| 170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 182 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 171 AutofillChangeList changes; | 183 AutofillChangeList changes; |
| 172 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues( | 184 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues( |
| 173 fields, &changes)) { | 185 fields, &changes)) { |
| 174 NOTREACHED(); | 186 NOTREACHED(); |
| 175 return WebDatabase::COMMIT_NOT_NEEDED; | 187 return WebDatabase::COMMIT_NOT_NEEDED; |
| 176 } | 188 } |
| 177 | 189 |
| 178 // Post the notifications including the list of affected keys. | 190 // Post the notifications including the list of affected keys. |
| 179 // This is sent here so that work resulting from this notification will be | 191 // This is sent here so that work resulting from this notification will be |
| 180 // done on the DB thread, and not the UI thread. | 192 // done on the DB thread, and not the UI thread. |
| 181 content::NotificationService::current()->Notify( | 193 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
| 182 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 194 db_observer_list_, |
| 183 content::Source<AutofillWebDataService>(this), | 195 AutofillEntriesChanged(changes)); |
| 184 content::Details<AutofillChangeList>(&changes)); | |
| 185 | 196 |
| 186 return WebDatabase::COMMIT_NEEDED; | 197 return WebDatabase::COMMIT_NEEDED; |
| 187 } | 198 } |
| 188 | 199 |
| 189 scoped_ptr<WDTypedResult> | 200 scoped_ptr<WDTypedResult> |
| 190 AutofillWebDataService::GetFormValuesForElementNameImpl( | 201 AutofillWebDataService::GetFormValuesForElementNameImpl( |
| 191 const string16& name, const string16& prefix, int limit, WebDatabase* db) { | 202 const string16& name, const string16& prefix, int limit, WebDatabase* db) { |
| 192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 193 std::vector<string16> values; | 204 std::vector<string16> values; |
| 194 AutofillTable::FromWebDatabase(db)->GetFormValuesForElementName( | 205 AutofillTable::FromWebDatabase(db)->GetFormValuesForElementName( |
| 195 name, prefix, &values, limit); | 206 name, prefix, &values, limit); |
| 196 return scoped_ptr<WDTypedResult>( | 207 return scoped_ptr<WDTypedResult>( |
| 197 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values)); | 208 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values)); |
| 198 } | 209 } |
| 199 | 210 |
| 200 WebDatabase::State AutofillWebDataService::RemoveFormElementsAddedBetweenImpl( | 211 WebDatabase::State AutofillWebDataService::RemoveFormElementsAddedBetweenImpl( |
| 201 const base::Time& delete_begin, const base::Time& delete_end, | 212 const base::Time& delete_begin, const base::Time& delete_end, |
| 202 WebDatabase* db) { | 213 WebDatabase* db) { |
| 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 204 AutofillChangeList changes; | 215 AutofillChangeList changes; |
| 205 | 216 |
| 206 if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween( | 217 if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween( |
| 207 delete_begin, delete_end, &changes)) { | 218 delete_begin, delete_end, &changes)) { |
| 208 if (!changes.empty()) { | 219 if (!changes.empty()) { |
| 209 // Post the notifications including the list of affected keys. | 220 // Post the notifications including the list of affected keys. |
| 210 // This is sent here so that work resulting from this notification | 221 // This is sent here so that work resulting from this notification |
| 211 // will be done on the DB thread, and not the UI thread. | 222 // will be done on the DB thread, and not the UI thread. |
| 212 content::NotificationService::current()->Notify( | 223 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
| 213 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 224 db_observer_list_, |
| 214 content::Source<AutofillWebDataService>(this), | 225 AutofillEntriesChanged(changes)); |
| 215 content::Details<AutofillChangeList>(&changes)); | |
| 216 } | 226 } |
| 217 return WebDatabase::COMMIT_NEEDED; | 227 return WebDatabase::COMMIT_NEEDED; |
| 218 } | 228 } |
| 219 return WebDatabase::COMMIT_NOT_NEEDED; | 229 return WebDatabase::COMMIT_NOT_NEEDED; |
| 220 } | 230 } |
| 221 | 231 |
| 222 WebDatabase::State AutofillWebDataService::RemoveExpiredFormElementsImpl( | 232 WebDatabase::State AutofillWebDataService::RemoveExpiredFormElementsImpl( |
| 223 WebDatabase* db) { | 233 WebDatabase* db) { |
| 224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 234 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 225 AutofillChangeList changes; | 235 AutofillChangeList changes; |
| 226 | 236 |
| 227 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) { | 237 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) { |
| 228 if (!changes.empty()) { | 238 if (!changes.empty()) { |
| 229 // Post the notifications including the list of affected keys. | 239 // Post the notifications including the list of affected keys. |
| 230 // This is sent here so that work resulting from this notification | 240 // This is sent here so that work resulting from this notification |
| 231 // will be done on the DB thread, and not the UI thread. | 241 // will be done on the DB thread, and not the UI thread. |
| 232 content::NotificationService::current()->Notify( | 242 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
| 233 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 243 db_observer_list_, |
| 234 content::Source<AutofillWebDataService>(this), | 244 AutofillEntriesChanged(changes)); |
| 235 content::Details<AutofillChangeList>(&changes)); | |
| 236 } | 245 } |
| 237 return WebDatabase::COMMIT_NEEDED; | 246 return WebDatabase::COMMIT_NEEDED; |
| 238 } | 247 } |
| 239 return WebDatabase::COMMIT_NOT_NEEDED; | 248 return WebDatabase::COMMIT_NOT_NEEDED; |
| 240 } | 249 } |
| 241 | 250 |
| 242 WebDatabase::State AutofillWebDataService::RemoveFormValueForElementNameImpl( | 251 WebDatabase::State AutofillWebDataService::RemoveFormValueForElementNameImpl( |
| 243 const string16& name, const string16& value, WebDatabase* db) { | 252 const string16& name, const string16& value, WebDatabase* db) { |
| 244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 253 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 245 | 254 |
| 246 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) { | 255 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) { |
| 247 AutofillChangeList changes; | 256 AutofillChangeList changes; |
| 248 changes.push_back(AutofillChange(AutofillChange::REMOVE, | 257 changes.push_back( |
| 249 AutofillKey(name, value))); | 258 AutofillChange(AutofillChange::REMOVE, AutofillKey(name, value))); |
| 250 | 259 |
| 251 // Post the notifications including the list of affected keys. | 260 // Post the notifications including the list of affected keys. |
| 252 content::NotificationService::current()->Notify( | 261 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
| 253 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 262 db_observer_list_, |
| 254 content::Source<AutofillWebDataService>(this), | 263 AutofillEntriesChanged(changes)); |
| 255 content::Details<AutofillChangeList>(&changes)); | |
| 256 | 264 |
| 257 return WebDatabase::COMMIT_NEEDED; | 265 return WebDatabase::COMMIT_NEEDED; |
| 258 } | 266 } |
| 259 return WebDatabase::COMMIT_NOT_NEEDED; | 267 return WebDatabase::COMMIT_NOT_NEEDED; |
| 260 } | 268 } |
| 261 | 269 |
| 262 WebDatabase::State AutofillWebDataService::AddAutofillProfileImpl( | 270 WebDatabase::State AutofillWebDataService::AddAutofillProfileImpl( |
| 263 const AutofillProfile& profile, WebDatabase* db) { | 271 const AutofillProfile& profile, WebDatabase* db) { |
| 264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 272 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 265 if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) { | 273 if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) { |
| 266 NOTREACHED(); | 274 NOTREACHED(); |
| 267 return WebDatabase::COMMIT_NOT_NEEDED; | 275 return WebDatabase::COMMIT_NOT_NEEDED; |
| 268 } | 276 } |
| 269 | 277 |
| 270 // Send GUID-based notification. | 278 // Send GUID-based notification. |
| 271 AutofillProfileChange change(AutofillProfileChange::ADD, | 279 AutofillProfileChange change( |
| 272 profile.guid(), &profile); | 280 AutofillProfileChange::ADD, profile.guid(), &profile); |
| 273 content::NotificationService::current()->Notify( | 281 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
| 274 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 282 db_observer_list_, |
| 275 content::Source<AutofillWebDataService>(this), | 283 AutofillProfileChanged(change)); |
| 276 content::Details<AutofillProfileChange>(&change)); | |
| 277 | 284 |
| 278 return WebDatabase::COMMIT_NEEDED; | 285 return WebDatabase::COMMIT_NEEDED; |
| 279 } | 286 } |
| 280 | 287 |
| 281 WebDatabase::State AutofillWebDataService::UpdateAutofillProfileImpl( | 288 WebDatabase::State AutofillWebDataService::UpdateAutofillProfileImpl( |
| 282 const AutofillProfile& profile, WebDatabase* db) { | 289 const AutofillProfile& profile, WebDatabase* db) { |
| 283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 290 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 284 // Only perform the update if the profile exists. It is currently | 291 // Only perform the update if the profile exists. It is currently |
| 285 // valid to try to update a missing profile. We simply drop the write and | 292 // valid to try to update a missing profile. We simply drop the write and |
| 286 // the caller will detect this on the next refresh. | 293 // the caller will detect this on the next refresh. |
| 287 AutofillProfile* original_profile = NULL; | 294 AutofillProfile* original_profile = NULL; |
| 288 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(), | 295 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(), |
| 289 &original_profile)) { | 296 &original_profile)) { |
| 290 return WebDatabase::COMMIT_NOT_NEEDED; | 297 return WebDatabase::COMMIT_NOT_NEEDED; |
| 291 } | 298 } |
| 292 scoped_ptr<AutofillProfile> scoped_profile(original_profile); | 299 scoped_ptr<AutofillProfile> scoped_profile(original_profile); |
| 293 | 300 |
| 294 if (!AutofillTable::FromWebDatabase(db)->UpdateAutofillProfileMulti( | 301 if (!AutofillTable::FromWebDatabase(db)->UpdateAutofillProfileMulti( |
| 295 profile)) { | 302 profile)) { |
| 296 NOTREACHED(); | 303 NOTREACHED(); |
| 297 return WebDatabase::COMMIT_NEEDED; | 304 return WebDatabase::COMMIT_NEEDED; |
| 298 } | 305 } |
| 299 | 306 |
| 300 // Send GUID-based notification. | 307 // Send GUID-based notification. |
| 301 AutofillProfileChange change(AutofillProfileChange::UPDATE, | 308 AutofillProfileChange change( |
| 302 profile.guid(), &profile); | 309 AutofillProfileChange::UPDATE, profile.guid(), &profile); |
| 303 content::NotificationService::current()->Notify( | 310 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
| 304 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 311 db_observer_list_, |
| 305 content::Source<AutofillWebDataService>(this), | 312 AutofillProfileChanged(change)); |
| 306 content::Details<AutofillProfileChange>(&change)); | |
| 307 | 313 |
| 308 return WebDatabase::COMMIT_NEEDED; | 314 return WebDatabase::COMMIT_NEEDED; |
| 309 } | 315 } |
| 310 | 316 |
| 311 WebDatabase::State AutofillWebDataService::RemoveAutofillProfileImpl( | 317 WebDatabase::State AutofillWebDataService::RemoveAutofillProfileImpl( |
| 312 const std::string& guid, WebDatabase* db) { | 318 const std::string& guid, WebDatabase* db) { |
| 313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 319 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 314 AutofillProfile* profile = NULL; | 320 AutofillProfile* profile = NULL; |
| 315 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) { | 321 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) { |
| 316 NOTREACHED(); | 322 NOTREACHED(); |
| 317 return WebDatabase::COMMIT_NOT_NEEDED; | 323 return WebDatabase::COMMIT_NOT_NEEDED; |
| 318 } | 324 } |
| 319 scoped_ptr<AutofillProfile> scoped_profile(profile); | 325 scoped_ptr<AutofillProfile> scoped_profile(profile); |
| 320 | 326 |
| 321 if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) { | 327 if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) { |
| 322 NOTREACHED(); | 328 NOTREACHED(); |
| 323 return WebDatabase::COMMIT_NOT_NEEDED; | 329 return WebDatabase::COMMIT_NOT_NEEDED; |
| 324 } | 330 } |
| 325 | 331 |
| 326 // Send GUID-based notification. | 332 // Send GUID-based notification. |
| 327 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); | 333 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); |
| 328 content::NotificationService::current()->Notify( | 334 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
| 329 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 335 db_observer_list_, |
| 330 content::Source<AutofillWebDataService>(this), | 336 AutofillProfileChanged(change)); |
| 331 content::Details<AutofillProfileChange>(&change)); | |
| 332 | 337 |
| 333 return WebDatabase::COMMIT_NEEDED; | 338 return WebDatabase::COMMIT_NEEDED; |
| 334 } | 339 } |
| 335 | 340 |
| 336 scoped_ptr<WDTypedResult> AutofillWebDataService::GetAutofillProfilesImpl( | 341 scoped_ptr<WDTypedResult> AutofillWebDataService::GetAutofillProfilesImpl( |
| 337 WebDatabase* db) { | 342 WebDatabase* db) { |
| 338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 343 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 339 std::vector<AutofillProfile*> profiles; | 344 std::vector<AutofillProfile*> profiles; |
| 340 AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles); | 345 AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles); |
| 341 return scoped_ptr<WDTypedResult>( | 346 return scoped_ptr<WDTypedResult>( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards); | 398 AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards); |
| 394 return scoped_ptr<WDTypedResult>( | 399 return scoped_ptr<WDTypedResult>( |
| 395 new WDDestroyableResult<std::vector<CreditCard*> >( | 400 new WDDestroyableResult<std::vector<CreditCard*> >( |
| 396 AUTOFILL_CREDITCARDS_RESULT, | 401 AUTOFILL_CREDITCARDS_RESULT, |
| 397 credit_cards, | 402 credit_cards, |
| 398 base::Bind(&AutofillWebDataService::DestroyAutofillCreditCardResult, | 403 base::Bind(&AutofillWebDataService::DestroyAutofillCreditCardResult, |
| 399 base::Unretained(this)))); | 404 base::Unretained(this)))); |
| 400 } | 405 } |
| 401 | 406 |
| 402 WebDatabase::State | 407 WebDatabase::State |
| 403 AutofillWebDataService::RemoveAutofillDataModifiedBetweenImpl( | 408 AutofillWebDataService::RemoveAutofillDataModifiedBetweenImpl( |
| 404 const base::Time& delete_begin, const base::Time& delete_end, | 409 const base::Time& delete_begin, |
| 410 const base::Time& delete_end, |
| 405 WebDatabase* db) { | 411 WebDatabase* db) { |
| 412 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 406 std::vector<std::string> profile_guids; | 413 std::vector<std::string> profile_guids; |
| 407 std::vector<std::string> credit_card_guids; | 414 std::vector<std::string> credit_card_guids; |
| 408 if (AutofillTable::FromWebDatabase(db)-> | 415 if (AutofillTable::FromWebDatabase(db)->RemoveAutofillDataModifiedBetween( |
| 409 RemoveAutofillDataModifiedBetween( | |
| 410 delete_begin, | 416 delete_begin, |
| 411 delete_end, | 417 delete_end, |
| 412 &profile_guids, | 418 &profile_guids, |
| 413 &credit_card_guids)) { | 419 &credit_card_guids)) { |
| 414 for (std::vector<std::string>::iterator iter = profile_guids.begin(); | 420 for (std::vector<std::string>::iterator iter = profile_guids.begin(); |
| 415 iter != profile_guids.end(); ++iter) { | 421 iter != profile_guids.end(); ++iter) { |
| 416 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, | 422 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, NULL); |
| 417 NULL); | 423 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnDBThread, |
| 418 content::NotificationService::current()->Notify( | 424 db_observer_list_, |
| 419 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 425 AutofillProfileChanged(change)); |
| 420 content::Source<AutofillWebDataService>(this), | |
| 421 content::Details<AutofillProfileChange>(&change)); | |
| 422 } | 426 } |
| 423 // Note: It is the caller's responsibility to post notifications for any | 427 // Note: It is the caller's responsibility to post notifications for any |
| 424 // changes, e.g. by calling the Refresh() method of PersonalDataManager. | 428 // changes, e.g. by calling the Refresh() method of PersonalDataManager. |
| 425 return WebDatabase::COMMIT_NEEDED; | 429 return WebDatabase::COMMIT_NEEDED; |
| 426 } | 430 } |
| 427 return WebDatabase::COMMIT_NOT_NEEDED; | 431 return WebDatabase::COMMIT_NOT_NEEDED; |
| 428 } | 432 } |
| 429 | 433 |
| 430 void AutofillWebDataService::DestroyAutofillProfileResult( | 434 void AutofillWebDataService::DestroyAutofillProfileResult( |
| 431 const WDTypedResult* result) { | 435 const WDTypedResult* result) { |
| 432 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); | 436 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); |
| 433 const WDResult<std::vector<AutofillProfile*> >* r = | 437 const WDResult<std::vector<AutofillProfile*> >* r = |
| 434 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); | 438 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); |
| 435 std::vector<AutofillProfile*> profiles = r->GetValue(); | 439 std::vector<AutofillProfile*> profiles = r->GetValue(); |
| 436 STLDeleteElements(&profiles); | 440 STLDeleteElements(&profiles); |
| 437 } | 441 } |
| 438 | 442 |
| 439 void AutofillWebDataService::DestroyAutofillCreditCardResult( | 443 void AutofillWebDataService::DestroyAutofillCreditCardResult( |
| 440 const WDTypedResult* result) { | 444 const WDTypedResult* result) { |
| 441 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); | 445 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); |
| 442 const WDResult<std::vector<CreditCard*> >* r = | 446 const WDResult<std::vector<CreditCard*> >* r = |
| 443 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); | 447 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); |
| 444 | 448 |
| 445 std::vector<CreditCard*> credit_cards = r->GetValue(); | 449 std::vector<CreditCard*> credit_cards = r->GetValue(); |
| 446 STLDeleteElements(&credit_cards); | 450 STLDeleteElements(&credit_cards); |
| 447 } | 451 } |
| 452 |
| 453 void AutofillWebDataService::NotifyAutofillMultipleChangedOnUIThread() { |
| 454 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 455 FOR_EACH_OBSERVER(AutofillWebDataServiceObserverOnUIThread, |
| 456 ui_observer_list_, |
| 457 AutofillMultipleChanged()); |
| 458 } |
| OLD | NEW |