1 // Copyright 2018 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 IOS_WEB_VIEW_INTERNAL_AUTOFILL_WEB_VIEW_AUTOCOMPLETE_HISTORY_MANAGER_FACTORY_H_
6 #define IOS_WEB_VIEW_INTERNAL_AUTOFILL_WEB_VIEW_AUTOCOMPLETE_HISTORY_MANAGER_FACTORY_H_
7 
8 #include <memory>
9 
10 #include "base/macros.h"
11 #include "base/no_destructor.h"
12 #include "components/keyed_service/ios/browser_state_keyed_service_factory.h"
13 
14 namespace autofill {
15 class AutocompleteHistoryManager;
16 }
17 
18 namespace ios_web_view {
19 class WebViewBrowserState;
20 
21 // Singleton that owns all AutocompleteHistoryManagers and associates them with
22 // ios_web_view::WebViewBrowserState.
23 class WebViewAutocompleteHistoryManagerFactory
24     : public BrowserStateKeyedServiceFactory {
25  public:
26   static autofill::AutocompleteHistoryManager* GetForBrowserState(
27       WebViewBrowserState* browser_state);
28   static WebViewAutocompleteHistoryManagerFactory* GetInstance();
29 
30  private:
31   friend class base::NoDestructor<WebViewAutocompleteHistoryManagerFactory>;
32 
33   WebViewAutocompleteHistoryManagerFactory();
34   ~WebViewAutocompleteHistoryManagerFactory() override;
35 
36   // BrowserStateKeyedServiceFactory implementation.
37   std::unique_ptr<KeyedService> BuildServiceInstanceFor(
38       web::BrowserState* context) const override;
39   web::BrowserState* GetBrowserStateToUse(
40       web::BrowserState* context) const override;
41 
42   DISALLOW_COPY_AND_ASSIGN(WebViewAutocompleteHistoryManagerFactory);
43 };
44 
45 }  // namespace ios_web_view
46 
47 #endif  // IOS_WEB_VIEW_INTERNAL_AUTOFILL_WEB_VIEW_AUTOCOMPLETE_HISTORY_MANAGER_FACTORY_H_
48