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 // Chromium settings and storage represent user-selected preferences and | 5 // Chromium settings and storage represent user-selected preferences and |
6 // information and MUST not be extracted, overwritten or modified except | 6 // information and MUST not be extracted, overwritten or modified except |
7 // through Chromium defined APIs. | 7 // through Chromium defined APIs. |
8 | 8 |
9 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ | 9 #ifndef CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ |
10 #define CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ | 10 #define CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ |
11 | 11 |
12 #include <map> | 12 #include <map> |
13 #include <string> | 13 #include <string> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
| 16 #include "base/callback.h" |
16 #include "base/callback_forward.h" | 17 #include "base/callback_forward.h" |
17 #include "base/file_path.h" | 18 #include "base/file_path.h" |
18 #include "base/location.h" | 19 #include "base/location.h" |
19 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
20 #include "base/sequenced_task_runner_helpers.h" | 21 #include "base/sequenced_task_runner_helpers.h" |
21 #include "base/synchronization/lock.h" | 22 #include "base/synchronization/lock.h" |
22 #include "chrome/browser/api/webdata/autofill_web_data_service.h" | 23 #include "chrome/browser/api/webdata/autofill_web_data_service.h" |
23 #include "chrome/browser/api/webdata/web_data_results.h" | 24 #include "chrome/browser/api/webdata/web_data_results.h" |
24 #include "chrome/browser/api/webdata/web_data_service_base.h" | 25 #include "chrome/browser/api/webdata/web_data_service_base.h" |
25 #include "chrome/browser/api/webdata/web_data_service_consumer.h" | 26 #include "chrome/browser/api/webdata/web_data_service_consumer.h" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 | 64 |
64 | 65 |
65 //////////////////////////////////////////////////////////////////////////////// | 66 //////////////////////////////////////////////////////////////////////////////// |
66 // | 67 // |
67 // WebDataService results | 68 // WebDataService results |
68 // | 69 // |
69 //////////////////////////////////////////////////////////////////////////////// | 70 //////////////////////////////////////////////////////////////////////////////// |
70 | 71 |
71 typedef std::vector<AutofillChange> AutofillChangeList; | 72 typedef std::vector<AutofillChange> AutofillChangeList; |
72 | 73 |
| 74 typedef base::Callback<WDTypedResult*(void)> ResultTask; |
| 75 |
73 // Result from GetWebAppImages. | 76 // Result from GetWebAppImages. |
74 struct WDAppImagesResult { | 77 struct WDAppImagesResult { |
75 WDAppImagesResult(); | 78 WDAppImagesResult(); |
76 ~WDAppImagesResult(); | 79 ~WDAppImagesResult(); |
77 | 80 |
78 // True if SetWebAppHasAllImages(true) was invoked. | 81 // True if SetWebAppHasAllImages(true) was invoked. |
79 bool has_all_images; | 82 bool has_all_images; |
80 | 83 |
81 // The images, may be empty. | 84 // The images, may be empty. |
82 std::vector<SkBitmap> images; | 85 std::vector<SkBitmap> images; |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 ////////////////////////////////////////////////////////////////////////////// | 334 ////////////////////////////////////////////////////////////////////////////// |
332 // | 335 // |
333 // The following methods are only invoked in the web data service thread. | 336 // The following methods are only invoked in the web data service thread. |
334 // | 337 // |
335 ////////////////////////////////////////////////////////////////////////////// | 338 ////////////////////////////////////////////////////////////////////////////// |
336 private: | 339 private: |
337 friend struct content::BrowserThread::DeleteOnThread< | 340 friend struct content::BrowserThread::DeleteOnThread< |
338 content::BrowserThread::UI>; | 341 content::BrowserThread::UI>; |
339 friend class base::DeleteHelper<WebDataService>; | 342 friend class base::DeleteHelper<WebDataService>; |
340 | 343 |
341 typedef GenericRequest2<std::vector<const TemplateURLData*>, | |
342 KeywordTable::Keywords> SetKeywordsRequest; | |
343 | |
344 // Invoked on the main thread if initializing the db fails. | 344 // Invoked on the main thread if initializing the db fails. |
345 void DBInitFailed(sql::InitStatus init_status); | 345 void DBInitFailed(sql::InitStatus init_status); |
346 | 346 |
347 // Initialize the database, if it hasn't already been initialized. | 347 // Initialize the database, if it hasn't already been initialized. |
348 void InitializeDatabaseIfNecessary(); | 348 void InitializeDatabaseIfNecessary(); |
349 | 349 |
350 // Initialize any syncable services. | 350 // Initialize any syncable services. |
351 void InitializeSyncableServices(); | 351 void InitializeSyncableServices(); |
352 | 352 |
353 // The notification method. | 353 // The notification method. |
354 void NotifyDatabaseLoadedOnUIThread(); | 354 void NotifyDatabaseLoadedOnUIThread(); |
355 | 355 |
356 // Commit any pending transaction and deletes the database. | 356 // Commit any pending transaction and deletes the database. |
357 void ShutdownDatabase(); | 357 void ShutdownDatabase(); |
358 | 358 |
359 // Deletes the syncable services. | 359 // Deletes the syncable services. |
360 void ShutdownSyncableServices(); | 360 void ShutdownSyncableServices(); |
361 | 361 |
362 // Commit the current transaction and creates a new one. | 362 // Commit the current transaction and creates a new one. |
363 void Commit(); | 363 void Commit(); |
364 | 364 |
365 // Schedule a task on our worker thread. | 365 // Schedule a task on our worker thread. |
366 void ScheduleTask(const tracked_objects::Location& from_here, | 366 void ScheduleTask(const tracked_objects::Location& from_here, |
367 const base::Closure& task); | 367 const base::Closure& task); |
368 | 368 |
| 369 void ScheduleDBTask(const tracked_objects::Location& from_here, |
| 370 const base::Closure& task); |
| 371 |
| 372 WebDataService::Handle ScheduleDBTaskWithResult( |
| 373 const tracked_objects::Location& from_here, |
| 374 const ResultTask& task, |
| 375 WebDataServiceConsumer* consumer); |
| 376 |
| 377 void DBTaskWrapper(const base::Closure& task, |
| 378 WebDataRequest* request); |
| 379 |
| 380 void DBResultTaskWrapper(const ResultTask& task, |
| 381 WebDataRequest* request); |
| 382 |
369 // Schedule a commit if one is not already pending. | 383 // Schedule a commit if one is not already pending. |
370 void ScheduleCommit(); | 384 void ScheduleCommit(); |
371 | 385 |
372 ////////////////////////////////////////////////////////////////////////////// | 386 ////////////////////////////////////////////////////////////////////////////// |
373 // | 387 // |
374 // Keywords. | 388 // Keywords. |
375 // | 389 // |
376 ////////////////////////////////////////////////////////////////////////////// | 390 ////////////////////////////////////////////////////////////////////////////// |
377 void AddKeywordImpl(GenericRequest<TemplateURLData>* request); | 391 void AddKeywordImpl(const TemplateURLData& data); |
378 void RemoveKeywordImpl(GenericRequest<TemplateURLID>* request); | 392 void RemoveKeywordImpl(TemplateURLID id); |
379 void UpdateKeywordImpl(GenericRequest<TemplateURLData>* request); | 393 void UpdateKeywordImpl(const TemplateURLData& data); |
380 void GetKeywordsImpl(WebDataRequest* request); | 394 WDTypedResult* GetKeywordsImpl(); |
381 void SetDefaultSearchProviderImpl(GenericRequest<TemplateURLID>* r); | 395 void SetDefaultSearchProviderImpl(TemplateURLID r); |
382 void SetBuiltinKeywordVersionImpl(GenericRequest<int>* r); | 396 void SetBuiltinKeywordVersionImpl(int version); |
383 | 397 |
384 ////////////////////////////////////////////////////////////////////////////// | 398 ////////////////////////////////////////////////////////////////////////////// |
385 // | 399 // |
386 // Web Apps. | 400 // Web Apps. |
387 // | 401 // |
388 ////////////////////////////////////////////////////////////////////////////// | 402 ////////////////////////////////////////////////////////////////////////////// |
389 void SetWebAppImageImpl(GenericRequest2<GURL, SkBitmap>* request); | 403 |
390 void SetWebAppHasAllImagesImpl(GenericRequest2<GURL, bool>* request); | 404 void SetWebAppImageImpl(const GURL& app_url, const SkBitmap& image); |
391 void RemoveWebAppImpl(GenericRequest<GURL>* request); | 405 void SetWebAppHasAllImagesImpl(const GURL& app_url, bool has_all_images); |
392 void GetWebAppImagesImpl(GenericRequest<GURL>* request); | 406 void RemoveWebAppImpl(const GURL& app_url); |
| 407 WDTypedResult* GetWebAppImagesImpl(const GURL& app_url); |
393 | 408 |
394 ////////////////////////////////////////////////////////////////////////////// | 409 ////////////////////////////////////////////////////////////////////////////// |
395 // | 410 // |
396 // Web Intents. | 411 // Web Intents. |
397 // | 412 // |
398 ////////////////////////////////////////////////////////////////////////////// | 413 ////////////////////////////////////////////////////////////////////////////// |
399 void AddWebIntentServiceImpl( | 414 void AddWebIntentServiceImpl( |
400 GenericRequest<webkit_glue::WebIntentServiceData>* request); | 415 const webkit_glue::WebIntentServiceData& service); |
401 void RemoveWebIntentServiceImpl( | 416 void RemoveWebIntentServiceImpl( |
402 GenericRequest<webkit_glue::WebIntentServiceData>* request); | 417 const webkit_glue::WebIntentServiceData& service); |
403 void GetWebIntentServicesImpl(GenericRequest<string16>* request); | 418 WDTypedResult* GetWebIntentServicesImpl(const string16& action); |
404 void GetWebIntentServicesForURLImpl(GenericRequest<string16>* request); | 419 WDTypedResult* GetWebIntentServicesForURLImpl(const string16& service_url); |
405 void GetAllWebIntentServicesImpl(GenericRequest<std::string>* request); | 420 WDTypedResult* GetAllWebIntentServicesImpl(); |
406 void AddDefaultWebIntentServiceImpl( | 421 void AddDefaultWebIntentServiceImpl(const DefaultWebIntentService& service); |
407 GenericRequest<DefaultWebIntentService>* request); | |
408 void RemoveDefaultWebIntentServiceImpl( | 422 void RemoveDefaultWebIntentServiceImpl( |
409 GenericRequest<DefaultWebIntentService>* request); | 423 const DefaultWebIntentService& service); |
410 void RemoveWebIntentServiceDefaultsImpl(GenericRequest<GURL>* request); | 424 void RemoveWebIntentServiceDefaultsImpl(const GURL& service_url); |
411 void GetDefaultWebIntentServicesForActionImpl( | 425 WDTypedResult* GetDefaultWebIntentServicesForActionImpl( |
412 GenericRequest<string16>* request); | 426 const string16& action); |
413 void GetAllDefaultWebIntentServicesImpl(GenericRequest<std::string>* request); | 427 WDTypedResult* GetAllDefaultWebIntentServicesImpl(); |
414 | 428 |
415 ////////////////////////////////////////////////////////////////////////////// | 429 ////////////////////////////////////////////////////////////////////////////// |
416 // | 430 // |
417 // Token Service. | 431 // Token Service. |
418 // | 432 // |
419 ////////////////////////////////////////////////////////////////////////////// | 433 ////////////////////////////////////////////////////////////////////////////// |
420 | 434 |
421 void RemoveAllTokensImpl(GenericRequest<std::string>* request); | 435 void RemoveAllTokensImpl(); |
422 void SetTokenForServiceImpl( | 436 void SetTokenForServiceImpl(const std::string& service, |
423 GenericRequest2<std::string, std::string>* request); | 437 const std::string& token); |
424 void GetAllTokensImpl(GenericRequest<std::string>* request); | 438 WDTypedResult* GetAllTokensImpl(); |
425 | 439 |
426 #if defined(OS_WIN) | 440 #if defined(OS_WIN) |
427 ////////////////////////////////////////////////////////////////////////////// | 441 ////////////////////////////////////////////////////////////////////////////// |
428 // | 442 // |
429 // Password manager. | 443 // Password manager. |
430 // | 444 // |
431 ////////////////////////////////////////////////////////////////////////////// | 445 ////////////////////////////////////////////////////////////////////////////// |
432 void AddIE7LoginImpl(GenericRequest<IE7PasswordInfo>* request); | 446 void AddIE7LoginImpl(const IE7PasswordInfo& info); |
433 void RemoveIE7LoginImpl(GenericRequest<IE7PasswordInfo>* request); | 447 void RemoveIE7LoginImpl(const IE7PasswordInfo& info); |
434 void GetIE7LoginImpl(GenericRequest<IE7PasswordInfo>* request); | 448 WDTypedResult* GetIE7LoginImpl(const IE7PasswordInfo& info); |
435 #endif // defined(OS_WIN) | 449 #endif // defined(OS_WIN) |
436 | 450 |
437 ////////////////////////////////////////////////////////////////////////////// | 451 ////////////////////////////////////////////////////////////////////////////// |
438 // | 452 // |
439 // Autofill. | 453 // Autofill. |
440 // | 454 // |
441 ////////////////////////////////////////////////////////////////////////////// | 455 ////////////////////////////////////////////////////////////////////////////// |
442 void AddFormElementsImpl( | 456 void AddFormElementsImpl(const std::vector<FormFieldData>& fields); |
443 GenericRequest<std::vector<FormFieldData> >* request); | 457 WDTypedResult* GetFormValuesForElementNameImpl( |
444 void GetFormValuesForElementNameImpl(WebDataRequest* request, | |
445 const string16& name, const string16& prefix, int limit); | 458 const string16& name, const string16& prefix, int limit); |
446 void RemoveFormElementsAddedBetweenImpl( | 459 void RemoveFormElementsAddedBetweenImpl( |
447 GenericRequest2<base::Time, base::Time>* request); | 460 const base::Time& delete_begin, const base::Time& delete_end); |
448 void RemoveExpiredFormElementsImpl(WebDataRequest* request); | 461 void RemoveExpiredFormElementsImpl(); |
449 void RemoveFormValueForElementNameImpl( | 462 void RemoveFormValueForElementNameImpl(const string16& name, |
450 GenericRequest2<string16, string16>* request); | 463 const string16& value); |
451 void AddAutofillProfileImpl(GenericRequest<AutofillProfile>* request); | 464 void AddAutofillProfileImpl(const AutofillProfile& profile); |
452 void UpdateAutofillProfileImpl(GenericRequest<AutofillProfile>* request); | 465 void UpdateAutofillProfileImpl(const AutofillProfile& profile); |
453 void RemoveAutofillProfileImpl(GenericRequest<std::string>* request); | 466 void RemoveAutofillProfileImpl(const std::string& guid); |
454 void GetAutofillProfilesImpl(WebDataRequest* request); | 467 WDTypedResult* GetAutofillProfilesImpl(); |
455 void EmptyMigrationTrashImpl(GenericRequest<bool>* request); | 468 void EmptyMigrationTrashImpl(bool notify_sync); |
456 void AddCreditCardImpl(GenericRequest<CreditCard>* request); | 469 void AddCreditCardImpl(const CreditCard& credit_card); |
457 void UpdateCreditCardImpl(GenericRequest<CreditCard>* request); | 470 void UpdateCreditCardImpl(const CreditCard& credit_card); |
458 void RemoveCreditCardImpl(GenericRequest<std::string>* request); | 471 void RemoveCreditCardImpl(const std::string& guid); |
459 void GetCreditCardsImpl(WebDataRequest* request); | 472 WDTypedResult* GetCreditCardsImpl(); |
460 void RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( | 473 void RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( |
461 GenericRequest2<base::Time, base::Time>* request); | 474 const base::Time& delete_begin, const base::Time& delete_end); |
462 | 475 |
463 // Callbacks to ensure that sensitive info is destroyed if request is | 476 // Callbacks to ensure that sensitive info is destroyed if request is |
464 // cancelled. | 477 // cancelled. |
465 void DestroyAutofillProfileResult(const WDTypedResult* result); | 478 void DestroyAutofillProfileResult(const WDTypedResult* result); |
466 void DestroyAutofillCreditCardResult(const WDTypedResult* result); | 479 void DestroyAutofillCreditCardResult(const WDTypedResult* result); |
467 | 480 |
468 // True once initialization has started. | 481 // True once initialization has started. |
469 bool is_running_; | 482 bool is_running_; |
470 | 483 |
471 // The path with which to initialize the database. | 484 // The path with which to initialize the database. |
(...skipping 21 matching lines...) Expand all Loading... |
493 // Whether we should commit the database. | 506 // Whether we should commit the database. |
494 bool should_commit_; | 507 bool should_commit_; |
495 | 508 |
496 // MessageLoop the WebDataService is created on. | 509 // MessageLoop the WebDataService is created on. |
497 MessageLoop* main_loop_; | 510 MessageLoop* main_loop_; |
498 | 511 |
499 DISALLOW_COPY_AND_ASSIGN(WebDataService); | 512 DISALLOW_COPY_AND_ASSIGN(WebDataService); |
500 }; | 513 }; |
501 | 514 |
502 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ | 515 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ |
OLD | NEW |