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