1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_WEB_DATA_SERVICE_FACTORY_H_
6 #define CHROME_BROWSER_WEB_DATA_SERVICE_FACTORY_H_
8 #include "base/memory/ref_counted.h"
9 #include "build/build_config.h"
10 #include "components/keyed_service/core/service_access_type.h"
11 #include "components/webdata_services/web_data_service_wrapper_factory.h"
18 class KeywordWebDataService;
21 class WebDataServiceWrapper;
24 class AutofillWebDataService;
27 // Singleton that owns all WebDataServiceWrappers and associates them with
29 class WebDataServiceFactory
30 : public webdata_services::WebDataServiceWrapperFactory {
32 // Returns the WebDataServiceWrapper associated with the |profile|.
33 static WebDataServiceWrapper* GetForProfile(Profile* profile,
34 ServiceAccessType access_type);
36 static WebDataServiceWrapper* GetForProfileIfExists(
38 ServiceAccessType access_type);
40 WebDataServiceFactory(const WebDataServiceFactory&) = delete;
41 WebDataServiceFactory& operator=(const WebDataServiceFactory&) = delete;
43 // Returns the AutofillWebDataService associated with the |profile|.
44 static scoped_refptr<autofill::AutofillWebDataService>
45 GetAutofillWebDataForProfile(Profile* profile, ServiceAccessType access_type);
47 // Returns the account-scoped AutofillWebDataService associated with the
49 static scoped_refptr<autofill::AutofillWebDataService>
50 GetAutofillWebDataForAccount(Profile* profile, ServiceAccessType access_type);
52 // Returns the KeywordWebDataService associated with the |profile|.
53 static scoped_refptr<KeywordWebDataService> GetKeywordWebDataForProfile(
55 ServiceAccessType access_type);
57 // Returns the TokenWebData associated with the |profile|.
58 static scoped_refptr<TokenWebData> GetTokenWebDataForProfile(
60 ServiceAccessType access_type);
62 static WebDataServiceFactory* GetInstance();
64 // Returns the default factory, useful in tests where it's null by default.
65 static TestingFactory GetDefaultFactory();
68 friend base::NoDestructor<WebDataServiceFactory>;
70 WebDataServiceFactory();
71 ~WebDataServiceFactory() override;
73 // |BrowserContextKeyedServiceFactory| methods:
74 content::BrowserContext* GetBrowserContextToUse(
75 content::BrowserContext* context) const override;
76 std::unique_ptr<KeyedService> BuildServiceInstanceForBrowserContext(
77 content::BrowserContext* profile) const override;
78 bool ServiceIsNULLWhileTesting() const override;
81 #endif // CHROME_BROWSER_WEB_DATA_SERVICE_FACTORY_H_