OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 #include "chrome/browser/search/google_search_provider_service.h" |
| 6 |
| 7 #include "components/search_engines/template_url_service.h" |
| 8 |
| 9 namespace { |
| 10 |
| 11 bool DefaultSearchProviderIsGoogleImpl( |
| 12 const TemplateURLService* template_url_service) { |
| 13 if (!template_url_service) |
| 14 return false; |
| 15 |
| 16 const TemplateURL* default_provider = |
| 17 template_url_service->GetDefaultSearchProvider(); |
| 18 return default_provider && (default_provider->GetEngineType( |
| 19 template_url_service->search_terms_data()) == |
| 20 SEARCH_ENGINE_GOOGLE); |
| 21 } |
| 22 |
| 23 } // namespace |
| 24 |
| 25 GoogleSearchProviderService::GoogleSearchProviderService( |
| 26 TemplateURLService* template_url_service) |
| 27 : template_url_service_(template_url_service), |
| 28 template_url_service_observer_(this), |
| 29 is_google_(false) { |
| 30 if (template_url_service_) |
| 31 template_url_service_observer_.Add(template_url_service_); |
| 32 OnTemplateURLServiceChanged(); |
| 33 } |
| 34 |
| 35 GoogleSearchProviderService::~GoogleSearchProviderService() = default; |
| 36 |
| 37 void GoogleSearchProviderService::Shutdown() { |
| 38 template_url_service_observer_.RemoveAll(); |
| 39 for (auto& observer : observers_) |
| 40 observer.OnGoogleSearchProviderServiceShuttingDown(); |
| 41 } |
| 42 |
| 43 bool GoogleSearchProviderService::DefaultSearchProviderIsGoogle() const { |
| 44 return is_google_; |
| 45 } |
| 46 |
| 47 void GoogleSearchProviderService::AddObserver( |
| 48 GoogleSearchProviderServiceObserver* observer) { |
| 49 observers_.AddObserver(observer); |
| 50 } |
| 51 |
| 52 void GoogleSearchProviderService::RemoveObserver( |
| 53 GoogleSearchProviderServiceObserver* observer) { |
| 54 observers_.RemoveObserver(observer); |
| 55 } |
| 56 |
| 57 void GoogleSearchProviderService::OnTemplateURLServiceChanged() { |
| 58 bool old_is_google = is_google_; |
| 59 is_google_ = DefaultSearchProviderIsGoogleImpl(template_url_service_); |
| 60 if (is_google_ != old_is_google) { |
| 61 for (auto& observer : observers_) |
| 62 observer.OnDefaultSearchProviderIsGoogleChanged(is_google_); |
| 63 } |
| 64 } |
OLD | NEW |