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