| Index: chrome/browser/search/google_search_provider_service.cc
|
| diff --git a/chrome/browser/search/google_search_provider_service.cc b/chrome/browser/search/google_search_provider_service.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b64dca9ce311a50171f1b8f82ba4f156c74aee32
|
| --- /dev/null
|
| +++ b/chrome/browser/search/google_search_provider_service.cc
|
| @@ -0,0 +1,64 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/search/google_search_provider_service.h"
|
| +
|
| +#include "components/search_engines/template_url_service.h"
|
| +
|
| +namespace {
|
| +
|
| +bool DefaultSearchProviderIsGoogleImpl(
|
| + const TemplateURLService* template_url_service) {
|
| + if (!template_url_service)
|
| + return false;
|
| +
|
| + const TemplateURL* default_provider =
|
| + template_url_service->GetDefaultSearchProvider();
|
| + return default_provider && (default_provider->GetEngineType(
|
| + template_url_service->search_terms_data()) ==
|
| + SEARCH_ENGINE_GOOGLE);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +GoogleSearchProviderService::GoogleSearchProviderService(
|
| + TemplateURLService* template_url_service)
|
| + : template_url_service_(template_url_service),
|
| + template_url_service_observer_(this),
|
| + is_google_(false) {
|
| + if (template_url_service_)
|
| + template_url_service_observer_.Add(template_url_service_);
|
| + OnTemplateURLServiceChanged();
|
| +}
|
| +
|
| +GoogleSearchProviderService::~GoogleSearchProviderService() = default;
|
| +
|
| +void GoogleSearchProviderService::Shutdown() {
|
| + template_url_service_observer_.RemoveAll();
|
| + for (auto& observer : observers_)
|
| + observer.OnGoogleSearchProviderServiceShuttingDown();
|
| +}
|
| +
|
| +bool GoogleSearchProviderService::DefaultSearchProviderIsGoogle() const {
|
| + return is_google_;
|
| +}
|
| +
|
| +void GoogleSearchProviderService::AddObserver(
|
| + GoogleSearchProviderServiceObserver* observer) {
|
| + observers_.AddObserver(observer);
|
| +}
|
| +
|
| +void GoogleSearchProviderService::RemoveObserver(
|
| + GoogleSearchProviderServiceObserver* observer) {
|
| + observers_.RemoveObserver(observer);
|
| +}
|
| +
|
| +void GoogleSearchProviderService::OnTemplateURLServiceChanged() {
|
| + bool old_is_google = is_google_;
|
| + is_google_ = DefaultSearchProviderIsGoogleImpl(template_url_service_);
|
| + if (is_google_ != old_is_google) {
|
| + for (auto& observer : observers_)
|
| + observer.OnDefaultSearchProviderIsGoogleChanged(is_google_);
|
| + }
|
| +}
|
|
|