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 COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_CONTROLLER_EMITTER_H_
6 #define COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_CONTROLLER_EMITTER_H_
7 
8 #include "build/build_config.h"
9 #include "components/keyed_service/core/keyed_service.h"
10 #include "components/omnibox/browser/autocomplete_controller.h"
11 
12 #if !defined(OS_IOS)
13 #include "content/public/browser/browser_context.h"
14 #endif  // !defined(OS_IOS)
15 
16 // This KeyedService is meant to observe multiple AutocompleteController
17 // instances and forward the notifications to its own observers.
18 // Its main purpose is to act as a bridge between the chrome://omnibox WebUI
19 // handler, and the many usages of AutocompleteController (Views, NTP, Android).
20 class OmniboxControllerEmitter : public KeyedService,
21                                  public AutocompleteController::Observer {
22  public:
23 #if !defined(OS_IOS)
24   static OmniboxControllerEmitter* GetForBrowserContext(
25       content::BrowserContext* browser_context);
26 #endif  // !defined(OS_IOS)
27 
28   OmniboxControllerEmitter();
29   ~OmniboxControllerEmitter() override;
30   OmniboxControllerEmitter(const OmniboxControllerEmitter&) = delete;
31   OmniboxControllerEmitter& operator=(const OmniboxControllerEmitter&) = delete;
32 
33   // Add/remove observer.
34   void AddObserver(AutocompleteController::Observer* observer);
35   void RemoveObserver(AutocompleteController::Observer* observer);
36 
37   // AutocompleteController::Observer:
38   void OnStart(AutocompleteController* controller,
39                const AutocompleteInput& input) override;
40   void OnResultChanged(AutocompleteController* controller,
41                        bool default_match_changed) override;
42 
43  private:
44   base::ObserverList<AutocompleteController::Observer> observers_;
45 };
46 
47 #endif  // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_CONTROLLER_EMITTER_H_
48