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" |
| 15 | #include "sql/init_status.h" |
sdefresne | f8cf5be | 2014-12-16 20:08:09 | [diff] [blame] | 16 | #include "sync/api/syncable_service.h" |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 17 | |
| 18 | class KeywordWebDataService; |
| 19 | class TokenWebData; |
| 20 | class WebDatabaseService; |
| 21 | |
| 22 | #if defined(OS_WIN) |
| 23 | class PasswordWebDataService; |
| 24 | #endif |
| 25 | |
| 26 | namespace autofill { |
| 27 | class AutofillWebDataBackend; |
| 28 | class AutofillWebDataService; |
| 29 | } // namespace autofill |
| 30 | |
| 31 | namespace base { |
| 32 | class FilePath; |
skyostil | b0daa01 | 2015-06-02 19:03:48 | [diff] [blame] | 33 | class SingleThreadTaskRunner; |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 34 | } // namespace base |
| 35 | |
| 36 | // WebDataServiceWrapper is a KeyedService that owns multiple WebDataServices |
| 37 | // so that they can be associated with a context. |
| 38 | class WebDataServiceWrapper : public KeyedService { |
| 39 | public: |
| 40 | // ErrorType indicates which service encountered an error loading its data. |
| 41 | enum ErrorType { |
| 42 | ERROR_LOADING_AUTOFILL, |
| 43 | ERROR_LOADING_KEYWORD, |
| 44 | ERROR_LOADING_TOKEN, |
| 45 | ERROR_LOADING_PASSWORD, |
| 46 | }; |
| 47 | |
| 48 | // Shows an error message if a loading error occurs. |
| 49 | using ShowErrorCallback = void (*)(ErrorType, sql::InitStatus); |
| 50 | |
sdefresne | f8cf5be | 2014-12-16 20:08:09 | [diff] [blame] | 51 | // Constructor for WebDataServiceWrapper that initializes the different |
| 52 | // WebDataServices and starts the synchronization services using |flare|. |
| 53 | // Since |flare| will be copied and called multiple times, it cannot bind |
| 54 | // values using base::Owned nor base::Passed; it should only bind simple or |
| 55 | // refcounted types. |
skyostil | b0daa01 | 2015-06-02 19:03:48 | [diff] [blame] | 56 | WebDataServiceWrapper( |
| 57 | const base::FilePath& context_path, |
| 58 | const std::string& application_locale, |
| 59 | const scoped_refptr<base::SingleThreadTaskRunner>& ui_thread, |
| 60 | const scoped_refptr<base::SingleThreadTaskRunner>& db_thread, |
| 61 | const syncer::SyncableService::StartSyncFlare& flare, |
thestig | 6f04675 | 2015-08-21 01:23:47 | [diff] [blame] | 62 | const ShowErrorCallback& show_error_callback); |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 63 | ~WebDataServiceWrapper() override; |
| 64 | |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 65 | // KeyedService: |
| 66 | void Shutdown() override; |
| 67 | |
| 68 | // Create the various types of service instances. These methods are virtual |
| 69 | // for testing purpose. |
| 70 | virtual scoped_refptr<autofill::AutofillWebDataService> GetAutofillWebData(); |
| 71 | virtual scoped_refptr<KeywordWebDataService> GetKeywordWebData(); |
| 72 | virtual scoped_refptr<TokenWebData> GetTokenWebData(); |
| 73 | #if defined(OS_WIN) |
| 74 | virtual scoped_refptr<PasswordWebDataService> GetPasswordWebData(); |
| 75 | #endif |
| 76 | |
thestig | 6f04675 | 2015-08-21 01:23:47 | [diff] [blame] | 77 | protected: |
| 78 | // For testing. |
| 79 | WebDataServiceWrapper(); |
| 80 | |
sdefresne | cb955cd | 2014-12-15 23:21:56 | [diff] [blame] | 81 | private: |
| 82 | scoped_refptr<WebDatabaseService> web_database_; |
| 83 | |
| 84 | scoped_refptr<autofill::AutofillWebDataService> autofill_web_data_; |
| 85 | scoped_refptr<KeywordWebDataService> keyword_web_data_; |
| 86 | scoped_refptr<TokenWebData> token_web_data_; |
| 87 | |
| 88 | #if defined(OS_WIN) |
| 89 | scoped_refptr<PasswordWebDataService> password_web_data_; |
| 90 | #endif |
| 91 | |
| 92 | DISALLOW_COPY_AND_ASSIGN(WebDataServiceWrapper); |
| 93 | }; |
| 94 | |
| 95 | #endif // COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_WRAPPER_H_ |