| 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_impl.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/web_database_service.h" | 12 #include "chrome/browser/webdata/web_database_service.h" |
| 13 #include "chrome/common/chrome_notification_types.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" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 scoped_refptr<WebDatabaseService> wdbs, | 56 scoped_refptr<WebDatabaseService> wdbs, |
| 57 const ProfileErrorCallback& callback) | 57 const ProfileErrorCallback& callback) |
| 58 : WebDataServiceBase(wdbs, callback) { | 58 : WebDataServiceBase(wdbs, callback) { |
| 59 } | 59 } |
| 60 | 60 |
| 61 AutofillWebDataService::AutofillWebDataService() | 61 AutofillWebDataService::AutofillWebDataService() |
| 62 : WebDataServiceBase(NULL, | 62 : WebDataServiceBase(NULL, |
| 63 WebDataServiceBase::ProfileErrorCallback()) { | 63 WebDataServiceBase::ProfileErrorCallback()) { |
| 64 } | 64 } |
| 65 | 65 |
| 66 AutofillWebDataServiceImpl::AutofillWebDataServiceImpl( | 66 content::NotificationSource AutofillWebDataService::GetNotificationSource() { |
| 67 scoped_refptr<WebDatabaseService> wdbs, | |
| 68 const ProfileErrorCallback& callback) | |
| 69 : AutofillWebDataService(wdbs, callback) { | |
| 70 } | |
| 71 | |
| 72 content::NotificationSource | |
| 73 AutofillWebDataServiceImpl::GetNotificationSource() { | |
| 74 return content::Source<AutofillWebDataService>(this); | 67 return content::Source<AutofillWebDataService>(this); |
| 75 } | 68 } |
| 76 | 69 |
| 77 void AutofillWebDataServiceImpl::AddFormFields( | 70 void AutofillWebDataService::AddFormFields( |
| 78 const std::vector<FormFieldData>& fields) { | 71 const std::vector<FormFieldData>& fields) { |
| 79 wdbs_->ScheduleDBTask(FROM_HERE, | 72 wdbs_->ScheduleDBTask(FROM_HERE, |
| 80 Bind(&AutofillWebDataServiceImpl::AddFormElementsImpl, this, fields)); | 73 Bind(&AutofillWebDataService::AddFormElementsImpl, this, fields)); |
| 81 } | 74 } |
| 82 | 75 |
| 83 WebDataServiceBase::Handle | 76 WebDataServiceBase::Handle AutofillWebDataService::GetFormValuesForElementName( |
| 84 AutofillWebDataServiceImpl::GetFormValuesForElementName( | |
| 85 const string16& name, const string16& prefix, int limit, | 77 const string16& name, const string16& prefix, int limit, |
| 86 WebDataServiceConsumer* consumer) { | 78 WebDataServiceConsumer* consumer) { |
| 87 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, | 79 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, |
| 88 Bind(&AutofillWebDataServiceImpl::GetFormValuesForElementNameImpl, | 80 Bind(&AutofillWebDataService::GetFormValuesForElementNameImpl, |
| 89 this, name, prefix, limit), consumer); | 81 this, name, prefix, limit), consumer); |
| 90 } | 82 } |
| 91 | 83 |
| 92 void AutofillWebDataServiceImpl::RemoveFormElementsAddedBetween( | 84 void AutofillWebDataService::RemoveFormElementsAddedBetween( |
| 93 const Time& delete_begin, const Time& delete_end) { | 85 const Time& delete_begin, const Time& delete_end) { |
| 94 wdbs_->ScheduleDBTask(FROM_HERE, | 86 wdbs_->ScheduleDBTask(FROM_HERE, |
| 95 Bind(&AutofillWebDataServiceImpl::RemoveFormElementsAddedBetweenImpl, | 87 Bind(&AutofillWebDataService::RemoveFormElementsAddedBetweenImpl, |
| 96 this, delete_begin, delete_end)); | 88 this, delete_begin, delete_end)); |
| 97 } | 89 } |
| 98 | 90 |
| 99 void AutofillWebDataServiceImpl::RemoveExpiredFormElements() { | 91 void AutofillWebDataService::RemoveExpiredFormElements() { |
| 100 wdbs_->ScheduleDBTask(FROM_HERE, | 92 wdbs_->ScheduleDBTask(FROM_HERE, |
| 101 Bind(&AutofillWebDataServiceImpl::RemoveExpiredFormElementsImpl, this)); | 93 Bind(&AutofillWebDataService::RemoveExpiredFormElementsImpl, this)); |
| 102 } | 94 } |
| 103 | 95 |
| 104 void AutofillWebDataServiceImpl::RemoveFormValueForElementName( | 96 void AutofillWebDataService::RemoveFormValueForElementName( |
| 105 const string16& name, const string16& value) { | 97 const string16& name, const string16& value) { |
| 106 wdbs_->ScheduleDBTask(FROM_HERE, | 98 wdbs_->ScheduleDBTask(FROM_HERE, |
| 107 Bind(&AutofillWebDataServiceImpl::RemoveFormValueForElementNameImpl, | 99 Bind(&AutofillWebDataService::RemoveFormValueForElementNameImpl, |
| 108 this, name, value)); | 100 this, name, value)); |
| 109 } | 101 } |
| 110 | 102 |
| 111 void AutofillWebDataServiceImpl::AddAutofillProfile( | 103 void AutofillWebDataService::AddAutofillProfile( |
| 112 const AutofillProfile& profile) { | 104 const AutofillProfile& profile) { |
| 113 wdbs_->ScheduleDBTask(FROM_HERE, | 105 wdbs_->ScheduleDBTask(FROM_HERE, |
| 114 Bind(&AutofillWebDataServiceImpl::AddAutofillProfileImpl, this, profile)); | 106 Bind(&AutofillWebDataService::AddAutofillProfileImpl, this, profile)); |
| 115 } | 107 } |
| 116 | 108 |
| 117 void AutofillWebDataServiceImpl::UpdateAutofillProfile( | 109 void AutofillWebDataService::UpdateAutofillProfile( |
| 118 const AutofillProfile& profile) { | 110 const AutofillProfile& profile) { |
| 119 wdbs_->ScheduleDBTask(FROM_HERE, | 111 wdbs_->ScheduleDBTask(FROM_HERE, |
| 120 Bind(&AutofillWebDataServiceImpl::UpdateAutofillProfileImpl, | 112 Bind(&AutofillWebDataService::UpdateAutofillProfileImpl, |
| 121 this, profile)); | 113 this, profile)); |
| 122 } | 114 } |
| 123 | 115 |
| 124 void AutofillWebDataServiceImpl::RemoveAutofillProfile( | 116 void AutofillWebDataService::RemoveAutofillProfile( |
| 125 const std::string& guid) { | 117 const std::string& guid) { |
| 126 wdbs_->ScheduleDBTask(FROM_HERE, | 118 wdbs_->ScheduleDBTask(FROM_HERE, |
| 127 Bind(&AutofillWebDataServiceImpl::RemoveAutofillProfileImpl, this, guid)); | 119 Bind(&AutofillWebDataService::RemoveAutofillProfileImpl, this, guid)); |
| 128 } | 120 } |
| 129 | 121 |
| 130 WebDataServiceBase::Handle AutofillWebDataServiceImpl::GetAutofillProfiles( | 122 WebDataServiceBase::Handle AutofillWebDataService::GetAutofillProfiles( |
| 131 WebDataServiceConsumer* consumer) { | 123 WebDataServiceConsumer* consumer) { |
| 132 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, | 124 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, |
| 133 Bind(&AutofillWebDataServiceImpl::GetAutofillProfilesImpl, this), | 125 Bind(&AutofillWebDataService::GetAutofillProfilesImpl, this), |
| 134 consumer); | 126 consumer); |
| 135 } | 127 } |
| 136 | 128 |
| 137 void AutofillWebDataServiceImpl::AddCreditCard(const CreditCard& credit_card) { | 129 void AutofillWebDataService::AddCreditCard(const CreditCard& credit_card) { |
| 138 wdbs_->ScheduleDBTask(FROM_HERE, | 130 wdbs_->ScheduleDBTask(FROM_HERE, |
| 139 Bind(&AutofillWebDataServiceImpl::AddCreditCardImpl, this, credit_card)); | 131 Bind(&AutofillWebDataService::AddCreditCardImpl, this, credit_card)); |
| 140 } | 132 } |
| 141 | 133 |
| 142 void AutofillWebDataServiceImpl::UpdateCreditCard( | 134 void AutofillWebDataService::UpdateCreditCard( |
| 143 const CreditCard& credit_card) { | 135 const CreditCard& credit_card) { |
| 144 wdbs_->ScheduleDBTask(FROM_HERE, | 136 wdbs_->ScheduleDBTask(FROM_HERE, |
| 145 Bind(&AutofillWebDataServiceImpl::UpdateCreditCardImpl, this, | 137 Bind(&AutofillWebDataService::UpdateCreditCardImpl, this, |
| 146 credit_card)); | 138 credit_card)); |
| 147 } | 139 } |
| 148 | 140 |
| 149 void AutofillWebDataServiceImpl::RemoveCreditCard(const std::string& guid) { | 141 void AutofillWebDataService::RemoveCreditCard(const std::string& guid) { |
| 150 wdbs_->ScheduleDBTask(FROM_HERE, | 142 wdbs_->ScheduleDBTask(FROM_HERE, |
| 151 Bind(&AutofillWebDataServiceImpl::RemoveCreditCardImpl, this, guid)); | 143 Bind(&AutofillWebDataService::RemoveCreditCardImpl, this, guid)); |
| 152 } | 144 } |
| 153 | 145 |
| 154 AutofillWebDataServiceImpl::Handle AutofillWebDataServiceImpl::GetCreditCards( | 146 WebDataServiceBase::Handle AutofillWebDataService::GetCreditCards( |
| 155 WebDataServiceConsumer* consumer) { | 147 WebDataServiceConsumer* consumer) { |
| 156 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, | 148 return wdbs_->ScheduleDBTaskWithResult(FROM_HERE, |
| 157 Bind(&AutofillWebDataServiceImpl::GetCreditCardsImpl, this), consumer); | 149 Bind(&AutofillWebDataService::GetCreditCardsImpl, this), consumer); |
| 158 } | 150 } |
| 159 | 151 |
| 160 void AutofillWebDataServiceImpl::RemoveAutofillDataModifiedBetween( | 152 void AutofillWebDataService::RemoveAutofillDataModifiedBetween( |
| 161 const Time& delete_begin, const Time& delete_end) { | 153 const Time& delete_begin, const Time& delete_end) { |
| 162 wdbs_->ScheduleDBTask(FROM_HERE, Bind( | 154 wdbs_->ScheduleDBTask(FROM_HERE, Bind( |
| 163 &AutofillWebDataServiceImpl::RemoveAutofillDataModifiedBetweenImpl, | 155 &AutofillWebDataService::RemoveAutofillDataModifiedBetweenImpl, |
| 164 this, delete_begin, delete_end)); | 156 this, delete_begin, delete_end)); |
| 165 } | 157 } |
| 166 | 158 |
| 167 AutofillWebDataServiceImpl::~AutofillWebDataServiceImpl() { | 159 AutofillWebDataService::~AutofillWebDataService() { |
| 168 } | 160 } |
| 169 | 161 |
| 170 //////////////////////////////////////////////////////////////////////////////// | 162 //////////////////////////////////////////////////////////////////////////////// |
| 171 // | 163 // |
| 172 // Autofill implementation. | 164 // Autofill implementation. |
| 173 // | 165 // |
| 174 //////////////////////////////////////////////////////////////////////////////// | 166 //////////////////////////////////////////////////////////////////////////////// |
| 175 | 167 |
| 176 WebDatabase::State AutofillWebDataServiceImpl::AddFormElementsImpl( | 168 WebDatabase::State AutofillWebDataService::AddFormElementsImpl( |
| 177 const std::vector<FormFieldData>& fields, WebDatabase* db) { | 169 const std::vector<FormFieldData>& fields, WebDatabase* db) { |
| 178 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 179 AutofillChangeList changes; | 171 AutofillChangeList changes; |
| 180 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues( | 172 if (!AutofillTable::FromWebDatabase(db)->AddFormFieldValues( |
| 181 fields, &changes)) { | 173 fields, &changes)) { |
| 182 NOTREACHED(); | 174 NOTREACHED(); |
| 183 return WebDatabase::COMMIT_NOT_NEEDED; | 175 return WebDatabase::COMMIT_NOT_NEEDED; |
| 184 } | 176 } |
| 185 | 177 |
| 186 // Post the notifications including the list of affected keys. | 178 // Post the notifications including the list of affected keys. |
| 187 // This is sent here so that work resulting from this notification will be | 179 // This is sent here so that work resulting from this notification will be |
| 188 // done on the DB thread, and not the UI thread. | 180 // done on the DB thread, and not the UI thread. |
| 189 content::NotificationService::current()->Notify( | 181 content::NotificationService::current()->Notify( |
| 190 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 182 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 191 content::Source<AutofillWebDataService>(this), | 183 content::Source<AutofillWebDataService>(this), |
| 192 content::Details<AutofillChangeList>(&changes)); | 184 content::Details<AutofillChangeList>(&changes)); |
| 193 | 185 |
| 194 return WebDatabase::COMMIT_NEEDED; | 186 return WebDatabase::COMMIT_NEEDED; |
| 195 } | 187 } |
| 196 | 188 |
| 197 scoped_ptr<WDTypedResult> | 189 scoped_ptr<WDTypedResult> |
| 198 AutofillWebDataServiceImpl::GetFormValuesForElementNameImpl( | 190 AutofillWebDataService::GetFormValuesForElementNameImpl( |
| 199 const string16& name, const string16& prefix, int limit, WebDatabase* db) { | 191 const string16& name, const string16& prefix, int limit, WebDatabase* db) { |
| 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 192 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 201 std::vector<string16> values; | 193 std::vector<string16> values; |
| 202 AutofillTable::FromWebDatabase(db)->GetFormValuesForElementName( | 194 AutofillTable::FromWebDatabase(db)->GetFormValuesForElementName( |
| 203 name, prefix, &values, limit); | 195 name, prefix, &values, limit); |
| 204 return scoped_ptr<WDTypedResult>( | 196 return scoped_ptr<WDTypedResult>( |
| 205 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values)); | 197 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values)); |
| 206 } | 198 } |
| 207 | 199 |
| 208 WebDatabase::State | 200 WebDatabase::State AutofillWebDataService::RemoveFormElementsAddedBetweenImpl( |
| 209 AutofillWebDataServiceImpl::RemoveFormElementsAddedBetweenImpl( | |
| 210 const base::Time& delete_begin, const base::Time& delete_end, | 201 const base::Time& delete_begin, const base::Time& delete_end, |
| 211 WebDatabase* db) { | 202 WebDatabase* db) { |
| 212 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 203 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 213 AutofillChangeList changes; | 204 AutofillChangeList changes; |
| 214 | 205 |
| 215 if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween( | 206 if (AutofillTable::FromWebDatabase(db)->RemoveFormElementsAddedBetween( |
| 216 delete_begin, delete_end, &changes)) { | 207 delete_begin, delete_end, &changes)) { |
| 217 if (!changes.empty()) { | 208 if (!changes.empty()) { |
| 218 // Post the notifications including the list of affected keys. | 209 // Post the notifications including the list of affected keys. |
| 219 // This is sent here so that work resulting from this notification | 210 // This is sent here so that work resulting from this notification |
| 220 // will be done on the DB thread, and not the UI thread. | 211 // will be done on the DB thread, and not the UI thread. |
| 221 content::NotificationService::current()->Notify( | 212 content::NotificationService::current()->Notify( |
| 222 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 213 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 223 content::Source<AutofillWebDataService>(this), | 214 content::Source<AutofillWebDataService>(this), |
| 224 content::Details<AutofillChangeList>(&changes)); | 215 content::Details<AutofillChangeList>(&changes)); |
| 225 } | 216 } |
| 226 return WebDatabase::COMMIT_NEEDED; | 217 return WebDatabase::COMMIT_NEEDED; |
| 227 } | 218 } |
| 228 return WebDatabase::COMMIT_NOT_NEEDED; | 219 return WebDatabase::COMMIT_NOT_NEEDED; |
| 229 } | 220 } |
| 230 | 221 |
| 231 WebDatabase::State AutofillWebDataServiceImpl::RemoveExpiredFormElementsImpl( | 222 WebDatabase::State AutofillWebDataService::RemoveExpiredFormElementsImpl( |
| 232 WebDatabase* db) { | 223 WebDatabase* db) { |
| 233 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 234 AutofillChangeList changes; | 225 AutofillChangeList changes; |
| 235 | 226 |
| 236 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) { | 227 if (AutofillTable::FromWebDatabase(db)->RemoveExpiredFormElements(&changes)) { |
| 237 if (!changes.empty()) { | 228 if (!changes.empty()) { |
| 238 // Post the notifications including the list of affected keys. | 229 // Post the notifications including the list of affected keys. |
| 239 // This is sent here so that work resulting from this notification | 230 // This is sent here so that work resulting from this notification |
| 240 // will be done on the DB thread, and not the UI thread. | 231 // will be done on the DB thread, and not the UI thread. |
| 241 content::NotificationService::current()->Notify( | 232 content::NotificationService::current()->Notify( |
| 242 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 233 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 243 content::Source<AutofillWebDataService>(this), | 234 content::Source<AutofillWebDataService>(this), |
| 244 content::Details<AutofillChangeList>(&changes)); | 235 content::Details<AutofillChangeList>(&changes)); |
| 245 } | 236 } |
| 246 return WebDatabase::COMMIT_NEEDED; | 237 return WebDatabase::COMMIT_NEEDED; |
| 247 } | 238 } |
| 248 return WebDatabase::COMMIT_NOT_NEEDED; | 239 return WebDatabase::COMMIT_NOT_NEEDED; |
| 249 } | 240 } |
| 250 | 241 |
| 251 WebDatabase::State | 242 WebDatabase::State AutofillWebDataService::RemoveFormValueForElementNameImpl( |
| 252 AutofillWebDataServiceImpl::RemoveFormValueForElementNameImpl( | |
| 253 const string16& name, const string16& value, WebDatabase* db) { | 243 const string16& name, const string16& value, WebDatabase* db) { |
| 254 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 244 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 255 | 245 |
| 256 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) { | 246 if (AutofillTable::FromWebDatabase(db)->RemoveFormElement(name, value)) { |
| 257 AutofillChangeList changes; | 247 AutofillChangeList changes; |
| 258 changes.push_back(AutofillChange(AutofillChange::REMOVE, | 248 changes.push_back(AutofillChange(AutofillChange::REMOVE, |
| 259 AutofillKey(name, value))); | 249 AutofillKey(name, value))); |
| 260 | 250 |
| 261 // Post the notifications including the list of affected keys. | 251 // Post the notifications including the list of affected keys. |
| 262 content::NotificationService::current()->Notify( | 252 content::NotificationService::current()->Notify( |
| 263 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 253 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 264 content::Source<AutofillWebDataService>(this), | 254 content::Source<AutofillWebDataService>(this), |
| 265 content::Details<AutofillChangeList>(&changes)); | 255 content::Details<AutofillChangeList>(&changes)); |
| 266 | 256 |
| 267 return WebDatabase::COMMIT_NEEDED; | 257 return WebDatabase::COMMIT_NEEDED; |
| 268 } | 258 } |
| 269 return WebDatabase::COMMIT_NOT_NEEDED; | 259 return WebDatabase::COMMIT_NOT_NEEDED; |
| 270 } | 260 } |
| 271 | 261 |
| 272 WebDatabase::State AutofillWebDataServiceImpl::AddAutofillProfileImpl( | 262 WebDatabase::State AutofillWebDataService::AddAutofillProfileImpl( |
| 273 const AutofillProfile& profile, WebDatabase* db) { | 263 const AutofillProfile& profile, WebDatabase* db) { |
| 274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 264 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 275 if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) { | 265 if (!AutofillTable::FromWebDatabase(db)->AddAutofillProfile(profile)) { |
| 276 NOTREACHED(); | 266 NOTREACHED(); |
| 277 return WebDatabase::COMMIT_NOT_NEEDED; | 267 return WebDatabase::COMMIT_NOT_NEEDED; |
| 278 } | 268 } |
| 279 | 269 |
| 280 // Send GUID-based notification. | 270 // Send GUID-based notification. |
| 281 AutofillProfileChange change(AutofillProfileChange::ADD, | 271 AutofillProfileChange change(AutofillProfileChange::ADD, |
| 282 profile.guid(), &profile); | 272 profile.guid(), &profile); |
| 283 content::NotificationService::current()->Notify( | 273 content::NotificationService::current()->Notify( |
| 284 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 274 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 285 content::Source<AutofillWebDataService>(this), | 275 content::Source<AutofillWebDataService>(this), |
| 286 content::Details<AutofillProfileChange>(&change)); | 276 content::Details<AutofillProfileChange>(&change)); |
| 287 | 277 |
| 288 return WebDatabase::COMMIT_NEEDED; | 278 return WebDatabase::COMMIT_NEEDED; |
| 289 } | 279 } |
| 290 | 280 |
| 291 WebDatabase::State AutofillWebDataServiceImpl::UpdateAutofillProfileImpl( | 281 WebDatabase::State AutofillWebDataService::UpdateAutofillProfileImpl( |
| 292 const AutofillProfile& profile, WebDatabase* db) { | 282 const AutofillProfile& profile, WebDatabase* db) { |
| 293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 283 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 294 // Only perform the update if the profile exists. It is currently | 284 // Only perform the update if the profile exists. It is currently |
| 295 // valid to try to update a missing profile. We simply drop the write and | 285 // valid to try to update a missing profile. We simply drop the write and |
| 296 // the caller will detect this on the next refresh. | 286 // the caller will detect this on the next refresh. |
| 297 AutofillProfile* original_profile = NULL; | 287 AutofillProfile* original_profile = NULL; |
| 298 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(), | 288 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(profile.guid(), |
| 299 &original_profile)) { | 289 &original_profile)) { |
| 300 return WebDatabase::COMMIT_NOT_NEEDED; | 290 return WebDatabase::COMMIT_NOT_NEEDED; |
| 301 } | 291 } |
| 302 scoped_ptr<AutofillProfile> scoped_profile(original_profile); | 292 scoped_ptr<AutofillProfile> scoped_profile(original_profile); |
| 303 | 293 |
| 304 if (!AutofillTable::FromWebDatabase(db)->UpdateAutofillProfileMulti( | 294 if (!AutofillTable::FromWebDatabase(db)->UpdateAutofillProfileMulti( |
| 305 profile)) { | 295 profile)) { |
| 306 NOTREACHED(); | 296 NOTREACHED(); |
| 307 return WebDatabase::COMMIT_NEEDED; | 297 return WebDatabase::COMMIT_NEEDED; |
| 308 } | 298 } |
| 309 | 299 |
| 310 // Send GUID-based notification. | 300 // Send GUID-based notification. |
| 311 AutofillProfileChange change(AutofillProfileChange::UPDATE, | 301 AutofillProfileChange change(AutofillProfileChange::UPDATE, |
| 312 profile.guid(), &profile); | 302 profile.guid(), &profile); |
| 313 content::NotificationService::current()->Notify( | 303 content::NotificationService::current()->Notify( |
| 314 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 304 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 315 content::Source<AutofillWebDataService>(this), | 305 content::Source<AutofillWebDataService>(this), |
| 316 content::Details<AutofillProfileChange>(&change)); | 306 content::Details<AutofillProfileChange>(&change)); |
| 317 | 307 |
| 318 return WebDatabase::COMMIT_NEEDED; | 308 return WebDatabase::COMMIT_NEEDED; |
| 319 } | 309 } |
| 320 | 310 |
| 321 WebDatabase::State AutofillWebDataServiceImpl::RemoveAutofillProfileImpl( | 311 WebDatabase::State AutofillWebDataService::RemoveAutofillProfileImpl( |
| 322 const std::string& guid, WebDatabase* db) { | 312 const std::string& guid, WebDatabase* db) { |
| 323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 313 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 324 AutofillProfile* profile = NULL; | 314 AutofillProfile* profile = NULL; |
| 325 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) { | 315 if (!AutofillTable::FromWebDatabase(db)->GetAutofillProfile(guid, &profile)) { |
| 326 NOTREACHED(); | 316 NOTREACHED(); |
| 327 return WebDatabase::COMMIT_NOT_NEEDED; | 317 return WebDatabase::COMMIT_NOT_NEEDED; |
| 328 } | 318 } |
| 329 scoped_ptr<AutofillProfile> scoped_profile(profile); | 319 scoped_ptr<AutofillProfile> scoped_profile(profile); |
| 330 | 320 |
| 331 if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) { | 321 if (!AutofillTable::FromWebDatabase(db)->RemoveAutofillProfile(guid)) { |
| 332 NOTREACHED(); | 322 NOTREACHED(); |
| 333 return WebDatabase::COMMIT_NOT_NEEDED; | 323 return WebDatabase::COMMIT_NOT_NEEDED; |
| 334 } | 324 } |
| 335 | 325 |
| 336 // Send GUID-based notification. | 326 // Send GUID-based notification. |
| 337 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); | 327 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); |
| 338 content::NotificationService::current()->Notify( | 328 content::NotificationService::current()->Notify( |
| 339 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 329 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 340 content::Source<AutofillWebDataService>(this), | 330 content::Source<AutofillWebDataService>(this), |
| 341 content::Details<AutofillProfileChange>(&change)); | 331 content::Details<AutofillProfileChange>(&change)); |
| 342 | 332 |
| 343 return WebDatabase::COMMIT_NEEDED; | 333 return WebDatabase::COMMIT_NEEDED; |
| 344 } | 334 } |
| 345 | 335 |
| 346 scoped_ptr<WDTypedResult> AutofillWebDataServiceImpl::GetAutofillProfilesImpl( | 336 scoped_ptr<WDTypedResult> AutofillWebDataService::GetAutofillProfilesImpl( |
| 347 WebDatabase* db) { | 337 WebDatabase* db) { |
| 348 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 338 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 349 std::vector<AutofillProfile*> profiles; | 339 std::vector<AutofillProfile*> profiles; |
| 350 AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles); | 340 AutofillTable::FromWebDatabase(db)->GetAutofillProfiles(&profiles); |
| 351 return scoped_ptr<WDTypedResult>( | 341 return scoped_ptr<WDTypedResult>( |
| 352 new WDDestroyableResult<std::vector<AutofillProfile*> >( | 342 new WDDestroyableResult<std::vector<AutofillProfile*> >( |
| 353 AUTOFILL_PROFILES_RESULT, | 343 AUTOFILL_PROFILES_RESULT, |
| 354 profiles, | 344 profiles, |
| 355 base::Bind(&AutofillWebDataServiceImpl::DestroyAutofillProfileResult, | 345 base::Bind(&AutofillWebDataService::DestroyAutofillProfileResult, |
| 356 base::Unretained(this)))); | 346 base::Unretained(this)))); |
| 357 } | 347 } |
| 358 | 348 |
| 359 WebDatabase::State AutofillWebDataServiceImpl::AddCreditCardImpl( | 349 WebDatabase::State AutofillWebDataService::AddCreditCardImpl( |
| 360 const CreditCard& credit_card, WebDatabase* db) { | 350 const CreditCard& credit_card, WebDatabase* db) { |
| 361 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 362 if (!AutofillTable::FromWebDatabase(db)->AddCreditCard(credit_card)) { | 352 if (!AutofillTable::FromWebDatabase(db)->AddCreditCard(credit_card)) { |
| 363 NOTREACHED(); | 353 NOTREACHED(); |
| 364 return WebDatabase::COMMIT_NOT_NEEDED; | 354 return WebDatabase::COMMIT_NOT_NEEDED; |
| 365 } | 355 } |
| 366 | 356 |
| 367 return WebDatabase::COMMIT_NEEDED; | 357 return WebDatabase::COMMIT_NEEDED; |
| 368 } | 358 } |
| 369 | 359 |
| 370 WebDatabase::State AutofillWebDataServiceImpl::UpdateCreditCardImpl( | 360 WebDatabase::State AutofillWebDataService::UpdateCreditCardImpl( |
| 371 const CreditCard& credit_card, WebDatabase* db) { | 361 const CreditCard& credit_card, WebDatabase* db) { |
| 372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 362 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 373 // It is currently valid to try to update a missing profile. We simply drop | 363 // It is currently valid to try to update a missing profile. We simply drop |
| 374 // the write and the caller will detect this on the next refresh. | 364 // the write and the caller will detect this on the next refresh. |
| 375 CreditCard* original_credit_card = NULL; | 365 CreditCard* original_credit_card = NULL; |
| 376 if (!AutofillTable::FromWebDatabase(db)->GetCreditCard(credit_card.guid(), | 366 if (!AutofillTable::FromWebDatabase(db)->GetCreditCard(credit_card.guid(), |
| 377 &original_credit_card)) { | 367 &original_credit_card)) { |
| 378 return WebDatabase::COMMIT_NOT_NEEDED; | 368 return WebDatabase::COMMIT_NOT_NEEDED; |
| 379 } | 369 } |
| 380 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); | 370 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); |
| 381 | 371 |
| 382 if (!AutofillTable::FromWebDatabase(db)->UpdateCreditCard(credit_card)) { | 372 if (!AutofillTable::FromWebDatabase(db)->UpdateCreditCard(credit_card)) { |
| 383 NOTREACHED(); | 373 NOTREACHED(); |
| 384 return WebDatabase::COMMIT_NOT_NEEDED; | 374 return WebDatabase::COMMIT_NOT_NEEDED; |
| 385 } | 375 } |
| 386 return WebDatabase::COMMIT_NEEDED; | 376 return WebDatabase::COMMIT_NEEDED; |
| 387 } | 377 } |
| 388 | 378 |
| 389 WebDatabase::State AutofillWebDataServiceImpl::RemoveCreditCardImpl( | 379 WebDatabase::State AutofillWebDataService::RemoveCreditCardImpl( |
| 390 const std::string& guid, WebDatabase* db) { | 380 const std::string& guid, WebDatabase* db) { |
| 391 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 392 if (!AutofillTable::FromWebDatabase(db)->RemoveCreditCard(guid)) { | 382 if (!AutofillTable::FromWebDatabase(db)->RemoveCreditCard(guid)) { |
| 393 NOTREACHED(); | 383 NOTREACHED(); |
| 394 return WebDatabase::COMMIT_NOT_NEEDED; | 384 return WebDatabase::COMMIT_NOT_NEEDED; |
| 395 } | 385 } |
| 396 return WebDatabase::COMMIT_NEEDED; | 386 return WebDatabase::COMMIT_NEEDED; |
| 397 } | 387 } |
| 398 | 388 |
| 399 scoped_ptr<WDTypedResult> AutofillWebDataServiceImpl::GetCreditCardsImpl( | 389 scoped_ptr<WDTypedResult> AutofillWebDataService::GetCreditCardsImpl( |
| 400 WebDatabase* db) { | 390 WebDatabase* db) { |
| 401 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 391 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 402 std::vector<CreditCard*> credit_cards; | 392 std::vector<CreditCard*> credit_cards; |
| 403 AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards); | 393 AutofillTable::FromWebDatabase(db)->GetCreditCards(&credit_cards); |
| 404 return scoped_ptr<WDTypedResult>( | 394 return scoped_ptr<WDTypedResult>( |
| 405 new WDDestroyableResult<std::vector<CreditCard*> >( | 395 new WDDestroyableResult<std::vector<CreditCard*> >( |
| 406 AUTOFILL_CREDITCARDS_RESULT, | 396 AUTOFILL_CREDITCARDS_RESULT, |
| 407 credit_cards, | 397 credit_cards, |
| 408 base::Bind(&AutofillWebDataServiceImpl::DestroyAutofillCreditCardResult, | 398 base::Bind(&AutofillWebDataService::DestroyAutofillCreditCardResult, |
| 409 base::Unretained(this)))); | 399 base::Unretained(this)))); |
| 410 } | 400 } |
| 411 | 401 |
| 412 WebDatabase::State | 402 WebDatabase::State |
| 413 AutofillWebDataServiceImpl::RemoveAutofillDataModifiedBetweenImpl( | 403 AutofillWebDataService::RemoveAutofillDataModifiedBetweenImpl( |
| 414 const base::Time& delete_begin, const base::Time& delete_end, | 404 const base::Time& delete_begin, const base::Time& delete_end, |
| 415 WebDatabase* db) { | 405 WebDatabase* db) { |
| 416 std::vector<std::string> profile_guids; | 406 std::vector<std::string> profile_guids; |
| 417 std::vector<std::string> credit_card_guids; | 407 std::vector<std::string> credit_card_guids; |
| 418 if (AutofillTable::FromWebDatabase(db)-> | 408 if (AutofillTable::FromWebDatabase(db)-> |
| 419 RemoveAutofillDataModifiedBetween( | 409 RemoveAutofillDataModifiedBetween( |
| 420 delete_begin, | 410 delete_begin, |
| 421 delete_end, | 411 delete_end, |
| 422 &profile_guids, | 412 &profile_guids, |
| 423 &credit_card_guids)) { | 413 &credit_card_guids)) { |
| 424 for (std::vector<std::string>::iterator iter = profile_guids.begin(); | 414 for (std::vector<std::string>::iterator iter = profile_guids.begin(); |
| 425 iter != profile_guids.end(); ++iter) { | 415 iter != profile_guids.end(); ++iter) { |
| 426 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, | 416 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, |
| 427 NULL); | 417 NULL); |
| 428 content::NotificationService::current()->Notify( | 418 content::NotificationService::current()->Notify( |
| 429 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 419 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 430 content::Source<AutofillWebDataService>(this), | 420 content::Source<AutofillWebDataService>(this), |
| 431 content::Details<AutofillProfileChange>(&change)); | 421 content::Details<AutofillProfileChange>(&change)); |
| 432 } | 422 } |
| 433 // Note: It is the caller's responsibility to post notifications for any | 423 // Note: It is the caller's responsibility to post notifications for any |
| 434 // changes, e.g. by calling the Refresh() method of PersonalDataManager. | 424 // changes, e.g. by calling the Refresh() method of PersonalDataManager. |
| 435 return WebDatabase::COMMIT_NEEDED; | 425 return WebDatabase::COMMIT_NEEDED; |
| 436 } | 426 } |
| 437 return WebDatabase::COMMIT_NOT_NEEDED; | 427 return WebDatabase::COMMIT_NOT_NEEDED; |
| 438 } | 428 } |
| 439 | 429 |
| 440 void AutofillWebDataServiceImpl::DestroyAutofillProfileResult( | 430 void AutofillWebDataService::DestroyAutofillProfileResult( |
| 441 const WDTypedResult* result) { | 431 const WDTypedResult* result) { |
| 442 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); | 432 DCHECK(result->GetType() == AUTOFILL_PROFILES_RESULT); |
| 443 const WDResult<std::vector<AutofillProfile*> >* r = | 433 const WDResult<std::vector<AutofillProfile*> >* r = |
| 444 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); | 434 static_cast<const WDResult<std::vector<AutofillProfile*> >*>(result); |
| 445 std::vector<AutofillProfile*> profiles = r->GetValue(); | 435 std::vector<AutofillProfile*> profiles = r->GetValue(); |
| 446 STLDeleteElements(&profiles); | 436 STLDeleteElements(&profiles); |
| 447 } | 437 } |
| 448 | 438 |
| 449 void AutofillWebDataServiceImpl::DestroyAutofillCreditCardResult( | 439 void AutofillWebDataService::DestroyAutofillCreditCardResult( |
| 450 const WDTypedResult* result) { | 440 const WDTypedResult* result) { |
| 451 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); | 441 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); |
| 452 const WDResult<std::vector<CreditCard*> >* r = | 442 const WDResult<std::vector<CreditCard*> >* r = |
| 453 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); | 443 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); |
| 454 | 444 |
| 455 std::vector<CreditCard*> credit_cards = r->GetValue(); | 445 std::vector<CreditCard*> credit_cards = r->GetValue(); |
| 456 STLDeleteElements(&credit_cards); | 446 STLDeleteElements(&credit_cards); |
| 457 } | 447 } |
| OLD | NEW |