| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/search_engines/template_url_service.h" | 5 #include "components/search_engines/template_url_service.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/guid.h" | 13 #include "base/guid.h" |
| 14 #include "base/i18n/case_conversion.h" | 14 #include "base/i18n/case_conversion.h" |
| 15 #include "base/memory/scoped_vector.h" | 15 #include "base/memory/scoped_vector.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/prefs/pref_service.h" | 17 #include "base/prefs/pref_service.h" |
| 18 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 19 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/strings/string_split.h" | 20 #include "base/strings/string_split.h" |
| 21 #include "base/strings/string_util.h" | 21 #include "base/strings/string_util.h" |
| 22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
| 23 #include "base/time/default_clock.h" |
| 23 #include "base/time/time.h" | 24 #include "base/time/time.h" |
| 24 #include "components/rappor/rappor_service.h" | 25 #include "components/rappor/rappor_service.h" |
| 25 #include "components/search_engines/search_engines_pref_names.h" | 26 #include "components/search_engines/search_engines_pref_names.h" |
| 26 #include "components/search_engines/search_host_to_urls_map.h" | 27 #include "components/search_engines/search_host_to_urls_map.h" |
| 27 #include "components/search_engines/search_terms_data.h" | 28 #include "components/search_engines/search_terms_data.h" |
| 28 #include "components/search_engines/template_url.h" | 29 #include "components/search_engines/template_url.h" |
| 29 #include "components/search_engines/template_url_prepopulate_data.h" | 30 #include "components/search_engines/template_url_prepopulate_data.h" |
| 30 #include "components/search_engines/template_url_service_client.h" | 31 #include "components/search_engines/template_url_service_client.h" |
| 31 #include "components/search_engines/template_url_service_observer.h" | 32 #include "components/search_engines/template_url_service_observer.h" |
| 32 #include "components/search_engines/util.h" | 33 #include "components/search_engines/util.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 client_(client.Pass()), | 192 client_(client.Pass()), |
| 192 google_url_tracker_(google_url_tracker), | 193 google_url_tracker_(google_url_tracker), |
| 193 rappor_service_(rappor_service), | 194 rappor_service_(rappor_service), |
| 194 dsp_change_callback_(dsp_change_callback), | 195 dsp_change_callback_(dsp_change_callback), |
| 195 provider_map_(new SearchHostToURLsMap), | 196 provider_map_(new SearchHostToURLsMap), |
| 196 loaded_(false), | 197 loaded_(false), |
| 197 load_failed_(false), | 198 load_failed_(false), |
| 198 load_handle_(0), | 199 load_handle_(0), |
| 199 default_search_provider_(NULL), | 200 default_search_provider_(NULL), |
| 200 next_id_(kInvalidTemplateURLID + 1), | 201 next_id_(kInvalidTemplateURLID + 1), |
| 201 time_provider_(&base::Time::Now), | 202 clock_(new base::DefaultClock), |
| 202 models_associated_(false), | 203 models_associated_(false), |
| 203 processing_syncer_changes_(false), | 204 processing_syncer_changes_(false), |
| 204 dsp_change_origin_(DSP_CHANGE_OTHER), | 205 dsp_change_origin_(DSP_CHANGE_OTHER), |
| 205 default_search_manager_( | 206 default_search_manager_( |
| 206 prefs_, | 207 prefs_, |
| 207 base::Bind(&TemplateURLService::OnDefaultSearchChange, | 208 base::Bind(&TemplateURLService::OnDefaultSearchChange, |
| 208 base::Unretained(this))) { | 209 base::Unretained(this))) { |
| 209 DCHECK(search_terms_data_); | 210 DCHECK(search_terms_data_); |
| 210 Init(NULL, 0); | 211 Init(NULL, 0); |
| 211 } | 212 } |
| 212 | 213 |
| 213 TemplateURLService::TemplateURLService(const Initializer* initializers, | 214 TemplateURLService::TemplateURLService(const Initializer* initializers, |
| 214 const int count) | 215 const int count) |
| 215 : prefs_(NULL), | 216 : prefs_(NULL), |
| 216 search_terms_data_(new SearchTermsData), | 217 search_terms_data_(new SearchTermsData), |
| 217 web_data_service_(NULL), | 218 web_data_service_(NULL), |
| 218 google_url_tracker_(NULL), | 219 google_url_tracker_(NULL), |
| 219 rappor_service_(NULL), | 220 rappor_service_(NULL), |
| 220 provider_map_(new SearchHostToURLsMap), | 221 provider_map_(new SearchHostToURLsMap), |
| 221 loaded_(false), | 222 loaded_(false), |
| 222 load_failed_(false), | 223 load_failed_(false), |
| 223 load_handle_(0), | 224 load_handle_(0), |
| 224 default_search_provider_(NULL), | 225 default_search_provider_(NULL), |
| 225 next_id_(kInvalidTemplateURLID + 1), | 226 next_id_(kInvalidTemplateURLID + 1), |
| 226 time_provider_(&base::Time::Now), | 227 clock_(new base::DefaultClock), |
| 227 models_associated_(false), | 228 models_associated_(false), |
| 228 processing_syncer_changes_(false), | 229 processing_syncer_changes_(false), |
| 229 dsp_change_origin_(DSP_CHANGE_OTHER), | 230 dsp_change_origin_(DSP_CHANGE_OTHER), |
| 230 default_search_manager_( | 231 default_search_manager_( |
| 231 prefs_, | 232 prefs_, |
| 232 base::Bind(&TemplateURLService::OnDefaultSearchChange, | 233 base::Bind(&TemplateURLService::OnDefaultSearchChange, |
| 233 base::Unretained(this))) { | 234 base::Unretained(this))) { |
| 234 Init(initializers, count); | 235 Init(initializers, count); |
| 235 } | 236 } |
| 236 | 237 |
| (...skipping 1823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2060 DCHECK(!search_url.empty()); | 2061 DCHECK(!search_url.empty()); |
| 2061 TemplateURLData data(url->data()); | 2062 TemplateURLData data(url->data()); |
| 2062 data.short_name = title; | 2063 data.short_name = title; |
| 2063 data.SetKeyword(keyword); | 2064 data.SetKeyword(keyword); |
| 2064 if (search_url != data.url()) { | 2065 if (search_url != data.url()) { |
| 2065 data.SetURL(search_url); | 2066 data.SetURL(search_url); |
| 2066 // The urls have changed, reset the favicon url. | 2067 // The urls have changed, reset the favicon url. |
| 2067 data.favicon_url = GURL(); | 2068 data.favicon_url = GURL(); |
| 2068 } | 2069 } |
| 2069 data.safe_for_autoreplace = false; | 2070 data.safe_for_autoreplace = false; |
| 2070 data.last_modified = time_provider_(); | 2071 data.last_modified = clock_->Now(); |
| 2071 return UpdateNoNotify(url, TemplateURL(data)); | 2072 return UpdateNoNotify(url, TemplateURL(data)); |
| 2072 } | 2073 } |
| 2073 | 2074 |
| 2074 void TemplateURLService::NotifyObservers() { | 2075 void TemplateURLService::NotifyObservers() { |
| 2075 if (!loaded_) | 2076 if (!loaded_) |
| 2076 return; | 2077 return; |
| 2077 | 2078 |
| 2078 FOR_EACH_OBSERVER(TemplateURLServiceObserver, model_observers_, | 2079 FOR_EACH_OBSERVER(TemplateURLServiceObserver, model_observers_, |
| 2079 OnTemplateURLServiceChanged()); | 2080 OnTemplateURLServiceChanged()); |
| 2080 } | 2081 } |
| (...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2375 | 2376 |
| 2376 if (most_recently_intalled_default) { | 2377 if (most_recently_intalled_default) { |
| 2377 base::AutoReset<DefaultSearchChangeOrigin> change_origin( | 2378 base::AutoReset<DefaultSearchChangeOrigin> change_origin( |
| 2378 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); | 2379 &dsp_change_origin_, DSP_CHANGE_OVERRIDE_SETTINGS_EXTENSION); |
| 2379 default_search_manager_.SetExtensionControlledDefaultSearchEngine( | 2380 default_search_manager_.SetExtensionControlledDefaultSearchEngine( |
| 2380 most_recently_intalled_default->data()); | 2381 most_recently_intalled_default->data()); |
| 2381 } else { | 2382 } else { |
| 2382 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); | 2383 default_search_manager_.ClearExtensionControlledDefaultSearchEngine(); |
| 2383 } | 2384 } |
| 2384 } | 2385 } |
| OLD | NEW |