blob: ecc8c33d3a3f579dd0051e705d58586c0b86aeb4 [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"
15#include "sql/init_status.h"
sdefresnef8cf5be2014-12-16 20:08:0916#include "sync/api/syncable_service.h"
sdefresnecb955cd2014-12-15 23:21:5617
18class KeywordWebDataService;
19class TokenWebData;
20class WebDatabaseService;
21
22#if defined(OS_WIN)
23class PasswordWebDataService;
24#endif
25
26namespace autofill {
27class AutofillWebDataBackend;
28class AutofillWebDataService;
29} // namespace autofill
30
31namespace base {
32class FilePath;
skyostilb0daa012015-06-02 19:03:4833class SingleThreadTaskRunner;
sdefresnecb955cd2014-12-15 23:21:5634} // namespace base
35
36// WebDataServiceWrapper is a KeyedService that owns multiple WebDataServices
37// so that they can be associated with a context.
38class 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
sdefresnef8cf5be2014-12-16 20:08:0951 // 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.
skyostilb0daa012015-06-02 19:03:4856 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,
thestig6f046752015-08-21 01:23:4762 const ShowErrorCallback& show_error_callback);
sdefresnecb955cd2014-12-15 23:21:5663 ~WebDataServiceWrapper() override;
64
sdefresnecb955cd2014-12-15 23:21:5665 // 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
thestig6f046752015-08-21 01:23:4777 protected:
78 // For testing.
79 WebDataServiceWrapper();
80
sdefresnecb955cd2014-12-15 23:21:5681 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_