| 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> | |
| 15 | 14 |
| 16 #include "base/callback_forward.h" | 15 #include "base/callback_forward.h" |
| 17 #include "base/files/file_path.h" | 16 #include "base/files/file_path.h" |
| 18 #include "base/location.h" | 17 #include "base/location.h" |
| 19 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 19 #include "base/observer_list.h" |
| 20 #include "base/sequenced_task_runner_helpers.h" | 20 #include "base/sequenced_task_runner_helpers.h" |
| 21 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
| 22 #include "chrome/browser/api/webdata/autofill_web_data_service.h" | 22 #include "chrome/browser/api/webdata/autofill_web_data.h" |
| 23 #include "chrome/browser/api/webdata/web_data_results.h" | 23 #include "chrome/browser/api/webdata/web_data_results.h" |
| 24 #include "chrome/browser/api/webdata/web_data_service_base.h" | 24 #include "chrome/browser/api/webdata/web_data_service_base.h" |
| 25 #include "chrome/browser/api/webdata/web_data_service_consumer.h" | 25 #include "chrome/browser/api/webdata/web_data_service_consumer.h" |
| 26 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" | 26 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" |
| 27 #include "chrome/browser/search_engines/template_url.h" | 27 #include "chrome/browser/search_engines/template_url.h" |
| 28 #include "chrome/browser/search_engines/template_url_id.h" | 28 #include "chrome/browser/search_engines/template_url_id.h" |
| 29 #include "chrome/browser/webdata/keyword_table.h" | 29 #include "chrome/browser/webdata/keyword_table.h" |
| 30 #include "chrome/browser/webdata/web_data_request_manager.h" | 30 #include "chrome/browser/webdata/web_data_request_manager.h" |
| 31 #include "chrome/browser/webdata/web_database.h" | 31 #include "chrome/browser/webdata/web_database.h" |
| 32 #include "components/autofill/common/form_field_data.h" |
| 32 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 33 #include "sql/init_status.h" | 34 #include "sql/init_status.h" |
| 34 | 35 |
| 35 class AutocompleteSyncableService; | 36 class AutocompleteSyncableService; |
| 36 class AutofillChange; | 37 class AutofillChange; |
| 38 class AutofillProfile; |
| 37 class AutofillProfileSyncableService; | 39 class AutofillProfileSyncableService; |
| 40 class CreditCard; |
| 38 struct DefaultWebIntentService; | 41 struct DefaultWebIntentService; |
| 39 class GURL; | 42 class GURL; |
| 40 #if defined(OS_WIN) | 43 #if defined(OS_WIN) |
| 41 struct IE7PasswordInfo; | 44 struct IE7PasswordInfo; |
| 42 #endif | 45 #endif |
| 43 class MessageLoop; | 46 class MessageLoop; |
| 44 class Profile; | 47 class Profile; |
| 45 class SkBitmap; | 48 class SkBitmap; |
| 46 class WebDatabaseService; | 49 class WebDatabaseService; |
| 47 | 50 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 62 // | 65 // |
| 63 //////////////////////////////////////////////////////////////////////////////// | 66 //////////////////////////////////////////////////////////////////////////////// |
| 64 | 67 |
| 65 | 68 |
| 66 //////////////////////////////////////////////////////////////////////////////// | 69 //////////////////////////////////////////////////////////////////////////////// |
| 67 // | 70 // |
| 68 // WebDataService results | 71 // WebDataService results |
| 69 // | 72 // |
| 70 //////////////////////////////////////////////////////////////////////////////// | 73 //////////////////////////////////////////////////////////////////////////////// |
| 71 | 74 |
| 72 typedef std::vector<AutofillChange> AutofillChangeList; | |
| 73 | |
| 74 typedef base::Callback<scoped_ptr<WDTypedResult>(void)> ResultTask; | 75 typedef base::Callback<scoped_ptr<WDTypedResult>(void)> ResultTask; |
| 75 | 76 |
| 76 // Result from GetWebAppImages. | 77 // Result from GetWebAppImages. |
| 77 struct WDAppImagesResult { | 78 struct WDAppImagesResult { |
| 78 WDAppImagesResult(); | 79 WDAppImagesResult(); |
| 79 ~WDAppImagesResult(); | 80 ~WDAppImagesResult(); |
| 80 | 81 |
| 81 // True if SetWebAppHasAllImages(true) was invoked. | 82 // True if SetWebAppHasAllImages(true) was invoked. |
| 82 bool has_all_images; | 83 bool has_all_images; |
| 83 | 84 |
| 84 // The images, may be empty. | 85 // The images, may be empty. |
| 85 std::vector<SkBitmap> images; | 86 std::vector<SkBitmap> images; |
| 86 }; | 87 }; |
| 87 | 88 |
| 88 struct WDKeywordsResult { | 89 struct WDKeywordsResult { |
| 89 WDKeywordsResult(); | 90 WDKeywordsResult(); |
| 90 ~WDKeywordsResult(); | 91 ~WDKeywordsResult(); |
| 91 | 92 |
| 92 KeywordTable::Keywords keywords; | 93 KeywordTable::Keywords keywords; |
| 93 // Identifies the ID of the TemplateURL that is the default search. A value of | 94 // Identifies the ID of the TemplateURL that is the default search. A value of |
| 94 // 0 indicates there is no default search provider. | 95 // 0 indicates there is no default search provider. |
| 95 int64 default_search_provider_id; | 96 int64 default_search_provider_id; |
| 96 // Version of the built-in keywords. A value of 0 indicates a first run. | 97 // Version of the built-in keywords. A value of 0 indicates a first run. |
| 97 int builtin_keyword_version; | 98 int builtin_keyword_version; |
| 98 }; | 99 }; |
| 99 | 100 |
| 100 class WebDataServiceConsumer; | 101 class WebDataServiceConsumer; |
| 102 class WebDataServiceObserver; |
| 101 | 103 |
| 102 class WebDataService | 104 class WebDataService |
| 103 : public WebDataServiceBase, | 105 : public WebDataServiceBase, |
| 104 public AutofillWebData, | 106 public AutofillWebData, |
| 105 public RefcountedProfileKeyedService { | 107 public RefcountedProfileKeyedService { |
| 106 public: | 108 public: |
| 107 explicit WebDataService(WebDatabaseService* wdbs); | 109 explicit WebDataService(WebDatabaseService* wdbs); |
| 108 | 110 |
| 109 // WebDataServiceBase implementation. | 111 // WebDataServiceBase implementation. |
| 110 virtual void CancelRequest(Handle h) OVERRIDE; | 112 virtual void CancelRequest(Handle h) OVERRIDE; |
| 111 virtual content::NotificationSource GetNotificationSource() OVERRIDE; | |
| 112 | 113 |
| 113 // Notifies listeners on the UI thread that multiple changes have been made to | 114 // Notifies listeners on the UI thread that multiple changes have been made to |
| 114 // to Autofill records of the database. | 115 // to Autofill records of the database. |
| 115 // NOTE: This method is intended to be called from the DB thread. It | 116 // NOTE: This method is intended to be called from the DB thread. It |
| 116 // it asynchronously notifies listeners on the UI thread. | 117 // it asynchronously notifies listeners on the UI thread. |
| 117 // |web_data_service| may be NULL for testing purposes. | 118 // |web_data_service| may be NULL for testing purposes. |
| 118 static void NotifyOfMultipleAutofillChanges(WebDataService* web_data_service); | 119 static void NotifyOfMultipleAutofillChanges(WebDataService* web_data_service); |
| 119 | 120 |
| 120 // RefcountedProfileKeyedService override: | 121 // RefcountedProfileKeyedService override: |
| 121 // Shutdown the web data service. The service can no longer be used after this | 122 // Shutdown the web data service. The service can no longer be used after this |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 // Returns the syncable service for Autofill addresses and credit cards stored | 299 // Returns the syncable service for Autofill addresses and credit cards stored |
| 299 // in this table. The returned service is owned by |this| object. | 300 // in this table. The returned service is owned by |this| object. |
| 300 virtual AutofillProfileSyncableService* | 301 virtual AutofillProfileSyncableService* |
| 301 GetAutofillProfileSyncableService() const; | 302 GetAutofillProfileSyncableService() const; |
| 302 | 303 |
| 303 // Returns the syncable service for field autocomplete stored in this table. | 304 // Returns the syncable service for field autocomplete stored in this table. |
| 304 // The returned service is owned by |this| object. | 305 // The returned service is owned by |this| object. |
| 305 virtual AutocompleteSyncableService* | 306 virtual AutocompleteSyncableService* |
| 306 GetAutocompleteSyncableService() const; | 307 GetAutocompleteSyncableService() const; |
| 307 | 308 |
| 309 void AddObserver(WebDataServiceObserver* observer); |
| 310 void RemoveObserver(WebDataServiceObserver* observer); |
| 311 |
| 308 protected: | 312 protected: |
| 309 friend class TemplateURLServiceTest; | 313 friend class TemplateURLServiceTest; |
| 310 friend class TemplateURLServiceTestingProfile; | 314 friend class TemplateURLServiceTestingProfile; |
| 311 friend class WebDataServiceTest; | 315 friend class WebDataServiceTest; |
| 312 friend class WebDataRequest; | 316 friend class WebDataRequest; |
| 313 | 317 |
| 314 virtual ~WebDataService(); | 318 virtual ~WebDataService(); |
| 315 | 319 |
| 316 ////////////////////////////////////////////////////////////////////////////// | 320 ////////////////////////////////////////////////////////////////////////////// |
| 317 // | 321 // |
| 318 // The following methods are only invoked in the web data service thread. | 322 // The following methods are only invoked in the web data service thread. |
| 319 // | 323 // |
| 320 ////////////////////////////////////////////////////////////////////////////// | 324 ////////////////////////////////////////////////////////////////////////////// |
| 325 |
| 326 void NotifyDatabaseLoadedOnUIThread(); |
| 327 |
| 321 private: | 328 private: |
| 322 friend struct content::BrowserThread::DeleteOnThread< | 329 friend struct content::BrowserThread::DeleteOnThread< |
| 323 content::BrowserThread::UI>; | 330 content::BrowserThread::UI>; |
| 324 friend class base::DeleteHelper<WebDataService>; | 331 friend class base::DeleteHelper<WebDataService>; |
| 325 | 332 |
| 326 // Initialize any syncable services. | 333 // Initialize any syncable services. |
| 327 void InitializeSyncableServices(); | 334 void InitializeSyncableServices(); |
| 328 | 335 |
| 329 // Deletes the syncable services. | 336 // Deletes the syncable services. |
| 330 void ShutdownSyncableServices(); | 337 void ShutdownSyncableServices(); |
| 331 | 338 |
| 332 void DBInitFailed(sql::InitStatus sql_status); | 339 void DBInitFailed(sql::InitStatus sql_status); |
| 333 void NotifyDatabaseLoadedOnUIThread(); | |
| 334 void OnDatabaseInit(sql::InitStatus status); | 340 void OnDatabaseInit(sql::InitStatus status); |
| 335 | 341 |
| 336 ////////////////////////////////////////////////////////////////////////////// | 342 ////////////////////////////////////////////////////////////////////////////// |
| 337 // | 343 // |
| 338 // Keywords. | 344 // Keywords. |
| 339 // | 345 // |
| 340 ////////////////////////////////////////////////////////////////////////////// | 346 ////////////////////////////////////////////////////////////////////////////// |
| 341 WebDatabase::State AddKeywordImpl( | 347 WebDatabase::State AddKeywordImpl( |
| 342 const TemplateURLData& data, WebDatabase* db); | 348 const TemplateURLData& data, WebDatabase* db); |
| 343 WebDatabase::State RemoveKeywordImpl( | 349 WebDatabase::State RemoveKeywordImpl( |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 WebDatabase::State AddCreditCardImpl( | 444 WebDatabase::State AddCreditCardImpl( |
| 439 const CreditCard& credit_card, WebDatabase* db); | 445 const CreditCard& credit_card, WebDatabase* db); |
| 440 WebDatabase::State UpdateCreditCardImpl( | 446 WebDatabase::State UpdateCreditCardImpl( |
| 441 const CreditCard& credit_card, WebDatabase* db); | 447 const CreditCard& credit_card, WebDatabase* db); |
| 442 WebDatabase::State RemoveCreditCardImpl( | 448 WebDatabase::State RemoveCreditCardImpl( |
| 443 const std::string& guid, WebDatabase* db); | 449 const std::string& guid, WebDatabase* db); |
| 444 scoped_ptr<WDTypedResult> GetCreditCardsImpl(WebDatabase* db); | 450 scoped_ptr<WDTypedResult> GetCreditCardsImpl(WebDatabase* db); |
| 445 WebDatabase::State RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( | 451 WebDatabase::State RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( |
| 446 const base::Time& delete_begin, const base::Time& delete_end, | 452 const base::Time& delete_begin, const base::Time& delete_end, |
| 447 WebDatabase* db); | 453 WebDatabase* db); |
| 454 void NotifyAutofillMultipleChangedOnUIThread(); |
| 448 | 455 |
| 449 // Callbacks to ensure that sensitive info is destroyed if request is | 456 // Callbacks to ensure that sensitive info is destroyed if request is |
| 450 // cancelled. | 457 // cancelled. |
| 451 void DestroyAutofillProfileResult(const WDTypedResult* result); | 458 void DestroyAutofillProfileResult(const WDTypedResult* result); |
| 452 void DestroyAutofillCreditCardResult(const WDTypedResult* result); | 459 void DestroyAutofillCreditCardResult(const WDTypedResult* result); |
| 453 | 460 |
| 454 // Our database service (not owned by us as it is a profile keyed service). | 461 // Our database service (not owned by us as it is a profile keyed service). |
| 455 WebDatabaseService* wdbs_; | 462 WebDatabaseService* wdbs_; |
| 456 | 463 |
| 457 // True if we've received a notification that the WebDatabase has loaded. | 464 // True if we've received a notification that the WebDatabase has loaded. |
| 458 bool db_loaded_; | 465 bool db_loaded_; |
| 459 | 466 |
| 460 // Syncable services for the database data. We own the services, but don't | 467 // Syncable services for the database data. We own the services, but don't |
| 461 // use |scoped_ptr|s because the lifetimes must be managed on the database | 468 // use |scoped_ptr|s because the lifetimes must be managed on the database |
| 462 // thread. | 469 // thread. |
| 463 // Currently only Autocomplete and Autofill profiles use the new Sync API, but | 470 // Currently only Autocomplete and Autofill profiles use the new Sync API, but |
| 464 // all the database data should migrate to this API over time. | 471 // all the database data should migrate to this API over time. |
| 465 AutocompleteSyncableService* autocomplete_syncable_service_; | 472 AutocompleteSyncableService* autocomplete_syncable_service_; |
| 466 AutofillProfileSyncableService* autofill_profile_syncable_service_; | 473 AutofillProfileSyncableService* autofill_profile_syncable_service_; |
| 467 | 474 |
| 475 ObserverList<WebDataServiceObserver> observer_list_; |
| 476 |
| 468 DISALLOW_COPY_AND_ASSIGN(WebDataService); | 477 DISALLOW_COPY_AND_ASSIGN(WebDataService); |
| 469 }; | 478 }; |
| 470 | 479 |
| 471 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ | 480 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ |
| OLD | NEW |