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 // 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 void NotifyDatabaseLoadedOnUIThread(); | |
| 
 
dhollowa
2013/03/12 22:22:28
It looks like you made this protected for use by t
 
kaiwang
2013/03/13 04:57:20
But it's FakeWebDataService in an anonymous namesp
 
dhollowa
2013/03/13 16:15:28
Ok.
 
 | |
| 326 | |
| 321 private: | 327 private: | 
| 322 friend struct content::BrowserThread::DeleteOnThread< | 328 friend struct content::BrowserThread::DeleteOnThread< | 
| 323 content::BrowserThread::UI>; | 329 content::BrowserThread::UI>; | 
| 324 friend class base::DeleteHelper<WebDataService>; | 330 friend class base::DeleteHelper<WebDataService>; | 
| 325 | 331 | 
| 326 // Initialize any syncable services. | 332 // Initialize any syncable services. | 
| 327 void InitializeSyncableServices(); | 333 void InitializeSyncableServices(); | 
| 328 | 334 | 
| 329 // Deletes the syncable services. | 335 // Deletes the syncable services. | 
| 330 void ShutdownSyncableServices(); | 336 void ShutdownSyncableServices(); | 
| 331 | 337 | 
| 332 void DBInitFailed(sql::InitStatus sql_status); | 338 void DBInitFailed(sql::InitStatus sql_status); | 
| 333 void NotifyDatabaseLoadedOnUIThread(); | |
| 334 void OnDatabaseInit(sql::InitStatus status); | 339 void OnDatabaseInit(sql::InitStatus status); | 
| 335 | 340 | 
| 336 ////////////////////////////////////////////////////////////////////////////// | 341 ////////////////////////////////////////////////////////////////////////////// | 
| 337 // | 342 // | 
| 338 // Keywords. | 343 // Keywords. | 
| 339 // | 344 // | 
| 340 ////////////////////////////////////////////////////////////////////////////// | 345 ////////////////////////////////////////////////////////////////////////////// | 
| 341 WebDatabase::State AddKeywordImpl( | 346 WebDatabase::State AddKeywordImpl( | 
| 342 const TemplateURLData& data, WebDatabase* db); | 347 const TemplateURLData& data, WebDatabase* db); | 
| 343 WebDatabase::State RemoveKeywordImpl( | 348 WebDatabase::State RemoveKeywordImpl( | 
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 438 WebDatabase::State AddCreditCardImpl( | 443 WebDatabase::State AddCreditCardImpl( | 
| 439 const CreditCard& credit_card, WebDatabase* db); | 444 const CreditCard& credit_card, WebDatabase* db); | 
| 440 WebDatabase::State UpdateCreditCardImpl( | 445 WebDatabase::State UpdateCreditCardImpl( | 
| 441 const CreditCard& credit_card, WebDatabase* db); | 446 const CreditCard& credit_card, WebDatabase* db); | 
| 442 WebDatabase::State RemoveCreditCardImpl( | 447 WebDatabase::State RemoveCreditCardImpl( | 
| 443 const std::string& guid, WebDatabase* db); | 448 const std::string& guid, WebDatabase* db); | 
| 444 scoped_ptr<WDTypedResult> GetCreditCardsImpl(WebDatabase* db); | 449 scoped_ptr<WDTypedResult> GetCreditCardsImpl(WebDatabase* db); | 
| 445 WebDatabase::State RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( | 450 WebDatabase::State RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( | 
| 446 const base::Time& delete_begin, const base::Time& delete_end, | 451 const base::Time& delete_begin, const base::Time& delete_end, | 
| 447 WebDatabase* db); | 452 WebDatabase* db); | 
| 453 void NotifyAutofillMultipleChangedOnUIThread(); | |
| 448 | 454 | 
| 449 // Callbacks to ensure that sensitive info is destroyed if request is | 455 // Callbacks to ensure that sensitive info is destroyed if request is | 
| 450 // cancelled. | 456 // cancelled. | 
| 451 void DestroyAutofillProfileResult(const WDTypedResult* result); | 457 void DestroyAutofillProfileResult(const WDTypedResult* result); | 
| 452 void DestroyAutofillCreditCardResult(const WDTypedResult* result); | 458 void DestroyAutofillCreditCardResult(const WDTypedResult* result); | 
| 453 | 459 | 
| 454 // Our database service (not owned by us as it is a profile keyed service). | 460 // Our database service (not owned by us as it is a profile keyed service). | 
| 455 WebDatabaseService* wdbs_; | 461 WebDatabaseService* wdbs_; | 
| 456 | 462 | 
| 457 // True if we've received a notification that the WebDatabase has loaded. | 463 // True if we've received a notification that the WebDatabase has loaded. | 
| 458 bool db_loaded_; | 464 bool db_loaded_; | 
| 459 | 465 | 
| 460 // Syncable services for the database data. We own the services, but don't | 466 // 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 | 467 // use |scoped_ptr|s because the lifetimes must be managed on the database | 
| 462 // thread. | 468 // thread. | 
| 463 // Currently only Autocomplete and Autofill profiles use the new Sync API, but | 469 // Currently only Autocomplete and Autofill profiles use the new Sync API, but | 
| 464 // all the database data should migrate to this API over time. | 470 // all the database data should migrate to this API over time. | 
| 465 AutocompleteSyncableService* autocomplete_syncable_service_; | 471 AutocompleteSyncableService* autocomplete_syncable_service_; | 
| 466 AutofillProfileSyncableService* autofill_profile_syncable_service_; | 472 AutofillProfileSyncableService* autofill_profile_syncable_service_; | 
| 467 | 473 | 
| 474 ObserverList<WebDataServiceObserver> observer_list_; | |
| 475 | |
| 468 DISALLOW_COPY_AND_ASSIGN(WebDataService); | 476 DISALLOW_COPY_AND_ASSIGN(WebDataService); | 
| 469 }; | 477 }; | 
| 470 | 478 | 
| 471 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ | 479 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ | 
| OLD | NEW |