Chromium Code Reviews| 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/web_data_service.h" | 5 #include "chrome/browser/webdata/web_data_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 142 return db_; | 142 return db_; |
| 143 } | 143 } |
| 144 | 144 |
| 145 ////////////////////////////////////////////////////////////////////////////// | 145 ////////////////////////////////////////////////////////////////////////////// |
| 146 // | 146 // |
| 147 // Keywords. | 147 // Keywords. |
| 148 // | 148 // |
| 149 ////////////////////////////////////////////////////////////////////////////// | 149 ////////////////////////////////////////////////////////////////////////////// |
| 150 | 150 |
| 151 void WebDataService::AddKeyword(const TemplateURLData& data) { | 151 void WebDataService::AddKeyword(const TemplateURLData& data) { |
| 152 GenericRequest<TemplateURLData>* request = | 152 ScheduleDBTask( |
| 153 new GenericRequest<TemplateURLData>( | 153 FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, data)); |
| 154 this, NULL, &request_manager_, data); | |
| 155 ScheduleTask(FROM_HERE, Bind(&WebDataService::AddKeywordImpl, this, request)); | |
| 156 } | 154 } |
| 157 | 155 |
| 158 void WebDataService::RemoveKeyword(TemplateURLID id) { | 156 void WebDataService::RemoveKeyword(TemplateURLID id) { |
| 159 GenericRequest<TemplateURLID>* request = | 157 ScheduleDBTask( |
| 160 new GenericRequest<TemplateURLID>(this, NULL, &request_manager_, id); | 158 FROM_HERE, Bind(&WebDataService::RemoveKeywordImpl, this, id)); |
| 161 ScheduleTask(FROM_HERE, | |
| 162 Bind(&WebDataService::RemoveKeywordImpl, this, request)); | |
| 163 } | 159 } |
| 164 | 160 |
| 165 void WebDataService::UpdateKeyword(const TemplateURLData& data) { | 161 void WebDataService::UpdateKeyword(const TemplateURLData& data) { |
| 166 GenericRequest<TemplateURLData>* request = | 162 ScheduleDBTask( |
| 167 new GenericRequest<TemplateURLData>( | 163 FROM_HERE, Bind(&WebDataService::UpdateKeywordImpl, this, data)); |
| 168 this, NULL, &request_manager_, data); | |
| 169 ScheduleTask(FROM_HERE, | |
| 170 Bind(&WebDataService::UpdateKeywordImpl, this, request)); | |
| 171 } | 164 } |
| 172 | 165 |
| 173 WebDataService::Handle WebDataService::GetKeywords( | 166 WebDataService::Handle WebDataService::GetKeywords( |
| 174 WebDataServiceConsumer* consumer) { | 167 WebDataServiceConsumer* consumer) { |
| 175 WebDataRequest* request = | 168 WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| 176 new WebDataRequest(this, consumer, &request_manager_); | 169 Bind(&WebDataService::GetKeywordsImpl, this), |
| 177 ScheduleTask(FROM_HERE, | 170 consumer); |
| 178 Bind(&WebDataService::GetKeywordsImpl, this, request)); | 171 return handle; |
| 179 return request->GetHandle(); | |
| 180 } | 172 } |
| 181 | 173 |
| 182 void WebDataService::SetDefaultSearchProvider(const TemplateURL* url) { | 174 void WebDataService::SetDefaultSearchProvider(const TemplateURL* url) { |
| 183 GenericRequest<TemplateURLID>* request = new GenericRequest<TemplateURLID>( | 175 ScheduleDBTask(FROM_HERE, |
| 184 this, NULL, &request_manager_, url ? url->id() : 0); | 176 Bind(&WebDataService::SetDefaultSearchProviderImpl, this, |
| 185 ScheduleTask(FROM_HERE, Bind(&WebDataService::SetDefaultSearchProviderImpl, | 177 url ? url->id() : 0)); |
| 186 this, request)); | |
| 187 } | 178 } |
| 188 | 179 |
| 189 void WebDataService::SetBuiltinKeywordVersion(int version) { | 180 void WebDataService::SetBuiltinKeywordVersion(int version) { |
| 190 GenericRequest<int>* request = new GenericRequest<int>( | 181 ScheduleDBTask(FROM_HERE, |
| 191 this, NULL, &request_manager_, version); | 182 Bind(&WebDataService::SetBuiltinKeywordVersionImpl, this, version)); |
| 192 ScheduleTask(FROM_HERE, Bind(&WebDataService::SetBuiltinKeywordVersionImpl, | |
| 193 this, request)); | |
| 194 } | 183 } |
| 195 | 184 |
| 196 ////////////////////////////////////////////////////////////////////////////// | 185 ////////////////////////////////////////////////////////////////////////////// |
| 197 // | 186 // |
| 198 // Web Apps | 187 // Web Apps |
| 199 // | 188 // |
| 200 ////////////////////////////////////////////////////////////////////////////// | 189 ////////////////////////////////////////////////////////////////////////////// |
| 201 | 190 |
| 202 void WebDataService::SetWebAppImage(const GURL& app_url, | 191 void WebDataService::SetWebAppImage(const GURL& app_url, |
| 203 const SkBitmap& image) { | 192 const SkBitmap& image) { |
| 204 GenericRequest2<GURL, SkBitmap>* request = | 193 ScheduleDBTask(FROM_HERE, |
| 205 new GenericRequest2<GURL, SkBitmap>( | 194 Bind(&WebDataService::SetWebAppImageImpl, this, app_url, image)); |
| 206 this, NULL, &request_manager_, app_url, image); | |
| 207 ScheduleTask(FROM_HERE, | |
| 208 Bind(&WebDataService::SetWebAppImageImpl, this, request)); | |
| 209 } | 195 } |
| 210 | 196 |
| 211 void WebDataService::SetWebAppHasAllImages(const GURL& app_url, | 197 void WebDataService::SetWebAppHasAllImages(const GURL& app_url, |
| 212 bool has_all_images) { | 198 bool has_all_images) { |
| 213 GenericRequest2<GURL, bool>* request = | 199 ScheduleDBTask(FROM_HERE, |
| 214 new GenericRequest2<GURL, bool>( | 200 Bind(&WebDataService::SetWebAppHasAllImagesImpl, this, app_url, |
| 215 this, NULL, &request_manager_, app_url, has_all_images); | 201 has_all_images)); |
| 216 ScheduleTask(FROM_HERE, | |
| 217 Bind(&WebDataService::SetWebAppHasAllImagesImpl, this, request)); | |
| 218 } | 202 } |
| 219 | 203 |
| 220 void WebDataService::RemoveWebApp(const GURL& app_url) { | 204 void WebDataService::RemoveWebApp(const GURL& app_url) { |
| 221 GenericRequest<GURL>* request = | 205 ScheduleDBTask(FROM_HERE, |
| 222 new GenericRequest<GURL>(this, NULL, &request_manager_, app_url); | 206 Bind(&WebDataService::RemoveWebAppImpl, this, app_url)); |
| 223 ScheduleTask(FROM_HERE, | |
| 224 Bind(&WebDataService::RemoveWebAppImpl, this, request)); | |
| 225 } | 207 } |
| 226 | 208 |
| 227 WebDataService::Handle WebDataService::GetWebAppImages( | 209 WebDataService::Handle WebDataService::GetWebAppImages( |
| 228 const GURL& app_url, | 210 const GURL& app_url, |
| 229 WebDataServiceConsumer* consumer) { | 211 WebDataServiceConsumer* consumer) { |
| 230 GenericRequest<GURL>* request = | 212 WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
|
erikwright (departed)
2013/01/10 19:48:10
is there a reason for the local variable?
Cait (Slow)
2013/01/11 19:40:39
Done.
| |
| 231 new GenericRequest<GURL>(this, consumer, &request_manager_, app_url); | 213 Bind(&WebDataService::GetWebAppImagesImpl, this, app_url), consumer); |
| 232 ScheduleTask(FROM_HERE, | 214 return handle; |
| 233 Bind(&WebDataService::GetWebAppImagesImpl, this, request)); | |
| 234 return request->GetHandle(); | |
| 235 } | 215 } |
| 236 | 216 |
| 237 ////////////////////////////////////////////////////////////////////////////// | 217 ////////////////////////////////////////////////////////////////////////////// |
| 238 // | 218 // |
| 239 // Web Intents. | 219 // Web Intents. |
| 240 // | 220 // |
| 241 ////////////////////////////////////////////////////////////////////////////// | 221 ////////////////////////////////////////////////////////////////////////////// |
| 242 | 222 |
| 243 void WebDataService::AddWebIntentService(const WebIntentServiceData& service) { | 223 void WebDataService::AddWebIntentService(const WebIntentServiceData& service) { |
| 244 GenericRequest<WebIntentServiceData>* request = | 224 ScheduleDBTask(FROM_HERE, |
| 245 new GenericRequest<WebIntentServiceData>( | 225 Bind(&WebDataService::AddWebIntentServiceImpl, this, service)); |
| 246 this, NULL, &request_manager_, service); | |
| 247 ScheduleTask(FROM_HERE, | |
| 248 Bind(&WebDataService::AddWebIntentServiceImpl, this, request)); | |
| 249 } | 226 } |
| 250 | 227 |
| 251 void WebDataService::RemoveWebIntentService( | 228 void WebDataService::RemoveWebIntentService( |
| 252 const WebIntentServiceData& service) { | 229 const WebIntentServiceData& service) { |
| 253 GenericRequest<WebIntentServiceData>* request = | 230 ScheduleDBTask(FROM_HERE, Bind(&WebDataService::RemoveWebIntentServiceImpl, |
| 254 new GenericRequest<WebIntentServiceData>( | 231 this, service)); |
| 255 this, NULL, &request_manager_, service); | |
| 256 ScheduleTask(FROM_HERE, Bind(&WebDataService::RemoveWebIntentServiceImpl, | |
| 257 this, request)); | |
| 258 } | 232 } |
| 259 | 233 |
| 260 WebDataService::Handle WebDataService::GetWebIntentServicesForAction( | 234 WebDataService::Handle WebDataService::GetWebIntentServicesForAction( |
| 261 const string16& action, | 235 const string16& action, |
| 262 WebDataServiceConsumer* consumer) { | 236 WebDataServiceConsumer* consumer) { |
| 263 DCHECK(consumer); | 237 DCHECK(consumer); |
|
erikwright (departed)
2013/01/10 19:48:10
How about putting a DCHECK like this inside Schedu
Cait (Slow)
2013/01/11 19:40:39
Done.
| |
| 264 GenericRequest<string16>* request = | 238 WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| 265 new GenericRequest<string16>( | 239 Bind(&WebDataService::GetWebIntentServicesImpl, this, action), |
| 266 this, consumer, &request_manager_, action); | 240 consumer); |
| 267 ScheduleTask(FROM_HERE, | 241 return handle; |
| 268 Bind(&WebDataService::GetWebIntentServicesImpl, this, request)); | |
| 269 return request->GetHandle(); | |
| 270 } | 242 } |
| 271 | 243 |
| 272 WebDataService::Handle WebDataService::GetWebIntentServicesForURL( | 244 WebDataService::Handle WebDataService::GetWebIntentServicesForURL( |
| 273 const string16& service_url, | 245 const string16& service_url, |
| 274 WebDataServiceConsumer* consumer) { | 246 WebDataServiceConsumer* consumer) { |
| 275 DCHECK(consumer); | 247 DCHECK(consumer); |
| 276 GenericRequest<string16>* request = | 248 WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| 277 new GenericRequest<string16>( | 249 Bind(&WebDataService::GetWebIntentServicesForURLImpl, this, service_url), |
| 278 this, consumer, &request_manager_, service_url); | 250 consumer); |
| 279 ScheduleTask(FROM_HERE, Bind(&WebDataService::GetWebIntentServicesForURLImpl, | 251 return handle; |
| 280 this, request)); | |
| 281 return request->GetHandle(); | |
| 282 } | 252 } |
| 283 | 253 |
| 284 | 254 |
| 285 WebDataService::Handle WebDataService::GetAllWebIntentServices( | 255 WebDataService::Handle WebDataService::GetAllWebIntentServices( |
| 286 WebDataServiceConsumer* consumer) { | 256 WebDataServiceConsumer* consumer) { |
| 287 DCHECK(consumer); | 257 DCHECK(consumer); |
| 288 GenericRequest<std::string>* request = | 258 WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| 289 new GenericRequest<std::string>( | 259 Bind(&WebDataService::GetAllWebIntentServicesImpl, this), consumer); |
| 290 this, consumer, &request_manager_, std::string()); | 260 return handle; |
| 291 ScheduleTask(FROM_HERE, Bind(&WebDataService::GetAllWebIntentServicesImpl, | |
| 292 this, request)); | |
| 293 return request->GetHandle(); | |
| 294 } | 261 } |
| 295 | 262 |
| 296 void WebDataService::AddDefaultWebIntentService( | 263 void WebDataService::AddDefaultWebIntentService( |
| 297 const DefaultWebIntentService& service) { | 264 const DefaultWebIntentService& service) { |
| 298 GenericRequest<DefaultWebIntentService>* request = | 265 ScheduleDBTask(FROM_HERE, |
| 299 new GenericRequest<DefaultWebIntentService>( | 266 Bind(&WebDataService::AddDefaultWebIntentServiceImpl, this, service)); |
| 300 this, NULL, &request_manager_, service); | |
| 301 ScheduleTask(FROM_HERE, | |
| 302 Bind(&WebDataService::AddDefaultWebIntentServiceImpl, this, | |
| 303 request)); | |
| 304 } | 267 } |
| 305 | 268 |
| 306 void WebDataService::RemoveDefaultWebIntentService( | 269 void WebDataService::RemoveDefaultWebIntentService( |
| 307 const DefaultWebIntentService& service) { | 270 const DefaultWebIntentService& service) { |
| 308 GenericRequest<DefaultWebIntentService>* request = | 271 ScheduleDBTask(FROM_HERE, |
| 309 new GenericRequest<DefaultWebIntentService>( | 272 Bind(&WebDataService::RemoveDefaultWebIntentServiceImpl, this, service)); |
| 310 this, NULL, &request_manager_, service); | |
| 311 ScheduleTask(FROM_HERE, | |
| 312 Bind(&WebDataService::RemoveDefaultWebIntentServiceImpl, this, | |
| 313 request)); | |
| 314 } | 273 } |
| 315 | 274 |
| 316 void WebDataService::RemoveWebIntentServiceDefaults( | 275 void WebDataService::RemoveWebIntentServiceDefaults( |
| 317 const GURL& service_url) { | 276 const GURL& service_url) { |
| 318 GenericRequest<GURL>* request = | 277 ScheduleDBTask(FROM_HERE, |
| 319 new GenericRequest<GURL>(this, NULL, &request_manager_, service_url); | 278 Bind(&WebDataService::RemoveWebIntentServiceDefaultsImpl, this, |
| 320 ScheduleTask( | 279 service_url)); |
| 321 FROM_HERE, | |
| 322 Bind(&WebDataService::RemoveWebIntentServiceDefaultsImpl, this, request)); | |
| 323 } | 280 } |
| 324 | 281 |
| 325 WebDataService::Handle WebDataService::GetDefaultWebIntentServicesForAction( | 282 WebDataService::Handle WebDataService::GetDefaultWebIntentServicesForAction( |
| 326 const string16& action, | 283 const string16& action, |
| 327 WebDataServiceConsumer* consumer) { | 284 WebDataServiceConsumer* consumer) { |
| 328 DCHECK(consumer); | 285 DCHECK(consumer); |
| 329 GenericRequest<string16>* request = new GenericRequest<string16>( | 286 WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| 330 this, consumer, &request_manager_, action); | 287 Bind(&WebDataService::GetDefaultWebIntentServicesForActionImpl, this, |
| 331 ScheduleTask(FROM_HERE, | 288 action), |
| 332 Bind(&WebDataService::GetDefaultWebIntentServicesForActionImpl, | 289 consumer); |
| 333 this, request)); | 290 return handle; |
| 334 return request->GetHandle(); | |
| 335 } | 291 } |
| 336 | 292 |
| 337 WebDataService::Handle WebDataService::GetAllDefaultWebIntentServices( | 293 WebDataService::Handle WebDataService::GetAllDefaultWebIntentServices( |
| 338 WebDataServiceConsumer* consumer) { | 294 WebDataServiceConsumer* consumer) { |
| 339 DCHECK(consumer); | 295 DCHECK(consumer); |
| 340 GenericRequest<std::string>* request = new GenericRequest<std::string>( | 296 WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| 341 this, consumer, &request_manager_, std::string()); | 297 Bind(&WebDataService::GetAllDefaultWebIntentServicesImpl, this), |
| 342 ScheduleTask(FROM_HERE, | 298 consumer); |
| 343 Bind(&WebDataService::GetAllDefaultWebIntentServicesImpl, | 299 return handle; |
| 344 this, request)); | |
| 345 return request->GetHandle(); | |
| 346 } | 300 } |
| 347 | 301 |
| 348 //////////////////////////////////////////////////////////////////////////////// | 302 //////////////////////////////////////////////////////////////////////////////// |
| 349 // | 303 // |
| 350 // Token Service | 304 // Token Service |
| 351 // | 305 // |
| 352 //////////////////////////////////////////////////////////////////////////////// | 306 //////////////////////////////////////////////////////////////////////////////// |
| 353 | 307 |
| 354 void WebDataService::SetTokenForService(const std::string& service, | 308 void WebDataService::SetTokenForService(const std::string& service, |
| 355 const std::string& token) { | 309 const std::string& token) { |
| 356 GenericRequest2<std::string, std::string>* request = | 310 ScheduleDBTask(FROM_HERE, |
| 357 new GenericRequest2<std::string, std::string>( | 311 Bind(&WebDataService::SetTokenForServiceImpl, this, service, token)); |
| 358 this, NULL, &request_manager_, service, token); | |
| 359 ScheduleTask(FROM_HERE, | |
| 360 Bind(&WebDataService::SetTokenForServiceImpl, this, request)); | |
| 361 } | 312 } |
| 362 | 313 |
| 363 void WebDataService::RemoveAllTokens() { | 314 void WebDataService::RemoveAllTokens() { |
| 364 GenericRequest<std::string>* request = | 315 ScheduleDBTask(FROM_HERE, Bind(&WebDataService::RemoveAllTokensImpl, this)); |
| 365 new GenericRequest<std::string>( | |
| 366 this, NULL, &request_manager_, std::string()); | |
| 367 ScheduleTask(FROM_HERE, | |
| 368 Bind(&WebDataService::RemoveAllTokensImpl, this, request)); | |
| 369 } | 316 } |
| 370 | 317 |
| 371 // Null on failure. Success is WDResult<std::string> | 318 // Null on failure. Success is WDResult<std::string> |
| 372 WebDataService::Handle WebDataService::GetAllTokens( | 319 WebDataService::Handle WebDataService::GetAllTokens( |
| 373 WebDataServiceConsumer* consumer) { | 320 WebDataServiceConsumer* consumer) { |
| 374 | 321 WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| 375 GenericRequest<std::string>* request = | 322 Bind(&WebDataService::GetAllTokensImpl, this), consumer); |
| 376 new GenericRequest<std::string>( | 323 return handle; |
| 377 this, consumer, &request_manager_, std::string()); | |
| 378 ScheduleTask(FROM_HERE, | |
| 379 Bind(&WebDataService::GetAllTokensImpl, this, request)); | |
| 380 return request->GetHandle(); | |
| 381 } | 324 } |
| 382 | 325 |
| 383 //////////////////////////////////////////////////////////////////////////////// | 326 //////////////////////////////////////////////////////////////////////////////// |
| 384 // | 327 // |
| 385 // Autofill. | 328 // Autofill. |
| 386 // | 329 // |
| 387 //////////////////////////////////////////////////////////////////////////////// | 330 //////////////////////////////////////////////////////////////////////////////// |
| 388 | 331 |
| 389 void WebDataService::AddFormFields( | 332 void WebDataService::AddFormFields( |
| 390 const std::vector<FormFieldData>& fields) { | 333 const std::vector<FormFieldData>& fields) { |
| 391 GenericRequest<std::vector<FormFieldData> >* request = | 334 ScheduleDBTask(FROM_HERE, |
| 392 new GenericRequest<std::vector<FormFieldData> >( | 335 Bind(&WebDataService::AddFormElementsImpl, this, fields)); |
| 393 this, NULL, &request_manager_, fields); | |
| 394 ScheduleTask(FROM_HERE, | |
| 395 Bind(&WebDataService::AddFormElementsImpl, this, request)); | |
| 396 } | 336 } |
| 397 | 337 |
| 398 WebDataService::Handle WebDataService::GetFormValuesForElementName( | 338 WebDataService::Handle WebDataService::GetFormValuesForElementName( |
| 399 const string16& name, const string16& prefix, int limit, | 339 const string16& name, const string16& prefix, int limit, |
| 400 WebDataServiceConsumer* consumer) { | 340 WebDataServiceConsumer* consumer) { |
| 401 WebDataRequest* request = | 341 WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| 402 new WebDataRequest(this, consumer, &request_manager_); | 342 Bind(&WebDataService::GetFormValuesForElementNameImpl, |
| 403 ScheduleTask(FROM_HERE, | 343 this, name, prefix, limit), |
| 404 Bind(&WebDataService::GetFormValuesForElementNameImpl, | 344 consumer); |
| 405 this, request, name, prefix, limit)); | 345 return handle; |
| 406 return request->GetHandle(); | |
| 407 } | 346 } |
| 408 | 347 |
| 409 void WebDataService::RemoveFormElementsAddedBetween(const Time& delete_begin, | 348 void WebDataService::RemoveFormElementsAddedBetween(const Time& delete_begin, |
| 410 const Time& delete_end) { | 349 const Time& delete_end) { |
| 411 GenericRequest2<Time, Time>* request = | 350 ScheduleDBTask(FROM_HERE, |
| 412 new GenericRequest2<Time, Time>( | 351 Bind(&WebDataService::RemoveFormElementsAddedBetweenImpl, |
| 413 this, NULL, &request_manager_, delete_begin, delete_end); | 352 this, delete_begin, delete_end)); |
| 414 ScheduleTask(FROM_HERE, | |
| 415 Bind(&WebDataService::RemoveFormElementsAddedBetweenImpl, | |
| 416 this, request)); | |
| 417 } | 353 } |
| 418 | 354 |
| 419 void WebDataService::RemoveExpiredFormElements() { | 355 void WebDataService::RemoveExpiredFormElements() { |
| 420 WebDataRequest* request = | 356 ScheduleDBTask(FROM_HERE, |
| 421 new WebDataRequest(this, NULL, &request_manager_); | 357 Bind(&WebDataService::RemoveExpiredFormElementsImpl, this)); |
| 422 ScheduleTask(FROM_HERE, | |
| 423 Bind(&WebDataService::RemoveExpiredFormElementsImpl, | |
| 424 this, request)); | |
| 425 } | 358 } |
| 426 | 359 |
| 427 void WebDataService::RemoveFormValueForElementName( | 360 void WebDataService::RemoveFormValueForElementName( |
| 428 const string16& name, const string16& value) { | 361 const string16& name, const string16& value) { |
| 429 GenericRequest2<string16, string16>* request = | 362 ScheduleDBTask(FROM_HERE, |
| 430 new GenericRequest2<string16, string16>( | 363 Bind(&WebDataService::RemoveFormValueForElementNameImpl, |
| 431 this, NULL, &request_manager_, name, value); | 364 this, name, value)); |
| 432 ScheduleTask(FROM_HERE, | |
| 433 Bind(&WebDataService::RemoveFormValueForElementNameImpl, | |
| 434 this, request)); | |
| 435 } | 365 } |
| 436 | 366 |
| 437 void WebDataService::AddAutofillProfile(const AutofillProfile& profile) { | 367 void WebDataService::AddAutofillProfile(const AutofillProfile& profile) { |
| 438 GenericRequest<AutofillProfile>* request = | 368 ScheduleDBTask(FROM_HERE, |
| 439 new GenericRequest<AutofillProfile>( | 369 Bind(&WebDataService::AddAutofillProfileImpl, this, profile)); |
| 440 this, NULL, &request_manager_, profile); | |
| 441 ScheduleTask(FROM_HERE, | |
| 442 Bind(&WebDataService::AddAutofillProfileImpl, this, request)); | |
| 443 } | 370 } |
| 444 | 371 |
| 445 void WebDataService::UpdateAutofillProfile(const AutofillProfile& profile) { | 372 void WebDataService::UpdateAutofillProfile(const AutofillProfile& profile) { |
| 446 GenericRequest<AutofillProfile>* request = | 373 ScheduleDBTask(FROM_HERE, |
| 447 new GenericRequest<AutofillProfile>( | 374 Bind(&WebDataService::UpdateAutofillProfileImpl, this, profile)); |
| 448 this, NULL, &request_manager_, profile); | |
| 449 ScheduleTask(FROM_HERE, | |
| 450 Bind(&WebDataService::UpdateAutofillProfileImpl, this, request)); | |
| 451 } | 375 } |
| 452 | 376 |
| 453 void WebDataService::RemoveAutofillProfile(const std::string& guid) { | 377 void WebDataService::RemoveAutofillProfile(const std::string& guid) { |
| 454 GenericRequest<std::string>* request = | 378 ScheduleDBTask(FROM_HERE, |
| 455 new GenericRequest<std::string>(this, NULL, &request_manager_, guid); | 379 Bind(&WebDataService::RemoveAutofillProfileImpl, this, guid)); |
| 456 ScheduleTask(FROM_HERE, | |
| 457 Bind(&WebDataService::RemoveAutofillProfileImpl, this, request)); | |
| 458 } | 380 } |
| 459 | 381 |
| 460 WebDataService::Handle WebDataService::GetAutofillProfiles( | 382 WebDataService::Handle WebDataService::GetAutofillProfiles( |
| 461 WebDataServiceConsumer* consumer) { | 383 WebDataServiceConsumer* consumer) { |
| 462 WebDataRequest* request = | 384 WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| 463 new WebDataRequest(this, consumer, &request_manager_); | 385 Bind(&WebDataService::GetAutofillProfilesImpl, this), consumer); |
| 464 ScheduleTask(FROM_HERE, | 386 return handle; |
| 465 Bind(&WebDataService::GetAutofillProfilesImpl, this, request)); | |
| 466 return request->GetHandle(); | |
| 467 } | 387 } |
| 468 | 388 |
| 469 void WebDataService::EmptyMigrationTrash(bool notify_sync) { | 389 void WebDataService::EmptyMigrationTrash(bool notify_sync) { |
| 470 GenericRequest<bool>* request = | 390 ScheduleDBTask(FROM_HERE, |
| 471 new GenericRequest<bool>(this, NULL, &request_manager_, notify_sync); | 391 Bind(&WebDataService::EmptyMigrationTrashImpl, this, notify_sync)); |
| 472 ScheduleTask(FROM_HERE, | |
| 473 Bind(&WebDataService::EmptyMigrationTrashImpl, this, request)); | |
| 474 } | 392 } |
| 475 | 393 |
| 476 void WebDataService::AddCreditCard(const CreditCard& credit_card) { | 394 void WebDataService::AddCreditCard(const CreditCard& credit_card) { |
| 477 GenericRequest<CreditCard>* request = | 395 ScheduleDBTask(FROM_HERE, |
| 478 new GenericRequest<CreditCard>( | 396 Bind(&WebDataService::AddCreditCardImpl, this, credit_card)); |
| 479 this, NULL, &request_manager_, credit_card); | |
| 480 ScheduleTask(FROM_HERE, | |
| 481 Bind(&WebDataService::AddCreditCardImpl, this, request)); | |
| 482 } | 397 } |
| 483 | 398 |
| 484 void WebDataService::UpdateCreditCard(const CreditCard& credit_card) { | 399 void WebDataService::UpdateCreditCard(const CreditCard& credit_card) { |
| 485 GenericRequest<CreditCard>* request = | 400 ScheduleDBTask(FROM_HERE, |
| 486 new GenericRequest<CreditCard>( | 401 Bind(&WebDataService::UpdateCreditCardImpl, this, credit_card)); |
| 487 this, NULL, &request_manager_, credit_card); | |
| 488 ScheduleTask(FROM_HERE, | |
| 489 Bind(&WebDataService::UpdateCreditCardImpl, this, request)); | |
| 490 } | 402 } |
| 491 | 403 |
| 492 void WebDataService::RemoveCreditCard(const std::string& guid) { | 404 void WebDataService::RemoveCreditCard(const std::string& guid) { |
| 493 GenericRequest<std::string>* request = | 405 ScheduleDBTask(FROM_HERE, |
| 494 new GenericRequest<std::string>(this, NULL, &request_manager_, guid); | 406 Bind(&WebDataService::RemoveCreditCardImpl, this, guid)); |
| 495 ScheduleTask(FROM_HERE, | |
| 496 Bind(&WebDataService::RemoveCreditCardImpl, this, request)); | |
| 497 } | 407 } |
| 498 | 408 |
| 499 WebDataService::Handle WebDataService::GetCreditCards( | 409 WebDataService::Handle WebDataService::GetCreditCards( |
| 500 WebDataServiceConsumer* consumer) { | 410 WebDataServiceConsumer* consumer) { |
| 501 WebDataRequest* request = | 411 WebDataService::Handle handle = ScheduleDBTaskWithResult(FROM_HERE, |
| 502 new WebDataRequest(this, consumer, &request_manager_); | 412 Bind(&WebDataService::GetCreditCardsImpl, this), consumer); |
| 503 ScheduleTask(FROM_HERE, | 413 return handle; |
| 504 Bind(&WebDataService::GetCreditCardsImpl, this, request)); | |
| 505 return request->GetHandle(); | |
| 506 } | 414 } |
| 507 | 415 |
| 508 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween( | 416 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
| 509 const Time& delete_begin, | 417 const Time& delete_begin, |
| 510 const Time& delete_end) { | 418 const Time& delete_end) { |
| 511 GenericRequest2<Time, Time>* request = | 419 ScheduleDBTask(FROM_HERE, Bind( |
| 512 new GenericRequest2<Time, Time>( | |
| 513 this, NULL, &request_manager_, delete_begin, delete_end); | |
| 514 ScheduleTask(FROM_HERE, Bind( | |
| 515 &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl, | 420 &WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl, |
| 516 this, request)); | 421 this, delete_begin, delete_end)); |
| 517 } | 422 } |
| 518 | 423 |
| 519 WebDataService::~WebDataService() { | 424 WebDataService::~WebDataService() { |
| 520 if (is_running_ && db_) { | 425 if (is_running_ && db_) { |
| 521 DLOG_ASSERT("WebDataService dtor called without Shutdown"); | 426 DLOG_ASSERT("WebDataService dtor called without Shutdown"); |
| 522 NOTREACHED(); | 427 NOTREACHED(); |
| 523 } | 428 } |
| 524 } | 429 } |
| 525 | 430 |
| 526 bool WebDataService::InitWithPath(const FilePath& path) { | 431 bool WebDataService::InitWithPath(const FilePath& path) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 636 } | 541 } |
| 637 | 542 |
| 638 void WebDataService::ScheduleTask(const tracked_objects::Location& from_here, | 543 void WebDataService::ScheduleTask(const tracked_objects::Location& from_here, |
| 639 const base::Closure& task) { | 544 const base::Closure& task) { |
| 640 if (is_running_) | 545 if (is_running_) |
| 641 BrowserThread::PostTask(BrowserThread::DB, from_here, task); | 546 BrowserThread::PostTask(BrowserThread::DB, from_here, task); |
| 642 else | 547 else |
| 643 NOTREACHED() << "Task scheduled after Shutdown()"; | 548 NOTREACHED() << "Task scheduled after Shutdown()"; |
| 644 } | 549 } |
| 645 | 550 |
| 551 void WebDataService::ScheduleDBTask( | |
| 552 const tracked_objects::Location& from_here, | |
| 553 const base::Closure& task) { | |
| 554 WebDataRequest* request = new WebDataRequest(this, NULL, | |
|
erikwright (departed)
2013/01/10 19:48:10
wrap after '=' or '('
erikwright (departed)
2013/01/10 19:48:10
Your changes here and in your previous CL reveal t
Cait (Slow)
2013/01/11 19:40:39
Ownership gap is fixed in https://codereview.chrom
Cait (Slow)
2013/01/11 19:40:39
Done.
| |
| 555 &request_manager_); | |
| 556 if (is_running_) { | |
| 557 BrowserThread::PostTask(BrowserThread::DB, from_here, | |
| 558 base::Bind(&WebDataService::DBTaskWrapper, this, task, request)); | |
| 559 } else { | |
| 560 NOTREACHED() << "Task scheduled after Shutdown()"; | |
| 561 } | |
| 562 } | |
| 563 | |
| 564 WebDataService::Handle WebDataService::ScheduleDBTaskWithResult( | |
| 565 const tracked_objects::Location& from_here, | |
| 566 const ResultTask& task, | |
| 567 WebDataServiceConsumer* consumer) { | |
| 568 WebDataRequest* request = new WebDataRequest(this, consumer, | |
| 569 &request_manager_); | |
| 570 if (is_running_) { | |
| 571 BrowserThread::PostTask(BrowserThread::DB, from_here, | |
| 572 base::Bind(&WebDataService::DBResultTaskWrapper, this, task, request)); | |
| 573 } else { | |
| 574 NOTREACHED() << "Task scheduled after Shutdown()"; | |
| 575 } | |
| 576 return request->GetHandle(); | |
| 577 } | |
| 578 | |
| 579 void WebDataService::DBTaskWrapper(const base::Closure& task, | |
| 580 WebDataRequest* request) { | |
| 581 InitializeDatabaseIfNecessary(); | |
| 582 if (db_ && !request->IsCancelled()) { | |
| 583 task.Run(); | |
| 584 } | |
| 585 request->RequestComplete(); | |
| 586 } | |
| 587 | |
| 588 void WebDataService::DBResultTaskWrapper(const ResultTask& task, | |
| 589 WebDataRequest* request) { | |
| 590 InitializeDatabaseIfNecessary(); | |
| 591 if (db_ && !request->IsCancelled()) { | |
| 592 WDTypedResult* result = task.Run(); | |
| 593 request->SetResult(result); | |
| 594 } | |
| 595 request->RequestComplete(); | |
| 596 } | |
| 597 | |
| 646 void WebDataService::ScheduleCommit() { | 598 void WebDataService::ScheduleCommit() { |
| 647 if (should_commit_ == false) { | 599 if (should_commit_ == false) { |
| 648 should_commit_ = true; | 600 should_commit_ = true; |
| 649 ScheduleTask(FROM_HERE, Bind(&WebDataService::Commit, this)); | 601 ScheduleTask(FROM_HERE, Bind(&WebDataService::Commit, this)); |
|
erikwright (departed)
2013/01/10 19:48:10
Is this now the only caller of ScheduleTask? If so
Cait (Slow)
2013/01/11 19:40:39
It's actually called in 5 places (init'ing and shu
| |
| 650 } | 602 } |
| 651 } | 603 } |
| 652 | 604 |
| 653 //////////////////////////////////////////////////////////////////////////////// | 605 //////////////////////////////////////////////////////////////////////////////// |
| 654 // | 606 // |
| 655 // Keywords implementation. | 607 // Keywords implementation. |
| 656 // | 608 // |
| 657 //////////////////////////////////////////////////////////////////////////////// | 609 //////////////////////////////////////////////////////////////////////////////// |
| 658 | 610 |
| 659 void WebDataService::AddKeywordImpl(GenericRequest<TemplateURLData>* request) { | 611 void WebDataService::AddKeywordImpl(const TemplateURLData& data) { |
| 660 InitializeDatabaseIfNecessary(); | 612 db_->GetKeywordTable()->AddKeyword(data); |
| 661 if (db_ && !request->IsCancelled()) { | 613 ScheduleCommit(); |
| 662 db_->GetKeywordTable()->AddKeyword(request->arg()); | |
| 663 ScheduleCommit(); | |
| 664 } | |
| 665 request->RequestComplete(); | |
| 666 } | 614 } |
| 667 | 615 |
| 668 void WebDataService::RemoveKeywordImpl(GenericRequest<TemplateURLID>* request) { | 616 void WebDataService::RemoveKeywordImpl(TemplateURLID id) { |
| 669 InitializeDatabaseIfNecessary(); | 617 DCHECK(id); |
| 670 if (db_ && !request->IsCancelled()) { | 618 db_->GetKeywordTable()->RemoveKeyword(id); |
| 671 DCHECK(request->arg()); | 619 ScheduleCommit(); |
| 672 db_->GetKeywordTable()->RemoveKeyword(request->arg()); | |
| 673 ScheduleCommit(); | |
| 674 } | |
| 675 request->RequestComplete(); | |
| 676 } | 620 } |
| 677 | 621 |
| 678 void WebDataService::UpdateKeywordImpl( | 622 void WebDataService::UpdateKeywordImpl(const TemplateURLData& data) { |
| 679 GenericRequest<TemplateURLData>* request) { | 623 if (!db_->GetKeywordTable()->UpdateKeyword(data)) { |
| 680 InitializeDatabaseIfNecessary(); | 624 NOTREACHED(); |
| 681 if (db_ && !request->IsCancelled()) { | 625 return; |
| 682 if (!db_->GetKeywordTable()->UpdateKeyword(request->arg())) { | |
| 683 NOTREACHED(); | |
| 684 return; | |
| 685 } | |
| 686 ScheduleCommit(); | |
| 687 } | 626 } |
| 688 request->RequestComplete(); | 627 ScheduleCommit(); |
| 689 } | 628 } |
| 690 | 629 |
| 691 void WebDataService::GetKeywordsImpl(WebDataRequest* request) { | 630 WDTypedResult* WebDataService::GetKeywordsImpl() { |
| 692 InitializeDatabaseIfNecessary(); | 631 WDKeywordsResult result; |
| 693 if (db_ && !request->IsCancelled()) { | 632 db_->GetKeywordTable()->GetKeywords(&result.keywords); |
| 694 WDKeywordsResult result; | 633 result.default_search_provider_id = |
| 695 db_->GetKeywordTable()->GetKeywords(&result.keywords); | 634 db_->GetKeywordTable()->GetDefaultSearchProviderID(); |
| 696 result.default_search_provider_id = | 635 result.builtin_keyword_version = |
| 697 db_->GetKeywordTable()->GetDefaultSearchProviderID(); | 636 db_->GetKeywordTable()->GetBuiltinKeywordVersion(); |
| 698 result.builtin_keyword_version = | 637 return new WDResult<WDKeywordsResult>(KEYWORDS_RESULT, result); |
| 699 db_->GetKeywordTable()->GetBuiltinKeywordVersion(); | |
| 700 request->SetResult( | |
| 701 new WDResult<WDKeywordsResult>(KEYWORDS_RESULT, result)); | |
| 702 } | |
| 703 request->RequestComplete(); | |
| 704 } | 638 } |
| 705 | 639 |
| 706 void WebDataService::SetDefaultSearchProviderImpl( | 640 void WebDataService::SetDefaultSearchProviderImpl(TemplateURLID id) { |
| 707 GenericRequest<TemplateURLID>* request) { | 641 if (!db_->GetKeywordTable()->SetDefaultSearchProviderID(id)) { |
| 708 InitializeDatabaseIfNecessary(); | 642 NOTREACHED(); |
| 709 if (db_ && !request->IsCancelled()) { | 643 return; |
| 710 if (!db_->GetKeywordTable()->SetDefaultSearchProviderID(request->arg())) { | |
| 711 NOTREACHED(); | |
| 712 return; | |
| 713 } | |
| 714 ScheduleCommit(); | |
| 715 } | 644 } |
| 716 request->RequestComplete(); | 645 ScheduleCommit(); |
| 717 } | 646 } |
| 718 | 647 |
| 719 void WebDataService::SetBuiltinKeywordVersionImpl( | 648 void WebDataService::SetBuiltinKeywordVersionImpl(int version) { |
| 720 GenericRequest<int>* request) { | 649 if (!db_->GetKeywordTable()->SetBuiltinKeywordVersion(version)) { |
| 721 InitializeDatabaseIfNecessary(); | 650 NOTREACHED(); |
| 722 if (db_ && !request->IsCancelled()) { | 651 return; |
| 723 if (!db_->GetKeywordTable()->SetBuiltinKeywordVersion(request->arg())) { | |
| 724 NOTREACHED(); | |
| 725 return; | |
| 726 } | |
| 727 ScheduleCommit(); | |
| 728 } | 652 } |
| 729 request->RequestComplete(); | 653 ScheduleCommit(); |
| 730 } | 654 } |
| 731 | 655 |
| 732 //////////////////////////////////////////////////////////////////////////////// | 656 //////////////////////////////////////////////////////////////////////////////// |
| 733 // | 657 // |
| 734 // Web Apps implementation. | 658 // Web Apps implementation. |
| 735 // | 659 // |
| 736 //////////////////////////////////////////////////////////////////////////////// | 660 //////////////////////////////////////////////////////////////////////////////// |
| 737 | 661 |
| 738 void WebDataService::SetWebAppImageImpl( | 662 void WebDataService::SetWebAppImageImpl( |
| 739 GenericRequest2<GURL, SkBitmap>* request) { | 663 const GURL& app_url, const SkBitmap& image) { |
| 740 InitializeDatabaseIfNecessary(); | 664 db_->GetWebAppsTable()->SetWebAppImage(app_url, image); |
| 741 if (db_ && !request->IsCancelled()) { | 665 ScheduleCommit(); |
| 742 db_->GetWebAppsTable()->SetWebAppImage( | |
| 743 request->arg1(), request->arg2()); | |
| 744 ScheduleCommit(); | |
| 745 } | |
| 746 request->RequestComplete(); | |
| 747 } | 666 } |
| 748 | 667 |
| 749 void WebDataService::SetWebAppHasAllImagesImpl( | 668 void WebDataService::SetWebAppHasAllImagesImpl( |
| 750 GenericRequest2<GURL, bool>* request) { | 669 const GURL& app_url, bool has_all_images) { |
| 751 InitializeDatabaseIfNecessary(); | 670 db_->GetWebAppsTable()->SetWebAppHasAllImages(app_url, has_all_images); |
| 752 if (db_ && !request->IsCancelled()) { | 671 ScheduleCommit(); |
| 753 db_->GetWebAppsTable()->SetWebAppHasAllImages(request->arg1(), | |
| 754 request->arg2()); | |
| 755 ScheduleCommit(); | |
| 756 } | |
| 757 request->RequestComplete(); | |
| 758 } | 672 } |
| 759 | 673 |
| 760 void WebDataService::RemoveWebAppImpl(GenericRequest<GURL>* request) { | 674 void WebDataService::RemoveWebAppImpl(const GURL& app_url) { |
| 761 InitializeDatabaseIfNecessary(); | 675 db_->GetWebAppsTable()->RemoveWebApp(app_url); |
| 762 if (db_ && !request->IsCancelled()) { | 676 ScheduleCommit(); |
| 763 db_->GetWebAppsTable()->RemoveWebApp(request->arg()); | |
| 764 ScheduleCommit(); | |
| 765 } | |
| 766 request->RequestComplete(); | |
| 767 } | 677 } |
| 768 | 678 |
| 769 void WebDataService::GetWebAppImagesImpl(GenericRequest<GURL>* request) { | 679 WDTypedResult* WebDataService::GetWebAppImagesImpl(const GURL& app_url) { |
|
erikwright (departed)
2013/01/10 19:48:10
The new style is to return scoped_ptr<WDTypedResul
Cait (Slow)
2013/01/11 19:40:39
Done.
| |
| 770 InitializeDatabaseIfNecessary(); | 680 WDAppImagesResult result; |
| 771 if (db_ && !request->IsCancelled()) { | 681 result.has_all_images = |
| 772 WDAppImagesResult result; | 682 db_->GetWebAppsTable()->GetWebAppHasAllImages(app_url); |
| 773 result.has_all_images = | 683 db_->GetWebAppsTable()->GetWebAppImages(app_url, &result.images); |
| 774 db_->GetWebAppsTable()->GetWebAppHasAllImages(request->arg()); | 684 return new WDResult<WDAppImagesResult>(WEB_APP_IMAGES, result); |
| 775 db_->GetWebAppsTable()->GetWebAppImages(request->arg(), &result.images); | |
| 776 request->SetResult( | |
| 777 new WDResult<WDAppImagesResult>(WEB_APP_IMAGES, result)); | |
| 778 } | |
| 779 request->RequestComplete(); | |
| 780 } | 685 } |
| 781 | 686 |
| 782 //////////////////////////////////////////////////////////////////////////////// | 687 //////////////////////////////////////////////////////////////////////////////// |
| 783 // | 688 // |
| 784 // Web Intents implementation. | 689 // Web Intents implementation. |
| 785 // | 690 // |
| 786 //////////////////////////////////////////////////////////////////////////////// | 691 //////////////////////////////////////////////////////////////////////////////// |
| 787 | 692 |
| 788 void WebDataService::RemoveWebIntentServiceImpl( | 693 void WebDataService::RemoveWebIntentServiceImpl( |
| 789 GenericRequest<WebIntentServiceData>* request) { | 694 const webkit_glue::WebIntentServiceData& service) { |
| 790 InitializeDatabaseIfNecessary(); | 695 db_->GetWebIntentsTable()->RemoveWebIntentService(service); |
| 791 if (db_ && !request->IsCancelled()) { | 696 ScheduleCommit(); |
| 792 const WebIntentServiceData& service = request->arg(); | |
| 793 db_->GetWebIntentsTable()->RemoveWebIntentService(service); | |
| 794 ScheduleCommit(); | |
| 795 } | |
| 796 request->RequestComplete(); | |
| 797 } | 697 } |
| 798 | 698 |
| 799 void WebDataService::AddWebIntentServiceImpl( | 699 void WebDataService::AddWebIntentServiceImpl( |
| 800 GenericRequest<WebIntentServiceData>* request) { | 700 const webkit_glue::WebIntentServiceData& service) { |
| 801 InitializeDatabaseIfNecessary(); | 701 db_->GetWebIntentsTable()->SetWebIntentService(service); |
| 802 if (db_ && !request->IsCancelled()) { | 702 ScheduleCommit(); |
| 803 const WebIntentServiceData& service = request->arg(); | |
| 804 db_->GetWebIntentsTable()->SetWebIntentService(service); | |
| 805 ScheduleCommit(); | |
| 806 } | |
| 807 request->RequestComplete(); | |
| 808 } | 703 } |
| 809 | 704 |
| 810 | 705 |
| 811 void WebDataService::GetWebIntentServicesImpl( | 706 WDTypedResult* WebDataService::GetWebIntentServicesImpl( |
| 812 GenericRequest<string16>* request) { | 707 const string16& action) { |
| 813 InitializeDatabaseIfNecessary(); | 708 std::vector<WebIntentServiceData> result; |
| 814 if (db_ && !request->IsCancelled()) { | 709 db_->GetWebIntentsTable()->GetWebIntentServicesForAction(action, &result); |
| 815 std::vector<WebIntentServiceData> result; | 710 return new WDResult<std::vector<WebIntentServiceData> >( |
| 816 db_->GetWebIntentsTable()->GetWebIntentServicesForAction(request->arg(), | 711 WEB_INTENTS_RESULT, result); |
| 817 &result); | |
| 818 request->SetResult(new WDResult<std::vector<WebIntentServiceData> >( | |
| 819 WEB_INTENTS_RESULT, result)); | |
| 820 } | |
| 821 request->RequestComplete(); | |
| 822 } | 712 } |
| 823 | 713 |
| 824 void WebDataService::GetWebIntentServicesForURLImpl( | 714 WDTypedResult* WebDataService::GetWebIntentServicesForURLImpl( |
| 825 GenericRequest<string16>* request) { | 715 const string16& service_url) { |
| 826 InitializeDatabaseIfNecessary(); | 716 std::vector<WebIntentServiceData> result; |
| 827 if (db_ && !request->IsCancelled()) { | 717 db_->GetWebIntentsTable()->GetWebIntentServicesForURL(service_url, &result); |
| 828 std::vector<WebIntentServiceData> result; | 718 return new WDResult<std::vector<WebIntentServiceData> >( |
| 829 db_->GetWebIntentsTable()->GetWebIntentServicesForURL( | 719 WEB_INTENTS_RESULT, result); |
| 830 request->arg(), &result); | |
| 831 request->SetResult( | |
| 832 new WDResult<std::vector<WebIntentServiceData> >( | |
| 833 WEB_INTENTS_RESULT, result)); | |
| 834 } | |
| 835 request->RequestComplete(); | |
| 836 } | 720 } |
| 837 | 721 |
| 838 void WebDataService::GetAllWebIntentServicesImpl( | 722 WDTypedResult* WebDataService::GetAllWebIntentServicesImpl() { |
| 839 GenericRequest<std::string>* request) { | 723 std::vector<WebIntentServiceData> result; |
| 840 InitializeDatabaseIfNecessary(); | 724 db_->GetWebIntentsTable()->GetAllWebIntentServices(&result); |
| 841 if (db_ && !request->IsCancelled()) { | 725 return new WDResult<std::vector<WebIntentServiceData> >( |
| 842 std::vector<WebIntentServiceData> result; | 726 WEB_INTENTS_RESULT, result); |
| 843 db_->GetWebIntentsTable()->GetAllWebIntentServices(&result); | |
| 844 request->SetResult( | |
| 845 new WDResult<std::vector<WebIntentServiceData> >( | |
| 846 WEB_INTENTS_RESULT, result)); | |
| 847 } | |
| 848 request->RequestComplete(); | |
| 849 } | 727 } |
| 850 | 728 |
| 851 void WebDataService::AddDefaultWebIntentServiceImpl( | 729 void WebDataService::AddDefaultWebIntentServiceImpl( |
| 852 GenericRequest<DefaultWebIntentService>* request) { | 730 const DefaultWebIntentService& service) { |
| 853 InitializeDatabaseIfNecessary(); | 731 db_->GetWebIntentsTable()->SetDefaultService(service); |
| 854 if (db_ && !request->IsCancelled()) { | 732 ScheduleCommit(); |
| 855 const DefaultWebIntentService& service = request->arg(); | |
| 856 db_->GetWebIntentsTable()->SetDefaultService(service); | |
| 857 ScheduleCommit(); | |
| 858 } | |
| 859 request->RequestComplete(); | |
| 860 } | 733 } |
| 861 | 734 |
| 862 void WebDataService::RemoveDefaultWebIntentServiceImpl( | 735 void WebDataService::RemoveDefaultWebIntentServiceImpl( |
| 863 GenericRequest<DefaultWebIntentService>* request) { | 736 const DefaultWebIntentService& service) { |
| 864 InitializeDatabaseIfNecessary(); | 737 db_->GetWebIntentsTable()->RemoveDefaultService(service); |
| 865 if (db_ && !request->IsCancelled()) { | 738 ScheduleCommit(); |
| 866 const DefaultWebIntentService& service = request->arg(); | |
| 867 db_->GetWebIntentsTable()->RemoveDefaultService(service); | |
| 868 ScheduleCommit(); | |
| 869 } | |
| 870 request->RequestComplete(); | |
| 871 } | 739 } |
| 872 | 740 |
| 873 void WebDataService::RemoveWebIntentServiceDefaultsImpl( | 741 void WebDataService::RemoveWebIntentServiceDefaultsImpl( |
| 874 GenericRequest<GURL>* request) { | 742 const GURL& service_url) { |
| 875 InitializeDatabaseIfNecessary(); | 743 db_->GetWebIntentsTable()->RemoveServiceDefaults(service_url); |
| 876 if (db_ && !request->IsCancelled()) { | 744 ScheduleCommit(); |
| 877 const GURL& service_url = request->arg(); | |
| 878 db_->GetWebIntentsTable()->RemoveServiceDefaults(service_url); | |
| 879 ScheduleCommit(); | |
| 880 } | |
| 881 request->RequestComplete(); | |
| 882 } | 745 } |
| 883 | 746 |
| 884 void WebDataService::GetDefaultWebIntentServicesForActionImpl( | 747 WDTypedResult* WebDataService::GetDefaultWebIntentServicesForActionImpl( |
| 885 GenericRequest<string16>* request) { | 748 const string16& action) { |
| 886 InitializeDatabaseIfNecessary(); | 749 std::vector<DefaultWebIntentService> result; |
| 887 if (db_ && !request->IsCancelled()) { | 750 db_->GetWebIntentsTable()->GetDefaultServices(action, &result); |
| 888 std::vector<DefaultWebIntentService> result; | 751 return new WDResult<std::vector<DefaultWebIntentService> >( |
| 889 db_->GetWebIntentsTable()->GetDefaultServices( | 752 WEB_INTENTS_DEFAULTS_RESULT, result); |
| 890 request->arg(), &result); | |
| 891 request->SetResult( | |
| 892 new WDResult<std::vector<DefaultWebIntentService> >( | |
| 893 WEB_INTENTS_DEFAULTS_RESULT, result)); | |
| 894 } | |
| 895 request->RequestComplete(); | |
| 896 } | 753 } |
| 897 | 754 |
| 898 void WebDataService::GetAllDefaultWebIntentServicesImpl( | 755 WDTypedResult* WebDataService::GetAllDefaultWebIntentServicesImpl() { |
| 899 GenericRequest<std::string>* request) { | 756 std::vector<DefaultWebIntentService> result; |
| 900 InitializeDatabaseIfNecessary(); | 757 db_->GetWebIntentsTable()->GetAllDefaultServices(&result); |
| 901 if (db_ && !request->IsCancelled()) { | 758 return new WDResult<std::vector<DefaultWebIntentService> >( |
| 902 std::vector<DefaultWebIntentService> result; | 759 WEB_INTENTS_DEFAULTS_RESULT, result); |
| 903 db_->GetWebIntentsTable()->GetAllDefaultServices(&result); | |
| 904 request->SetResult( | |
| 905 new WDResult<std::vector<DefaultWebIntentService> >( | |
| 906 WEB_INTENTS_DEFAULTS_RESULT, result)); | |
| 907 } | |
| 908 request->RequestComplete(); | |
| 909 } | 760 } |
| 910 | 761 |
| 911 //////////////////////////////////////////////////////////////////////////////// | 762 //////////////////////////////////////////////////////////////////////////////// |
| 912 // | 763 // |
| 913 // Token Service implementation. | 764 // Token Service implementation. |
| 914 // | 765 // |
| 915 //////////////////////////////////////////////////////////////////////////////// | 766 //////////////////////////////////////////////////////////////////////////////// |
| 916 | 767 |
| 917 // argument std::string is unused | 768 void WebDataService::RemoveAllTokensImpl() { |
| 918 void WebDataService::RemoveAllTokensImpl( | 769 if (db_->GetTokenServiceTable()->RemoveAllTokens()) { |
| 919 GenericRequest<std::string>* request) { | 770 ScheduleCommit(); |
| 920 InitializeDatabaseIfNecessary(); | |
| 921 if (db_ && !request->IsCancelled()) { | |
| 922 if (db_->GetTokenServiceTable()->RemoveAllTokens()) { | |
| 923 ScheduleCommit(); | |
| 924 } | |
| 925 } | 771 } |
| 926 request->RequestComplete(); | |
| 927 } | 772 } |
| 928 | 773 |
| 929 void WebDataService::SetTokenForServiceImpl( | 774 void WebDataService::SetTokenForServiceImpl(const std::string& service, |
| 930 GenericRequest2<std::string, std::string>* request) { | 775 const std::string& token) { |
| 931 InitializeDatabaseIfNecessary(); | 776 if (db_->GetTokenServiceTable()->SetTokenForService(service, token)) { |
| 932 if (db_ && !request->IsCancelled()) { | 777 ScheduleCommit(); |
| 933 if (db_->GetTokenServiceTable()->SetTokenForService( | |
| 934 request->arg1(), request->arg2())) { | |
| 935 ScheduleCommit(); | |
| 936 } | |
| 937 } | 778 } |
| 938 request->RequestComplete(); | |
| 939 } | 779 } |
| 940 | 780 |
| 941 // argument is unused | 781 WDTypedResult* WebDataService::GetAllTokensImpl() { |
| 942 void WebDataService::GetAllTokensImpl( | 782 std::map<std::string, std::string> map; |
| 943 GenericRequest<std::string>* request) { | 783 db_->GetTokenServiceTable()->GetAllTokens(&map); |
| 944 InitializeDatabaseIfNecessary(); | 784 return new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map); |
| 945 if (db_ && !request->IsCancelled()) { | |
| 946 std::map<std::string, std::string> map; | |
| 947 db_->GetTokenServiceTable()->GetAllTokens(&map); | |
| 948 request->SetResult( | |
| 949 new WDResult<std::map<std::string, std::string> >(TOKEN_RESULT, map)); | |
| 950 } | |
| 951 request->RequestComplete(); | |
| 952 } | 785 } |
| 953 | 786 |
| 954 //////////////////////////////////////////////////////////////////////////////// | 787 //////////////////////////////////////////////////////////////////////////////// |
| 955 // | 788 // |
| 956 // Autofill implementation. | 789 // Autofill implementation. |
| 957 // | 790 // |
| 958 //////////////////////////////////////////////////////////////////////////////// | 791 //////////////////////////////////////////////////////////////////////////////// |
| 959 | 792 |
| 960 void WebDataService::AddFormElementsImpl( | 793 void WebDataService::AddFormElementsImpl( |
| 961 GenericRequest<std::vector<FormFieldData> >* request) { | 794 const std::vector<FormFieldData>& fields) { |
| 962 InitializeDatabaseIfNecessary(); | 795 AutofillChangeList changes; |
| 963 if (db_ && !request->IsCancelled()) { | 796 if (!db_->GetAutofillTable()->AddFormFieldValues(fields, &changes)) { |
| 797 NOTREACHED(); | |
| 798 return; | |
| 799 } | |
| 800 ScheduleCommit(); | |
| 801 | |
| 802 // Post the notifications including the list of affected keys. | |
| 803 // This is sent here so that work resulting from this notification will be | |
| 804 // done on the DB thread, and not the UI thread. | |
| 805 content::NotificationService::current()->Notify( | |
| 806 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | |
| 807 content::Source<WebDataService>(this), | |
| 808 content::Details<AutofillChangeList>(&changes)); | |
| 809 } | |
| 810 | |
| 811 WDTypedResult* WebDataService::GetFormValuesForElementNameImpl( | |
| 812 const string16& name, const string16& prefix, int limit) { | |
| 813 std::vector<string16> values; | |
| 814 db_->GetAutofillTable()->GetFormValuesForElementName( | |
| 815 name, prefix, &values, limit); | |
| 816 return new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values); | |
| 817 } | |
| 818 | |
| 819 void WebDataService::RemoveFormElementsAddedBetweenImpl( | |
| 820 const base::Time& delete_begin, const base::Time& delete_end) { | |
| 821 AutofillChangeList changes; | |
| 822 if (db_->GetAutofillTable()->RemoveFormElementsAddedBetween( | |
| 823 delete_begin, delete_end, &changes)) { | |
| 824 if (!changes.empty()) { | |
| 825 // Post the notifications including the list of affected keys. | |
| 826 // This is sent here so that work resulting from this notification | |
| 827 // will be done on the DB thread, and not the UI thread. | |
| 828 content::NotificationService::current()->Notify( | |
| 829 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | |
| 830 content::Source<WebDataService>(this), | |
| 831 content::Details<AutofillChangeList>(&changes)); | |
| 832 } | |
| 833 ScheduleCommit(); | |
| 834 } | |
| 835 } | |
| 836 | |
| 837 void WebDataService::RemoveExpiredFormElementsImpl() { | |
| 838 AutofillChangeList changes; | |
| 839 | |
| 840 if (db_->GetAutofillTable()->RemoveExpiredFormElements(&changes)) { | |
| 841 if (!changes.empty()) { | |
| 842 // Post the notifications including the list of affected keys. | |
| 843 // This is sent here so that work resulting from this notification | |
| 844 // will be done on the DB thread, and not the UI thread. | |
| 845 content::NotificationService::current()->Notify( | |
| 846 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | |
| 847 content::Source<WebDataService>(this), | |
| 848 content::Details<AutofillChangeList>(&changes)); | |
| 849 } | |
| 850 ScheduleCommit(); | |
| 851 } | |
| 852 } | |
| 853 | |
| 854 void WebDataService::RemoveFormValueForElementNameImpl( | |
| 855 const string16& name, const string16& value) { | |
| 856 | |
| 857 if (db_->GetAutofillTable()->RemoveFormElement(name, value)) { | |
| 964 AutofillChangeList changes; | 858 AutofillChangeList changes; |
| 965 if (!db_->GetAutofillTable()->AddFormFieldValues( | 859 changes.push_back(AutofillChange(AutofillChange::REMOVE, |
| 966 request->arg(), &changes)) { | 860 AutofillKey(name, value))); |
| 967 NOTREACHED(); | |
| 968 return; | |
| 969 } | |
| 970 request->SetResult( | |
| 971 new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes)); | |
| 972 ScheduleCommit(); | 861 ScheduleCommit(); |
| 973 | 862 |
| 974 // Post the notifications including the list of affected keys. | 863 // Post the notifications including the list of affected keys. |
| 975 // This is sent here so that work resulting from this notification will be | |
| 976 // done on the DB thread, and not the UI thread. | |
| 977 content::NotificationService::current()->Notify( | 864 content::NotificationService::current()->Notify( |
| 978 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 865 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, |
| 979 content::Source<WebDataService>(this), | 866 content::Source<WebDataService>(this), |
| 980 content::Details<AutofillChangeList>(&changes)); | 867 content::Details<AutofillChangeList>(&changes)); |
| 981 } | 868 } |
| 982 | 869 } |
| 983 request->RequestComplete(); | 870 |
| 984 } | 871 void WebDataService::AddAutofillProfileImpl(const AutofillProfile& profile) { |
| 985 | 872 if (!db_->GetAutofillTable()->AddAutofillProfile(profile)) { |
| 986 void WebDataService::GetFormValuesForElementNameImpl(WebDataRequest* request, | 873 NOTREACHED(); |
| 987 const string16& name, const string16& prefix, int limit) { | 874 return; |
| 988 InitializeDatabaseIfNecessary(); | 875 } |
| 989 if (db_ && !request->IsCancelled()) { | 876 ScheduleCommit(); |
| 990 std::vector<string16> values; | 877 |
| 991 db_->GetAutofillTable()->GetFormValuesForElementName( | 878 // Send GUID-based notification. |
| 992 name, prefix, &values, limit); | 879 AutofillProfileChange change(AutofillProfileChange::ADD, |
| 993 request->SetResult( | 880 profile.guid(), &profile); |
| 994 new WDResult<std::vector<string16> >(AUTOFILL_VALUE_RESULT, values)); | 881 content::NotificationService::current()->Notify( |
| 995 } | 882 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 996 request->RequestComplete(); | 883 content::Source<WebDataService>(this), |
| 997 } | 884 content::Details<AutofillProfileChange>(&change)); |
| 998 | 885 } |
| 999 void WebDataService::RemoveFormElementsAddedBetweenImpl( | 886 |
| 1000 GenericRequest2<Time, Time>* request) { | 887 void WebDataService::UpdateAutofillProfileImpl(const AutofillProfile& profile) { |
| 1001 InitializeDatabaseIfNecessary(); | 888 // Only perform the update if the profile exists. It is currently |
| 1002 if (db_ && !request->IsCancelled()) { | 889 // valid to try to update a missing profile. We simply drop the write and |
| 1003 AutofillChangeList changes; | 890 // the caller will detect this on the next refresh. |
| 1004 if (db_->GetAutofillTable()->RemoveFormElementsAddedBetween( | 891 AutofillProfile* original_profile = NULL; |
| 1005 request->arg1(), request->arg2(), &changes)) { | 892 if (!db_->GetAutofillTable()->GetAutofillProfile(profile.guid(), |
| 1006 if (!changes.empty()) { | 893 &original_profile)) { |
| 1007 request->SetResult( | 894 return; |
| 1008 new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes)); | 895 } |
| 1009 | 896 scoped_ptr<AutofillProfile> scoped_profile(original_profile); |
| 1010 // Post the notifications including the list of affected keys. | 897 |
| 1011 // This is sent here so that work resulting from this notification | 898 if (!db_->GetAutofillTable()->UpdateAutofillProfileMulti(profile)) { |
| 1012 // will be done on the DB thread, and not the UI thread. | 899 NOTREACHED(); |
| 1013 content::NotificationService::current()->Notify( | 900 return; |
| 1014 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 901 } |
| 1015 content::Source<WebDataService>(this), | 902 ScheduleCommit(); |
| 1016 content::Details<AutofillChangeList>(&changes)); | 903 |
| 1017 } | 904 // Send GUID-based notification. |
| 1018 ScheduleCommit(); | 905 AutofillProfileChange change(AutofillProfileChange::UPDATE, |
| 1019 } | 906 profile.guid(), &profile); |
| 1020 } | 907 content::NotificationService::current()->Notify( |
| 1021 request->RequestComplete(); | 908 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 1022 } | 909 content::Source<WebDataService>(this), |
| 1023 | 910 content::Details<AutofillProfileChange>(&change)); |
| 1024 void WebDataService::RemoveExpiredFormElementsImpl(WebDataRequest* request) { | 911 } |
| 1025 InitializeDatabaseIfNecessary(); | 912 |
| 1026 if (db_ && !request->IsCancelled()) { | 913 void WebDataService::RemoveAutofillProfileImpl(const std::string& guid) { |
| 1027 AutofillChangeList changes; | 914 AutofillProfile* profile = NULL; |
| 1028 if (db_->GetAutofillTable()->RemoveExpiredFormElements(&changes)) { | 915 if (!db_->GetAutofillTable()->GetAutofillProfile(guid, &profile)) { |
| 1029 if (!changes.empty()) { | 916 NOTREACHED(); |
| 1030 request->SetResult( | 917 return; |
| 1031 new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes)); | 918 } |
| 1032 | 919 scoped_ptr<AutofillProfile> scoped_profile(profile); |
| 1033 // Post the notifications including the list of affected keys. | 920 |
| 1034 // This is sent here so that work resulting from this notification | 921 if (!db_->GetAutofillTable()->RemoveAutofillProfile(guid)) { |
| 1035 // will be done on the DB thread, and not the UI thread. | 922 NOTREACHED(); |
| 1036 content::NotificationService::current()->Notify( | 923 return; |
| 1037 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | 924 } |
| 1038 content::Source<WebDataService>(this), | 925 ScheduleCommit(); |
| 1039 content::Details<AutofillChangeList>(&changes)); | 926 |
| 1040 } | 927 // Send GUID-based notification. |
| 1041 ScheduleCommit(); | 928 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); |
| 1042 } | 929 content::NotificationService::current()->Notify( |
| 1043 } | 930 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 1044 request->RequestComplete(); | 931 content::Source<WebDataService>(this), |
| 1045 } | 932 content::Details<AutofillProfileChange>(&change)); |
| 1046 | 933 } |
| 1047 void WebDataService::RemoveFormValueForElementNameImpl( | 934 |
| 1048 GenericRequest2<string16, string16>* request) { | 935 WDTypedResult* WebDataService::GetAutofillProfilesImpl() { |
| 1049 InitializeDatabaseIfNecessary(); | 936 std::vector<AutofillProfile*> profiles; |
| 1050 if (db_ && !request->IsCancelled()) { | 937 db_->GetAutofillTable()->GetAutofillProfiles(&profiles); |
| 1051 const string16& name = request->arg1(); | 938 return new WDResult<std::vector<AutofillProfile*> >(AUTOFILL_PROFILES_RESULT, |
| 1052 const string16& value = request->arg2(); | 939 base::Bind(&WebDataService::DestroyAutofillProfileResult, |
| 1053 | 940 base::Unretained(this)), profiles); |
| 1054 if (db_->GetAutofillTable()->RemoveFormElement(name, value)) { | 941 } |
| 1055 AutofillChangeList changes; | 942 |
| 1056 changes.push_back(AutofillChange(AutofillChange::REMOVE, | 943 void WebDataService::EmptyMigrationTrashImpl(bool notify_sync) { |
| 1057 AutofillKey(name, value))); | 944 if (notify_sync) { |
| 1058 request->SetResult( | 945 std::vector<std::string> guids; |
| 1059 new WDResult<AutofillChangeList>(AUTOFILL_CHANGES, changes)); | 946 if (!db_->GetAutofillTable()->GetAutofillProfilesInTrash(&guids)) { |
| 1060 ScheduleCommit(); | |
| 1061 | |
| 1062 // Post the notifications including the list of affected keys. | |
| 1063 content::NotificationService::current()->Notify( | |
| 1064 chrome::NOTIFICATION_AUTOFILL_ENTRIES_CHANGED, | |
| 1065 content::Source<WebDataService>(this), | |
| 1066 content::Details<AutofillChangeList>(&changes)); | |
| 1067 } | |
| 1068 } | |
| 1069 request->RequestComplete(); | |
| 1070 } | |
| 1071 | |
| 1072 void WebDataService::AddAutofillProfileImpl( | |
| 1073 GenericRequest<AutofillProfile>* request) { | |
| 1074 InitializeDatabaseIfNecessary(); | |
| 1075 if (db_ && !request->IsCancelled()) { | |
| 1076 const AutofillProfile& profile = request->arg(); | |
| 1077 if (!db_->GetAutofillTable()->AddAutofillProfile(profile)) { | |
| 1078 NOTREACHED(); | 947 NOTREACHED(); |
| 1079 return; | 948 return; |
| 1080 } | 949 } |
| 1081 ScheduleCommit(); | 950 |
| 1082 | 951 for (std::vector<std::string>::const_iterator iter = guids.begin(); |
| 1083 // Send GUID-based notification. | 952 iter != guids.end(); ++iter) { |
| 1084 AutofillProfileChange change(AutofillProfileChange::ADD, | 953 // Send GUID-based notification. |
| 1085 profile.guid(), &profile); | 954 AutofillProfileChange change(AutofillProfileChange::REMOVE, |
| 1086 content::NotificationService::current()->Notify( | 955 *iter, NULL); |
| 1087 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 956 content::NotificationService::current()->Notify( |
| 1088 content::Source<WebDataService>(this), | 957 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 1089 content::Details<AutofillProfileChange>(&change)); | 958 content::Source<WebDataService>(this), |
| 1090 } | 959 content::Details<AutofillProfileChange>(&change)); |
| 1091 request->RequestComplete(); | 960 } |
| 1092 } | 961 |
| 1093 | 962 // If we trashed any profiles they may have been merged, so send out |
| 1094 void WebDataService::UpdateAutofillProfileImpl( | 963 // update notifications as well. |
| 1095 GenericRequest<AutofillProfile>* request) { | 964 if (!guids.empty()) { |
| 1096 InitializeDatabaseIfNecessary(); | 965 std::vector<AutofillProfile*> profiles; |
| 1097 if (db_ && !request->IsCancelled()) { | 966 db_->GetAutofillTable()->GetAutofillProfiles(&profiles); |
| 1098 const AutofillProfile& profile = request->arg(); | 967 for (std::vector<AutofillProfile*>::const_iterator |
| 1099 | 968 iter = profiles.begin(); |
| 1100 // Only perform the update if the profile exists. It is currently | 969 iter != profiles.end(); ++iter) { |
| 1101 // valid to try to update a missing profile. We simply drop the write and | 970 AutofillProfileChange change(AutofillProfileChange::UPDATE, |
| 1102 // the caller will detect this on the next refresh. | 971 (*iter)->guid(), *iter); |
| 1103 AutofillProfile* original_profile = NULL; | |
| 1104 if (!db_->GetAutofillTable()->GetAutofillProfile(profile.guid(), | |
| 1105 &original_profile)) { | |
| 1106 request->RequestComplete(); | |
| 1107 return; | |
| 1108 } | |
| 1109 scoped_ptr<AutofillProfile> scoped_profile(original_profile); | |
| 1110 | |
| 1111 if (!db_->GetAutofillTable()->UpdateAutofillProfileMulti(profile)) { | |
| 1112 NOTREACHED(); | |
| 1113 return; | |
| 1114 } | |
| 1115 ScheduleCommit(); | |
| 1116 | |
| 1117 // Send GUID-based notification. | |
| 1118 AutofillProfileChange change(AutofillProfileChange::UPDATE, | |
| 1119 profile.guid(), &profile); | |
| 1120 content::NotificationService::current()->Notify( | |
| 1121 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | |
| 1122 content::Source<WebDataService>(this), | |
| 1123 content::Details<AutofillProfileChange>(&change)); | |
| 1124 } | |
| 1125 request->RequestComplete(); | |
| 1126 } | |
| 1127 | |
| 1128 void WebDataService::RemoveAutofillProfileImpl( | |
| 1129 GenericRequest<std::string>* request) { | |
| 1130 InitializeDatabaseIfNecessary(); | |
| 1131 if (db_ && !request->IsCancelled()) { | |
| 1132 const std::string& guid = request->arg(); | |
| 1133 | |
| 1134 AutofillProfile* profile = NULL; | |
| 1135 if (!db_->GetAutofillTable()->GetAutofillProfile(guid, &profile)) { | |
| 1136 NOTREACHED(); | |
| 1137 return; | |
| 1138 } | |
| 1139 scoped_ptr<AutofillProfile> scoped_profile(profile); | |
| 1140 | |
| 1141 if (!db_->GetAutofillTable()->RemoveAutofillProfile(guid)) { | |
| 1142 NOTREACHED(); | |
| 1143 return; | |
| 1144 } | |
| 1145 ScheduleCommit(); | |
| 1146 | |
| 1147 // Send GUID-based notification. | |
| 1148 AutofillProfileChange change(AutofillProfileChange::REMOVE, guid, NULL); | |
| 1149 content::NotificationService::current()->Notify( | |
| 1150 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | |
| 1151 content::Source<WebDataService>(this), | |
| 1152 content::Details<AutofillProfileChange>(&change)); | |
| 1153 } | |
| 1154 request->RequestComplete(); | |
| 1155 } | |
| 1156 | |
| 1157 void WebDataService::GetAutofillProfilesImpl(WebDataRequest* request) { | |
| 1158 InitializeDatabaseIfNecessary(); | |
| 1159 if (db_ && !request->IsCancelled()) { | |
| 1160 std::vector<AutofillProfile*> profiles; | |
| 1161 db_->GetAutofillTable()->GetAutofillProfiles(&profiles); | |
| 1162 request->SetResult( | |
| 1163 new WDResult<std::vector<AutofillProfile*> >(AUTOFILL_PROFILES_RESULT, | |
| 1164 base::Bind(&WebDataService::DestroyAutofillProfileResult, | |
| 1165 base::Unretained(this)), profiles)); | |
| 1166 } | |
| 1167 request->RequestComplete(); | |
| 1168 } | |
| 1169 | |
| 1170 void WebDataService::EmptyMigrationTrashImpl( | |
| 1171 GenericRequest<bool>* request) { | |
| 1172 InitializeDatabaseIfNecessary(); | |
| 1173 if (db_ && !request->IsCancelled()) { | |
| 1174 bool notify_sync = request->arg(); | |
| 1175 if (notify_sync) { | |
| 1176 std::vector<std::string> guids; | |
| 1177 if (!db_->GetAutofillTable()->GetAutofillProfilesInTrash(&guids)) { | |
| 1178 NOTREACHED(); | |
| 1179 return; | |
| 1180 } | |
| 1181 | |
| 1182 for (std::vector<std::string>::const_iterator iter = guids.begin(); | |
| 1183 iter != guids.end(); ++iter) { | |
| 1184 // Send GUID-based notification. | |
| 1185 AutofillProfileChange change(AutofillProfileChange::REMOVE, | |
| 1186 *iter, NULL); | |
| 1187 content::NotificationService::current()->Notify( | 972 content::NotificationService::current()->Notify( |
| 1188 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 973 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 1189 content::Source<WebDataService>(this), | 974 content::Source<WebDataService>(this), |
| 1190 content::Details<AutofillProfileChange>(&change)); | 975 content::Details<AutofillProfileChange>(&change)); |
| 1191 } | 976 } |
| 1192 | 977 STLDeleteElements(&profiles); |
| 1193 // If we trashed any profiles they may have been merged, so send out | 978 } |
| 1194 // update notifications as well. | 979 } |
| 1195 if (!guids.empty()) { | 980 |
| 1196 std::vector<AutofillProfile*> profiles; | 981 if (!db_->GetAutofillTable()->EmptyAutofillProfilesTrash()) { |
| 1197 db_->GetAutofillTable()->GetAutofillProfiles(&profiles); | 982 NOTREACHED(); |
| 1198 for (std::vector<AutofillProfile*>::const_iterator | 983 return; |
| 1199 iter = profiles.begin(); | 984 } |
| 1200 iter != profiles.end(); ++iter) { | 985 ScheduleCommit(); |
| 1201 AutofillProfileChange change(AutofillProfileChange::UPDATE, | 986 } |
| 1202 (*iter)->guid(), *iter); | 987 |
| 1203 content::NotificationService::current()->Notify( | 988 void WebDataService::AddCreditCardImpl(const CreditCard& credit_card) { |
| 1204 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 989 if (!db_->GetAutofillTable()->AddCreditCard(credit_card)) { |
| 1205 content::Source<WebDataService>(this), | 990 NOTREACHED(); |
| 1206 content::Details<AutofillProfileChange>(&change)); | 991 return; |
| 1207 } | 992 } |
| 1208 STLDeleteElements(&profiles); | 993 ScheduleCommit(); |
| 1209 } | 994 |
| 1210 } | 995 // Send GUID-based notification. |
| 1211 | 996 AutofillCreditCardChange change(AutofillCreditCardChange::ADD, |
| 1212 if (!db_->GetAutofillTable()->EmptyAutofillProfilesTrash()) { | 997 credit_card.guid(), &credit_card); |
| 1213 NOTREACHED(); | 998 content::NotificationService::current()->Notify( |
| 1214 return; | 999 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| 1215 } | 1000 content::Source<WebDataService>(this), |
| 1216 ScheduleCommit(); | 1001 content::Details<AutofillCreditCardChange>(&change)); |
| 1217 } | 1002 } |
| 1218 request->RequestComplete(); | 1003 |
| 1219 } | 1004 void WebDataService::UpdateCreditCardImpl(const CreditCard& credit_card) { |
| 1220 | 1005 // It is currently valid to try to update a missing profile. We simply drop |
| 1221 void WebDataService::AddCreditCardImpl( | 1006 // the write and the caller will detect this on the next refresh. |
| 1222 GenericRequest<CreditCard>* request) { | 1007 CreditCard* original_credit_card = NULL; |
| 1223 InitializeDatabaseIfNecessary(); | 1008 if (!db_->GetAutofillTable()->GetCreditCard(credit_card.guid(), |
| 1224 if (db_ && !request->IsCancelled()) { | 1009 &original_credit_card)) { |
| 1225 const CreditCard& credit_card = request->arg(); | 1010 return; |
| 1226 if (!db_->GetAutofillTable()->AddCreditCard(credit_card)) { | 1011 } |
| 1227 NOTREACHED(); | 1012 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); |
| 1228 return; | 1013 |
| 1229 } | 1014 if (!db_->GetAutofillTable()->UpdateCreditCard(credit_card)) { |
| 1230 ScheduleCommit(); | 1015 NOTREACHED(); |
| 1231 | 1016 return; |
| 1232 // Send GUID-based notification. | 1017 } |
| 1233 AutofillCreditCardChange change(AutofillCreditCardChange::ADD, | 1018 ScheduleCommit(); |
| 1234 credit_card.guid(), &credit_card); | 1019 |
| 1235 content::NotificationService::current()->Notify( | 1020 // Send GUID-based notification. |
| 1236 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, | 1021 AutofillCreditCardChange change(AutofillCreditCardChange::UPDATE, |
| 1237 content::Source<WebDataService>(this), | 1022 credit_card.guid(), &credit_card); |
| 1238 content::Details<AutofillCreditCardChange>(&change)); | 1023 content::NotificationService::current()->Notify( |
| 1239 } | 1024 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| 1240 request->RequestComplete(); | 1025 content::Source<WebDataService>(this), |
| 1241 } | 1026 content::Details<AutofillCreditCardChange>(&change)); |
| 1242 | 1027 } |
| 1243 void WebDataService::UpdateCreditCardImpl( | 1028 |
| 1244 GenericRequest<CreditCard>* request) { | 1029 void WebDataService::RemoveCreditCardImpl(const std::string& guid) { |
| 1245 InitializeDatabaseIfNecessary(); | 1030 if (!db_->GetAutofillTable()->RemoveCreditCard(guid)) { |
| 1246 if (db_ && !request->IsCancelled()) { | 1031 NOTREACHED(); |
| 1247 const CreditCard& credit_card = request->arg(); | 1032 return; |
| 1248 | 1033 } |
| 1249 // It is currently valid to try to update a missing profile. We simply drop | 1034 ScheduleCommit(); |
| 1250 // the write and the caller will detect this on the next refresh. | 1035 |
| 1251 CreditCard* original_credit_card = NULL; | 1036 // Send GUID-based notification. |
| 1252 if (!db_->GetAutofillTable()->GetCreditCard(credit_card.guid(), | 1037 AutofillCreditCardChange change(AutofillCreditCardChange::REMOVE, guid, |
| 1253 &original_credit_card)) { | 1038 NULL); |
| 1254 request->RequestComplete(); | 1039 content::NotificationService::current()->Notify( |
| 1255 return; | 1040 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| 1256 } | 1041 content::Source<WebDataService>(this), |
| 1257 scoped_ptr<CreditCard> scoped_credit_card(original_credit_card); | 1042 content::Details<AutofillCreditCardChange>(&change)); |
| 1258 | 1043 } |
| 1259 if (!db_->GetAutofillTable()->UpdateCreditCard(credit_card)) { | 1044 |
| 1260 NOTREACHED(); | 1045 WDTypedResult* WebDataService::GetCreditCardsImpl() { |
| 1261 return; | 1046 std::vector<CreditCard*> credit_cards; |
| 1262 } | 1047 db_->GetAutofillTable()->GetCreditCards(&credit_cards); |
| 1263 ScheduleCommit(); | 1048 return new WDResult<std::vector<CreditCard*> >(AUTOFILL_CREDITCARDS_RESULT, |
| 1264 | 1049 base::Bind(&WebDataService::DestroyAutofillCreditCardResult, |
| 1265 // Send GUID-based notification. | 1050 base::Unretained(this)), credit_cards); |
| 1266 AutofillCreditCardChange change(AutofillCreditCardChange::UPDATE, | |
| 1267 credit_card.guid(), &credit_card); | |
| 1268 content::NotificationService::current()->Notify( | |
| 1269 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, | |
| 1270 content::Source<WebDataService>(this), | |
| 1271 content::Details<AutofillCreditCardChange>(&change)); | |
| 1272 } | |
| 1273 request->RequestComplete(); | |
| 1274 } | |
| 1275 | |
| 1276 void WebDataService::RemoveCreditCardImpl( | |
| 1277 GenericRequest<std::string>* request) { | |
| 1278 InitializeDatabaseIfNecessary(); | |
| 1279 if (db_ && !request->IsCancelled()) { | |
| 1280 const std::string& guid = request->arg(); | |
| 1281 if (!db_->GetAutofillTable()->RemoveCreditCard(guid)) { | |
| 1282 NOTREACHED(); | |
| 1283 return; | |
| 1284 } | |
| 1285 ScheduleCommit(); | |
| 1286 | |
| 1287 // Send GUID-based notification. | |
| 1288 AutofillCreditCardChange change(AutofillCreditCardChange::REMOVE, guid, | |
| 1289 NULL); | |
| 1290 content::NotificationService::current()->Notify( | |
| 1291 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, | |
| 1292 content::Source<WebDataService>(this), | |
| 1293 content::Details<AutofillCreditCardChange>(&change)); | |
| 1294 } | |
| 1295 request->RequestComplete(); | |
| 1296 } | |
| 1297 | |
| 1298 void WebDataService::GetCreditCardsImpl(WebDataRequest* request) { | |
| 1299 InitializeDatabaseIfNecessary(); | |
| 1300 if (db_ && !request->IsCancelled()) { | |
| 1301 std::vector<CreditCard*> credit_cards; | |
| 1302 db_->GetAutofillTable()->GetCreditCards(&credit_cards); | |
| 1303 request->SetResult( | |
| 1304 new WDResult<std::vector<CreditCard*> >(AUTOFILL_CREDITCARDS_RESULT, | |
| 1305 base::Bind(&WebDataService::DestroyAutofillCreditCardResult, | |
| 1306 base::Unretained(this)), credit_cards)); | |
| 1307 } | |
| 1308 request->RequestComplete(); | |
| 1309 } | 1051 } |
| 1310 | 1052 |
| 1311 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( | 1053 void WebDataService::RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( |
| 1312 GenericRequest2<Time, Time>* request) { | 1054 const base::Time& delete_begin, const base::Time& delete_end) { |
| 1313 InitializeDatabaseIfNecessary(); | 1055 std::vector<std::string> profile_guids; |
| 1314 if (db_ && !request->IsCancelled()) { | 1056 std::vector<std::string> credit_card_guids; |
| 1315 std::vector<std::string> profile_guids; | 1057 if (db_->GetAutofillTable()-> |
| 1316 std::vector<std::string> credit_card_guids; | 1058 RemoveAutofillProfilesAndCreditCardsModifiedBetween( |
| 1317 if (db_->GetAutofillTable()-> | 1059 delete_begin, |
| 1318 RemoveAutofillProfilesAndCreditCardsModifiedBetween( | 1060 delete_end, |
| 1319 request->arg1(), | 1061 &profile_guids, |
| 1320 request->arg2(), | 1062 &credit_card_guids)) { |
| 1321 &profile_guids, | 1063 for (std::vector<std::string>::iterator iter = profile_guids.begin(); |
| 1322 &credit_card_guids)) { | 1064 iter != profile_guids.end(); ++iter) { |
| 1323 for (std::vector<std::string>::iterator iter = profile_guids.begin(); | 1065 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, |
| 1324 iter != profile_guids.end(); ++iter) { | 1066 NULL); |
| 1325 AutofillProfileChange change(AutofillProfileChange::REMOVE, *iter, | 1067 content::NotificationService::current()->Notify( |
| 1326 NULL); | 1068 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, |
| 1327 content::NotificationService::current()->Notify( | 1069 content::Source<WebDataService>(this), |
| 1328 chrome::NOTIFICATION_AUTOFILL_PROFILE_CHANGED, | 1070 content::Details<AutofillProfileChange>(&change)); |
| 1329 content::Source<WebDataService>(this), | 1071 } |
| 1330 content::Details<AutofillProfileChange>(&change)); | 1072 |
| 1331 } | 1073 for (std::vector<std::string>::iterator iter = credit_card_guids.begin(); |
| 1332 | 1074 iter != credit_card_guids.end(); ++iter) { |
| 1333 for (std::vector<std::string>::iterator iter = credit_card_guids.begin(); | 1075 AutofillCreditCardChange change(AutofillCreditCardChange::REMOVE, |
| 1334 iter != credit_card_guids.end(); ++iter) { | 1076 *iter, NULL); |
| 1335 AutofillCreditCardChange change(AutofillCreditCardChange::REMOVE, | 1077 content::NotificationService::current()->Notify( |
| 1336 *iter, NULL); | 1078 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, |
| 1337 content::NotificationService::current()->Notify( | 1079 content::Source<WebDataService>(this), |
| 1338 chrome::NOTIFICATION_AUTOFILL_CREDIT_CARD_CHANGED, | 1080 content::Details<AutofillCreditCardChange>(&change)); |
| 1339 content::Source<WebDataService>(this), | 1081 } |
| 1340 content::Details<AutofillCreditCardChange>(&change)); | 1082 // Note: It is the caller's responsibility to post notifications for any |
| 1341 } | 1083 // changes, e.g. by calling the Refresh() method of PersonalDataManager. |
| 1342 // Note: It is the caller's responsibility to post notifications for any | 1084 ScheduleCommit(); |
| 1343 // changes, e.g. by calling the Refresh() method of PersonalDataManager. | 1085 } |
| 1344 ScheduleCommit(); | |
| 1345 } | |
| 1346 } | |
| 1347 request->RequestComplete(); | |
| 1348 } | 1086 } |
| 1349 | 1087 |
| 1350 AutofillProfileSyncableService* | 1088 AutofillProfileSyncableService* |
| 1351 WebDataService::GetAutofillProfileSyncableService() const { | 1089 WebDataService::GetAutofillProfileSyncableService() const { |
| 1352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); | 1090 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::DB)); |
| 1353 DCHECK(autofill_profile_syncable_service_); // Make sure we're initialized. | 1091 DCHECK(autofill_profile_syncable_service_); // Make sure we're initialized. |
| 1354 | 1092 |
| 1355 return autofill_profile_syncable_service_; | 1093 return autofill_profile_syncable_service_; |
| 1356 } | 1094 } |
| 1357 | 1095 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1373 | 1111 |
| 1374 void WebDataService::DestroyAutofillCreditCardResult( | 1112 void WebDataService::DestroyAutofillCreditCardResult( |
| 1375 const WDTypedResult* result) { | 1113 const WDTypedResult* result) { |
| 1376 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); | 1114 DCHECK(result->GetType() == AUTOFILL_CREDITCARDS_RESULT); |
| 1377 const WDResult<std::vector<CreditCard*> >* r = | 1115 const WDResult<std::vector<CreditCard*> >* r = |
| 1378 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); | 1116 static_cast<const WDResult<std::vector<CreditCard*> >*>(result); |
| 1379 | 1117 |
| 1380 std::vector<CreditCard*> credit_cards = r->GetValue(); | 1118 std::vector<CreditCard*> credit_cards = r->GetValue(); |
| 1381 STLDeleteElements(&credit_cards); | 1119 STLDeleteElements(&credit_cards); |
| 1382 } | 1120 } |
| OLD | NEW |