1 // Copyright 2019 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 COMPONENTS_SEARCH_SEARCH_PROVIDER_OBSERVER_H_
6 #define COMPONENTS_SEARCH_SEARCH_PROVIDER_OBSERVER_H_
8 #include "base/memory/raw_ptr.h"
9 #include "base/scoped_observation.h"
10 #include "components/search_engines/template_url_service.h"
11 #include "components/search_engines/template_url_service_observer.h"
13 // Keeps track of any changes in search engine provider and call
14 // the provided callback if a third-party search provider (i.e. a third-party
15 // NTP) is being used.
16 class SearchProviderObserver : public TemplateURLServiceObserver {
18 explicit SearchProviderObserver(TemplateURLService* service,
19 base::RepeatingClosure callback);
20 ~SearchProviderObserver() override;
22 virtual bool is_google();
25 // TemplateURLServiceObserver:
26 void OnTemplateURLServiceChanged() override;
27 void OnTemplateURLServiceShuttingDown() override;
29 base::ScopedObservation<TemplateURLService, TemplateURLServiceObserver>
30 service_observation_{this};
31 // May be nullptr in tests.
32 raw_ptr<TemplateURLService> service_;
34 base::RepeatingClosure callback_;
37 #endif // COMPONENTS_SEARCH_SEARCH_PROVIDER_OBSERVER_H_