[M120 Migration]Fix for crash during chrome exit
[platform/framework/web/chromium-efl.git] / chrome / browser / web_data_service_factory.h
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.
4
5 #ifndef CHROME_BROWSER_WEB_DATA_SERVICE_FACTORY_H_
6 #define CHROME_BROWSER_WEB_DATA_SERVICE_FACTORY_H_
7
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"
12
13 namespace base {
14 template <typename T>
15 class NoDestructor;
16 }
17
18 class KeywordWebDataService;
19 class Profile;
20 class TokenWebData;
21 class WebDataServiceWrapper;
22
23 namespace autofill {
24 class AutofillWebDataService;
25 }
26
27 // Singleton that owns all WebDataServiceWrappers and associates them with
28 // Profiles.
29 class WebDataServiceFactory
30     : public webdata_services::WebDataServiceWrapperFactory {
31  public:
32   // Returns the WebDataServiceWrapper associated with the |profile|.
33   static WebDataServiceWrapper* GetForProfile(Profile* profile,
34                                               ServiceAccessType access_type);
35
36   static WebDataServiceWrapper* GetForProfileIfExists(
37       Profile* profile,
38       ServiceAccessType access_type);
39
40   WebDataServiceFactory(const WebDataServiceFactory&) = delete;
41   WebDataServiceFactory& operator=(const WebDataServiceFactory&) = delete;
42
43   // Returns the AutofillWebDataService associated with the |profile|.
44   static scoped_refptr<autofill::AutofillWebDataService>
45   GetAutofillWebDataForProfile(Profile* profile, ServiceAccessType access_type);
46
47   // Returns the account-scoped AutofillWebDataService associated with the
48   // |profile|.
49   static scoped_refptr<autofill::AutofillWebDataService>
50   GetAutofillWebDataForAccount(Profile* profile, ServiceAccessType access_type);
51
52   // Returns the KeywordWebDataService associated with the |profile|.
53   static scoped_refptr<KeywordWebDataService> GetKeywordWebDataForProfile(
54       Profile* profile,
55       ServiceAccessType access_type);
56
57   // Returns the TokenWebData associated with the |profile|.
58   static scoped_refptr<TokenWebData> GetTokenWebDataForProfile(
59       Profile* profile,
60       ServiceAccessType access_type);
61
62   static WebDataServiceFactory* GetInstance();
63
64   // Returns the default factory, useful in tests where it's null by default.
65   static TestingFactory GetDefaultFactory();
66
67  private:
68   friend base::NoDestructor<WebDataServiceFactory>;
69
70   WebDataServiceFactory();
71   ~WebDataServiceFactory() override;
72
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;
79 };
80
81 #endif  // CHROME_BROWSER_WEB_DATA_SERVICE_FACTORY_H_