| 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_forward.h" | 16 #include "base/callback_forward.h" |
| 17 #include "base/files/file_path.h" | 17 #include "base/files/file_path.h" |
| 18 #include "base/location.h" | 18 #include "base/location.h" |
| 19 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.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_service.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/search_engines/template_url.h" | 26 #include "chrome/browser/search_engines/template_url.h" |
| 27 #include "chrome/browser/search_engines/template_url_id.h" | 27 #include "chrome/browser/search_engines/template_url_id.h" |
| 28 #include "chrome/browser/webdata/keyword_table.h" | 28 #include "chrome/browser/webdata/keyword_table.h" |
| 29 #include "chrome/browser/webdata/web_data_request_manager.h" | |
| 30 #include "chrome/browser/webdata/web_database.h" | 29 #include "chrome/browser/webdata/web_database.h" |
| 31 #include "content/public/browser/browser_thread.h" | |
| 32 #include "sql/init_status.h" | |
| 33 | 30 |
| 34 class AutocompleteSyncableService; | 31 class AutocompleteSyncableService; |
| 35 class AutofillChange; | 32 class AutofillChange; |
| 36 class AutofillProfileSyncableService; | 33 class AutofillProfileSyncableService; |
| 37 struct DefaultWebIntentService; | 34 struct DefaultWebIntentService; |
| 38 class GURL; | 35 class GURL; |
| 39 #if defined(OS_WIN) | 36 #if defined(OS_WIN) |
| 40 struct IE7PasswordInfo; | 37 struct IE7PasswordInfo; |
| 41 #endif | 38 #endif |
| 42 class MessageLoop; | 39 class MessageLoop; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 // Identifies the ID of the TemplateURL that is the default search. A value of | 93 // Identifies the ID of the TemplateURL that is the default search. A value of |
| 97 // 0 indicates there is no default search provider. | 94 // 0 indicates there is no default search provider. |
| 98 int64 default_search_provider_id; | 95 int64 default_search_provider_id; |
| 99 // Version of the built-in keywords. A value of 0 indicates a first run. | 96 // Version of the built-in keywords. A value of 0 indicates a first run. |
| 100 int builtin_keyword_version; | 97 int builtin_keyword_version; |
| 101 }; | 98 }; |
| 102 | 99 |
| 103 class WebDataServiceConsumer; | 100 class WebDataServiceConsumer; |
| 104 | 101 |
| 105 class WebDataService | 102 class WebDataService |
| 106 : public base::RefCountedThreadSafe<WebDataService, | 103 : public WebDataServiceBase, |
| 107 content::BrowserThread::DeleteOnUIThread>, | |
| 108 public WebDataServiceBase, | |
| 109 public AutofillWebData { | 104 public AutofillWebData { |
| 110 public: | 105 public: |
| 111 // Retrieve a WebDataService for the given context. | 106 // Retrieve a WebDataService for the given context. |
| 112 static scoped_refptr<WebDataService> FromBrowserContext( | 107 static scoped_refptr<WebDataService> FromBrowserContext( |
| 113 content::BrowserContext* context); | 108 content::BrowserContext* context); |
| 114 | 109 |
| 115 WebDataService(); | 110 WebDataService(); |
| 116 | 111 |
| 117 // WebDataServiceBase implementation. | 112 // WebDataServiceBase implementation. |
| 118 virtual void CancelRequest(Handle h) OVERRIDE; | 113 virtual void ShutdownOnUIThread() OVERRIDE; |
| 119 virtual content::NotificationSource GetNotificationSource() OVERRIDE; | 114 virtual void Init(const base::FilePath& path) OVERRIDE; |
| 120 | 115 |
| 121 // Notifies listeners on the UI thread that multiple changes have been made to | 116 // Notifies listeners on the UI thread that multiple changes have been made to |
| 122 // to Autofill records of the database. | 117 // to Autofill records of the database. |
| 123 // NOTE: This method is intended to be called from the DB thread. It | 118 // NOTE: This method is intended to be called from the DB thread. It |
| 124 // it asynchronously notifies listeners on the UI thread. | 119 // it asynchronously notifies listeners on the UI thread. |
| 125 // |web_data_service| may be NULL for testing purposes. | 120 // |web_data_service| may be NULL for testing purposes. |
| 126 static void NotifyOfMultipleAutofillChanges(WebDataService* web_data_service); | 121 static void NotifyOfMultipleAutofillChanges(WebDataService* web_data_service); |
| 127 | 122 |
| 128 // Shutdown the web data service. The service can no longer be used after this | |
| 129 // call. | |
| 130 void ShutdownOnUIThread(); | |
| 131 | 123 |
| 132 // Initializes the web data service. | |
| 133 void Init(const base::FilePath& path); | |
| 134 | |
| 135 // Unloads the database without actually shutting down the service. This can | |
| 136 // be used to temporarily reduce the browser process' memory footprint. | |
| 137 void UnloadDatabase(); | |
| 138 | |
| 139 // Unloads the database permanently and shuts down service. | |
| 140 void ShutdownDatabase(); | |
| 141 | |
| 142 // Returns true if the database load has completetd successfully, and | |
| 143 // ShutdownOnUIThread has not yet been called. | |
| 144 virtual bool IsDatabaseLoaded(); | |
| 145 | |
| 146 // Returns a pointer to the DB (used by SyncableServices). May return NULL if | |
| 147 // the database is not loaded or otherwise unavailable. Must be called on | |
| 148 // DBThread. | |
| 149 virtual WebDatabase* GetDatabase(); | |
| 150 | 124 |
| 151 ////////////////////////////////////////////////////////////////////////////// | 125 ////////////////////////////////////////////////////////////////////////////// |
| 152 // | 126 // |
| 153 // Keywords | 127 // Keywords |
| 154 // | 128 // |
| 155 ////////////////////////////////////////////////////////////////////////////// | 129 ////////////////////////////////////////////////////////////////////////////// |
| 156 | 130 |
| 157 // As the database processes requests at a later date, all deletion is | 131 // As the database processes requests at a later date, all deletion is |
| 158 // done on the background thread. | 132 // done on the background thread. |
| 159 // | 133 // |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 // in this table. The returned service is owned by |this| object. | 293 // in this table. The returned service is owned by |this| object. |
| 320 virtual AutofillProfileSyncableService* | 294 virtual AutofillProfileSyncableService* |
| 321 GetAutofillProfileSyncableService() const; | 295 GetAutofillProfileSyncableService() const; |
| 322 | 296 |
| 323 // Returns the syncable service for field autocomplete stored in this table. | 297 // Returns the syncable service for field autocomplete stored in this table. |
| 324 // The returned service is owned by |this| object. | 298 // The returned service is owned by |this| object. |
| 325 virtual AutocompleteSyncableService* | 299 virtual AutocompleteSyncableService* |
| 326 GetAutocompleteSyncableService() const; | 300 GetAutocompleteSyncableService() const; |
| 327 | 301 |
| 328 protected: | 302 protected: |
| 303 // TODO (caitkp): We probably don't need these anymore. |
| 329 friend class TemplateURLServiceTest; | 304 friend class TemplateURLServiceTest; |
| 330 friend class TemplateURLServiceTestingProfile; | 305 friend class TemplateURLServiceTestingProfile; |
| 331 friend class WebDataServiceTest; | 306 friend class WebDataServiceTest; |
| 332 friend class WebDataRequest; | 307 friend class WebDataRequest; |
| 333 | 308 |
| 334 virtual ~WebDataService(); | 309 virtual ~WebDataService(); |
| 335 | 310 |
| 336 ////////////////////////////////////////////////////////////////////////////// | 311 ////////////////////////////////////////////////////////////////////////////// |
| 337 // | 312 // |
| 338 // The following methods are only invoked in the web data service thread. | 313 // The following methods are only invoked in the web data service thread. |
| 339 // | 314 // |
| 340 ////////////////////////////////////////////////////////////////////////////// | 315 ////////////////////////////////////////////////////////////////////////////// |
| 341 private: | 316 private: |
| 342 friend struct content::BrowserThread::DeleteOnThread< | |
| 343 content::BrowserThread::UI>; | |
| 344 friend class base::DeleteHelper<WebDataService>; | |
| 345 | |
| 346 // Initialize any syncable services. | 317 // Initialize any syncable services. |
| 347 void InitializeSyncableServices(); | 318 void InitializeSyncableServices(); |
| 348 | 319 |
| 349 // Deletes the syncable services. | 320 // Deletes the syncable services. |
| 350 void ShutdownSyncableServices(); | 321 void ShutdownSyncableServices(); |
| 351 | 322 |
| 352 void DBInitFailed(sql::InitStatus sql_status); | |
| 353 void NotifyDatabaseLoadedOnUIThread(); | |
| 354 void DatabaseInitOnDB(sql::InitStatus status); | |
| 355 | |
| 356 ////////////////////////////////////////////////////////////////////////////// | 323 ////////////////////////////////////////////////////////////////////////////// |
| 357 // | 324 // |
| 358 // Keywords. | 325 // Keywords. |
| 359 // | 326 // |
| 360 ////////////////////////////////////////////////////////////////////////////// | 327 ////////////////////////////////////////////////////////////////////////////// |
| 361 WebDatabase::State AddKeywordImpl( | 328 WebDatabase::State AddKeywordImpl( |
| 362 const TemplateURLData& data, WebDatabase* db); | 329 const TemplateURLData& data, WebDatabase* db); |
| 363 WebDatabase::State RemoveKeywordImpl( | 330 WebDatabase::State RemoveKeywordImpl( |
| 364 TemplateURLID id, WebDatabase* db); | 331 TemplateURLID id, WebDatabase* db); |
| 365 WebDatabase::State UpdateKeywordImpl( | 332 WebDatabase::State UpdateKeywordImpl( |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 scoped_ptr<WDTypedResult> GetCreditCardsImpl(WebDatabase* db); | 431 scoped_ptr<WDTypedResult> GetCreditCardsImpl(WebDatabase* db); |
| 465 WebDatabase::State RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( | 432 WebDatabase::State RemoveAutofillProfilesAndCreditCardsModifiedBetweenImpl( |
| 466 const base::Time& delete_begin, const base::Time& delete_end, | 433 const base::Time& delete_begin, const base::Time& delete_end, |
| 467 WebDatabase* db); | 434 WebDatabase* db); |
| 468 | 435 |
| 469 // Callbacks to ensure that sensitive info is destroyed if request is | 436 // Callbacks to ensure that sensitive info is destroyed if request is |
| 470 // cancelled. | 437 // cancelled. |
| 471 void DestroyAutofillProfileResult(const WDTypedResult* result); | 438 void DestroyAutofillProfileResult(const WDTypedResult* result); |
| 472 void DestroyAutofillCreditCardResult(const WDTypedResult* result); | 439 void DestroyAutofillCreditCardResult(const WDTypedResult* result); |
| 473 | 440 |
| 474 // Our database service. | |
| 475 scoped_ptr<WebDatabaseService> wdbs_; | |
| 476 | |
| 477 // True if we've received a notification that the WebDatabase has loaded. | |
| 478 bool db_loaded_; | |
| 479 | |
| 480 // Syncable services for the database data. We own the services, but don't | 441 // Syncable services for the database data. We own the services, but don't |
| 481 // use |scoped_ptr|s because the lifetimes must be managed on the database | 442 // use |scoped_ptr|s because the lifetimes must be managed on the database |
| 482 // thread. | 443 // thread. |
| 483 // Currently only Autocomplete and Autofill profiles use the new Sync API, but | 444 // Currently only Autocomplete and Autofill profiles use the new Sync API, but |
| 484 // all the database data should migrate to this API over time. | 445 // all the database data should migrate to this API over time. |
| 485 AutocompleteSyncableService* autocomplete_syncable_service_; | 446 AutocompleteSyncableService* autocomplete_syncable_service_; |
| 486 AutofillProfileSyncableService* autofill_profile_syncable_service_; | 447 AutofillProfileSyncableService* autofill_profile_syncable_service_; |
| 487 | 448 |
| 488 DISALLOW_COPY_AND_ASSIGN(WebDataService); | 449 DISALLOW_COPY_AND_ASSIGN(WebDataService); |
| 489 }; | 450 }; |
| 490 | 451 |
| 491 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ | 452 #endif // CHROME_BROWSER_WEBDATA_WEB_DATA_SERVICE_H__ |
| OLD | NEW |