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.
5 #ifndef COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_WRAPPER_H_
6 #define COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_WRAPPER_H_
10 #include "base/callback_forward.h"
11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h"
13 #include "build/build_config.h"
14 #include "components/keyed_service/core/keyed_service.h"
15 #include "components/sync/model/syncable_service.h"
16 #include "sql/init_status.h"
18 class KeywordWebDataService;
20 class WebDatabaseService;
24 class PaymentManifestWebDataService;
25 } // namespace payments
29 class AutofillWebDataService;
30 } // namespace autofill
34 class SingleThreadTaskRunner;
37 // WebDataServiceWrapper is a KeyedService that owns multiple WebDataServices
38 // so that they can be associated with a context.
39 class WebDataServiceWrapper : public KeyedService {
41 // ErrorType indicates which service encountered an error loading its data.
43 ERROR_LOADING_AUTOFILL,
44 ERROR_LOADING_ACCOUNT_AUTOFILL,
45 ERROR_LOADING_KEYWORD,
47 ERROR_LOADING_PASSWORD,
48 ERROR_LOADING_PAYMENT_MANIFEST,
51 // Shows an error message if a loading error occurs.
52 // |error_type| shows which service encountered an error while loading.
53 // |init_status| is the returned status of initializing the underlying
55 // |diagnostics| contains information about the underlying database
56 // which can help in identifying the cause of the error.
57 using ShowErrorCallback =
58 base::RepeatingCallback<void(ErrorType error_type,
59 sql::InitStatus init_status,
60 const std::string& diagnostics)>;
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
67 WebDataServiceWrapper(
68 const base::FilePath& context_path,
69 const std::string& application_locale,
70 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
71 const syncer::SyncableService::StartSyncFlare& flare,
72 const ShowErrorCallback& show_error_callback);
74 ~WebDataServiceWrapper() override;
77 void Shutdown() override;
79 // Create the various types of service instances. These methods are virtual
80 // for testing purpose.
81 virtual scoped_refptr<autofill::AutofillWebDataService>
82 GetProfileAutofillWebData();
83 virtual scoped_refptr<autofill::AutofillWebDataService>
84 GetAccountAutofillWebData();
85 virtual scoped_refptr<KeywordWebDataService> GetKeywordWebData();
86 virtual scoped_refptr<TokenWebData> GetTokenWebData();
88 virtual scoped_refptr<payments::PaymentManifestWebDataService>
89 GetPaymentManifestWebData();
94 WebDataServiceWrapper();
97 scoped_refptr<WebDatabaseService> profile_database_;
98 scoped_refptr<WebDatabaseService> account_database_;
100 scoped_refptr<autofill::AutofillWebDataService> profile_autofill_web_data_;
101 scoped_refptr<autofill::AutofillWebDataService> account_autofill_web_data_;
102 scoped_refptr<KeywordWebDataService> keyword_web_data_;
103 scoped_refptr<TokenWebData> token_web_data_;
106 scoped_refptr<payments::PaymentManifestWebDataService>
107 payment_manifest_web_data_;
110 DISALLOW_COPY_AND_ASSIGN(WebDataServiceWrapper);
113 #endif // COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_WRAPPER_H_