sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_WRAPPER_H_ |
| 6 | #define COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_WRAPPER_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/callback_forward.h" |
| 11 | #include "base/macros.h" |
| 12 | #include "base/memory/ref_counted.h" |
avi | 5dd91f8 | 2015-12-25 22:30:46 | [diff] [blame] | 13 | #include "build/build_config.h" |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 14 | #include "components/keyed_service/core/keyed_service.h" |
skym | 7160384 | 2016-10-10 18:17:31 | [diff] [blame] | 15 | #include "components/sync/model/syncable_service.h" |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 16 | #include "sql/init_status.h" |
| 17 | |
| 18 | class KeywordWebDataService; |
| 19 | class TokenWebData; |
| 20 | class WebDatabaseService; |
| 21 | |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 22 | #if !defined(OS_IOS) |
gogerald | 7947209 | 2017-04-27 15:38:16 | [diff] [blame] | 23 | namespace payments { |
| 24 | class PaymentManifestWebDataService; |
| 25 | } // namespace payments |
| 26 | #endif |
| 27 | |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 28 | namespace autofill { |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 29 | class AutofillWebDataService; |
| 30 | } // namespace autofill |
| 31 | |
| 32 | namespace base { |
| 33 | class FilePath; |
skyostil | b0daa01 | 2015-06-02 19:03:48 | [diff] [blame] | 34 | class SingleThreadTaskRunner; |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 35 | } // namespace base |
| 36 | |
| 37 | // WebDataServiceWrapper is a KeyedService that owns multiple WebDataServices |
| 38 | // so that they can be associated with a context. |
| 39 | class WebDataServiceWrapper : public KeyedService { |
| 40 | public: |
| 41 | // ErrorType indicates which service encountered an error loading its data. |
| 42 | enum ErrorType { |
| 43 | ERROR_LOADING_AUTOFILL, |
Florian Uunk | 75c22c9 | 2018-06-25 12:44:10 | [diff] [blame] | 44 | ERROR_LOADING_ACCOUNT_AUTOFILL, |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 45 | ERROR_LOADING_KEYWORD, |
| 46 | ERROR_LOADING_TOKEN, |
| 47 | ERROR_LOADING_PASSWORD, |
gogerald | 7947209 | 2017-04-27 15:38:16 | [diff] [blame] | 48 | ERROR_LOADING_PAYMENT_MANIFEST, |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | // Shows an error message if a loading error occurs. |
afakhry | 7c9abe7 | 2016-08-05 17:33:19 | [diff] [blame] | 52 | // |error_type| shows which service encountered an error while loading. |
| 53 | // |init_status| is the returned status of initializing the underlying |
| 54 | // database. |
| 55 | // |diagnostics| contains information about the underlying database |
| 56 | // which can help in identifying the cause of the error. |
Peter Kasting | a86b853 | 2018-02-13 23:37:21 | [diff] [blame] | 57 | using ShowErrorCallback = |
| 58 | base::RepeatingCallback<void(ErrorType error_type, |
| 59 | sql::InitStatus init_status, |
| 60 | const std::string& diagnostics)>; |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 61 | |
sdefresne | f8cf5be | 2014-12-16 20:08:09 | [diff] [blame] | 62 | // Constructor for WebDataServiceWrapper that initializes the different |
| 63 | // WebDataServices and starts the synchronization services using |flare|. |
| 64 | // Since |flare| will be copied and called multiple times, it cannot bind |
| 65 | // values using base::Owned nor base::Passed; it should only bind simple or |
| 66 | // refcounted types. |
skyostil | b0daa01 | 2015-06-02 19:03:48 | [diff] [blame] | 67 | WebDataServiceWrapper( |
| 68 | const base::FilePath& context_path, |
| 69 | const std::string& application_locale, |
Peter Kasting | 1975067 | 2017-08-04 05:24:09 | [diff] [blame] | 70 | const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner, |
skyostil | b0daa01 | 2015-06-02 19:03:48 | [diff] [blame] | 71 | const syncer::SyncableService::StartSyncFlare& flare, |
thestig | 6f04675 | 2015-08-21 01:23:47 | [diff] [blame] | 72 | const ShowErrorCallback& show_error_callback); |
Florian Uunk | 75c22c9 | 2018-06-25 12:44:10 | [diff] [blame] | 73 | |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 74 | ~WebDataServiceWrapper() override; |
| 75 | |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 76 | // KeyedService: |
| 77 | void Shutdown() override; |
| 78 | |
| 79 | // Create the various types of service instances. These methods are virtual |
| 80 | // for testing purpose. |
Florian Uunk | 75c22c9 | 2018-06-25 12:44:10 | [diff] [blame] | 81 | virtual scoped_refptr<autofill::AutofillWebDataService> |
| 82 | GetProfileAutofillWebData(); |
| 83 | virtual scoped_refptr<autofill::AutofillWebDataService> |
| 84 | GetAccountAutofillWebData(); |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 85 | virtual scoped_refptr<KeywordWebDataService> GetKeywordWebData(); |
| 86 | virtual scoped_refptr<TokenWebData> GetTokenWebData(); |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 87 | #if !defined(OS_IOS) |
gogerald | 7947209 | 2017-04-27 15:38:16 | [diff] [blame] | 88 | virtual scoped_refptr<payments::PaymentManifestWebDataService> |
| 89 | GetPaymentManifestWebData(); |
| 90 | #endif |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 91 | |
thestig | 6f04675 | 2015-08-21 01:23:47 | [diff] [blame] | 92 | protected: |
| 93 | // For testing. |
| 94 | WebDataServiceWrapper(); |
| 95 | |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 96 | private: |
Florian Uunk | 75c22c9 | 2018-06-25 12:44:10 | [diff] [blame] | 97 | scoped_refptr<WebDatabaseService> profile_database_; |
| 98 | scoped_refptr<WebDatabaseService> account_database_; |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 99 | |
Florian Uunk | 75c22c9 | 2018-06-25 12:44:10 | [diff] [blame] | 100 | scoped_refptr<autofill::AutofillWebDataService> profile_autofill_web_data_; |
| 101 | scoped_refptr<autofill::AutofillWebDataService> account_autofill_web_data_; |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 102 | scoped_refptr<KeywordWebDataService> keyword_web_data_; |
| 103 | scoped_refptr<TokenWebData> token_web_data_; |
| 104 | |
Rouslan Solomakhin | de01253 | 2017-09-20 15:18:34 | [diff] [blame] | 105 | #if !defined(OS_IOS) |
gogerald | 7947209 | 2017-04-27 15:38:16 | [diff] [blame] | 106 | scoped_refptr<payments::PaymentManifestWebDataService> |
| 107 | payment_manifest_web_data_; |
| 108 | #endif |
| 109 | |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 110 | DISALLOW_COPY_AND_ASSIGN(WebDataServiceWrapper); |
| 111 | }; |
| 112 | |
| 113 | #endif // COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_WRAPPER_H_ |