blob: cc430039d06531317856f0a1c254e272819cde04 [file] [log] [blame]
sdefresnecb955cd2014-12-15 23:21:561// 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"
avi5dd91f82015-12-25 22:30:4613#include "build/build_config.h"
sdefresnecb955cd2014-12-15 23:21:5614#include "components/keyed_service/core/keyed_service.h"
skym71603842016-10-10 18:17:3115#include "components/sync/model/syncable_service.h"
sdefresnecb955cd2014-12-15 23:21:5616#include "sql/init_status.h"
17
18class KeywordWebDataService;
19class TokenWebData;
20class WebDatabaseService;
21
Rouslan Solomakhinde012532017-09-20 15:18:3422#if !defined(OS_IOS)
gogerald79472092017-04-27 15:38:1623namespace payments {
24class PaymentManifestWebDataService;
25} // namespace payments
26#endif
27
sdefresnecb955cd2014-12-15 23:21:5628namespace autofill {
sdefresnecb955cd2014-12-15 23:21:5629class AutofillWebDataService;
30} // namespace autofill
31
32namespace base {
33class FilePath;
skyostilb0daa012015-06-02 19:03:4834class SingleThreadTaskRunner;
sdefresnecb955cd2014-12-15 23:21:5635} // namespace base
36
37// WebDataServiceWrapper is a KeyedService that owns multiple WebDataServices
38// so that they can be associated with a context.
39class WebDataServiceWrapper : public KeyedService {
40 public:
41 // ErrorType indicates which service encountered an error loading its data.
42 enum ErrorType {
43 ERROR_LOADING_AUTOFILL,
Florian Uunk75c22c92018-06-25 12:44:1044 ERROR_LOADING_ACCOUNT_AUTOFILL,
sdefresnecb955cd2014-12-15 23:21:5645 ERROR_LOADING_KEYWORD,
46 ERROR_LOADING_TOKEN,
47 ERROR_LOADING_PASSWORD,
gogerald79472092017-04-27 15:38:1648 ERROR_LOADING_PAYMENT_MANIFEST,
sdefresnecb955cd2014-12-15 23:21:5649 };
50
51 // Shows an error message if a loading error occurs.
afakhry7c9abe72016-08-05 17:33:1952 // |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 Kastinga86b8532018-02-13 23:37:2157 using ShowErrorCallback =
58 base::RepeatingCallback<void(ErrorType error_type,
59 sql::InitStatus init_status,
60 const std::string& diagnostics)>;
sdefresnecb955cd2014-12-15 23:21:5661
sdefresnef8cf5be2014-12-16 20:08:0962 // 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.
skyostilb0daa012015-06-02 19:03:4867 WebDataServiceWrapper(
68 const base::FilePath& context_path,
69 const std::string& application_locale,
Peter Kasting19750672017-08-04 05:24:0970 const scoped_refptr<base::SingleThreadTaskRunner>& ui_task_runner,
skyostilb0daa012015-06-02 19:03:4871 const syncer::SyncableService::StartSyncFlare& flare,
thestig6f046752015-08-21 01:23:4772 const ShowErrorCallback& show_error_callback);
Florian Uunk75c22c92018-06-25 12:44:1073
sdefresnecb955cd2014-12-15 23:21:5674 ~WebDataServiceWrapper() override;
75
sdefresnecb955cd2014-12-15 23:21:5676 // KeyedService:
77 void Shutdown() override;
78
79 // Create the various types of service instances. These methods are virtual
80 // for testing purpose.
Florian Uunk75c22c92018-06-25 12:44:1081 virtual scoped_refptr<autofill::AutofillWebDataService>
82 GetProfileAutofillWebData();
83 virtual scoped_refptr<autofill::AutofillWebDataService>
84 GetAccountAutofillWebData();
sdefresnecb955cd2014-12-15 23:21:5685 virtual scoped_refptr<KeywordWebDataService> GetKeywordWebData();
86 virtual scoped_refptr<TokenWebData> GetTokenWebData();
Rouslan Solomakhinde012532017-09-20 15:18:3487#if !defined(OS_IOS)
gogerald79472092017-04-27 15:38:1688 virtual scoped_refptr<payments::PaymentManifestWebDataService>
89 GetPaymentManifestWebData();
90#endif
sdefresnecb955cd2014-12-15 23:21:5691
thestig6f046752015-08-21 01:23:4792 protected:
93 // For testing.
94 WebDataServiceWrapper();
95
sdefresnecb955cd2014-12-15 23:21:5696 private:
Florian Uunk75c22c92018-06-25 12:44:1097 scoped_refptr<WebDatabaseService> profile_database_;
98 scoped_refptr<WebDatabaseService> account_database_;
sdefresnecb955cd2014-12-15 23:21:5699
Florian Uunk75c22c92018-06-25 12:44:10100 scoped_refptr<autofill::AutofillWebDataService> profile_autofill_web_data_;
101 scoped_refptr<autofill::AutofillWebDataService> account_autofill_web_data_;
sdefresnecb955cd2014-12-15 23:21:56102 scoped_refptr<KeywordWebDataService> keyword_web_data_;
103 scoped_refptr<TokenWebData> token_web_data_;
104
Rouslan Solomakhinde012532017-09-20 15:18:34105#if !defined(OS_IOS)
gogerald79472092017-04-27 15:38:16106 scoped_refptr<payments::PaymentManifestWebDataService>
107 payment_manifest_web_data_;
108#endif
109
sdefresnecb955cd2014-12-15 23:21:56110 DISALLOW_COPY_AND_ASSIGN(WebDataServiceWrapper);
111};
112
113#endif // COMPONENTS_WEBDATA_SERVICES_WEB_DATA_SERVICE_WRAPPER_H_