OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/search_engines/template_url_service.h" | 5 #include "chrome/browser/search_engines/template_url_service.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/environment.h" | 8 #include "base/environment.h" |
9 #include "base/i18n/case_conversion.h" | 9 #include "base/i18n/case_conversion.h" |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
95 } | 95 } |
96 }; | 96 }; |
97 | 97 |
98 TemplateURLService::TemplateURLService(Profile* profile) | 98 TemplateURLService::TemplateURLService(Profile* profile) |
99 : profile_(profile), | 99 : profile_(profile), |
100 loaded_(false), | 100 loaded_(false), |
101 load_failed_(false), | 101 load_failed_(false), |
102 load_handle_(0), | 102 load_handle_(0), |
103 default_search_provider_(NULL), | 103 default_search_provider_(NULL), |
104 is_default_search_managed_(false), | 104 is_default_search_managed_(false), |
105 next_id_(1) { | 105 next_id_(1), |
106 time_provider_(&base::Time::Now) { | |
106 DCHECK(profile_); | 107 DCHECK(profile_); |
107 Init(NULL, 0); | 108 Init(NULL, 0); |
108 } | 109 } |
109 | 110 |
110 TemplateURLService::TemplateURLService(const Initializer* initializers, | 111 TemplateURLService::TemplateURLService(const Initializer* initializers, |
111 const int count) | 112 const int count) |
112 : profile_(NULL), | 113 : profile_(NULL), |
113 loaded_(false), | 114 loaded_(false), |
114 load_failed_(false), | 115 load_failed_(false), |
115 load_handle_(0), | 116 load_handle_(0), |
116 service_(NULL), | 117 service_(NULL), |
117 default_search_provider_(NULL), | 118 default_search_provider_(NULL), |
118 is_default_search_managed_(false), | 119 is_default_search_managed_(false), |
119 next_id_(1) { | 120 next_id_(1), |
121 time_provider_(&base::Time::Now) { | |
120 Init(initializers, count); | 122 Init(initializers, count); |
121 } | 123 } |
122 | 124 |
123 TemplateURLService::~TemplateURLService() { | 125 TemplateURLService::~TemplateURLService() { |
124 if (load_handle_) { | 126 if (load_handle_) { |
125 DCHECK(service_.get()); | 127 DCHECK(service_.get()); |
126 service_->CancelRequest(load_handle_); | 128 service_->CancelRequest(load_handle_); |
127 } | 129 } |
128 | 130 |
129 STLDeleteElements(&template_urls_); | 131 STLDeleteElements(&template_urls_); |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 new_url.set_short_name(title); | 394 new_url.set_short_name(title); |
393 new_url.set_keyword(keyword); | 395 new_url.set_keyword(keyword); |
394 if ((new_url.url() && search_url.empty()) || | 396 if ((new_url.url() && search_url.empty()) || |
395 (!new_url.url() && !search_url.empty()) || | 397 (!new_url.url() && !search_url.empty()) || |
396 (new_url.url() && new_url.url()->url() != search_url)) { | 398 (new_url.url() && new_url.url()->url() != search_url)) { |
397 // The urls have changed, reset the favicon url. | 399 // The urls have changed, reset the favicon url. |
398 new_url.SetFaviconURL(GURL()); | 400 new_url.SetFaviconURL(GURL()); |
399 new_url.SetURL(search_url, 0, 0); | 401 new_url.SetURL(search_url, 0, 0); |
400 } | 402 } |
401 new_url.set_safe_for_autoreplace(false); | 403 new_url.set_safe_for_autoreplace(false); |
404 new_url.set_last_modified(time_provider_()); | |
402 UpdateNoNotify(url, new_url); | 405 UpdateNoNotify(url, new_url); |
403 NotifyObservers(); | 406 NotifyObservers(); |
404 } | 407 } |
405 | 408 |
406 bool TemplateURLService::CanMakeDefault(const TemplateURL* url) { | 409 bool TemplateURLService::CanMakeDefault(const TemplateURL* url) { |
407 return url != GetDefaultSearchProvider() && | 410 return url != GetDefaultSearchProvider() && |
408 url->url() && | 411 url->url() && |
409 url->url()->SupportsReplacement() && | 412 url->url()->SupportsReplacement() && |
410 !is_default_search_managed(); | 413 !is_default_search_managed(); |
411 } | 414 } |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
627 std::string(), | 630 std::string(), |
628 PrefService::UNSYNCABLE_PREF); | 631 PrefService::UNSYNCABLE_PREF); |
629 prefs->RegisterStringPref(prefs::kDefaultSearchProviderIconURL, | 632 prefs->RegisterStringPref(prefs::kDefaultSearchProviderIconURL, |
630 std::string(), | 633 std::string(), |
631 PrefService::UNSYNCABLE_PREF); | 634 PrefService::UNSYNCABLE_PREF); |
632 prefs->RegisterStringPref(prefs::kDefaultSearchProviderEncodings, | 635 prefs->RegisterStringPref(prefs::kDefaultSearchProviderEncodings, |
633 std::string(), | 636 std::string(), |
634 PrefService::UNSYNCABLE_PREF); | 637 PrefService::UNSYNCABLE_PREF); |
635 } | 638 } |
636 | 639 |
640 void TemplateURLService::InstallTimeProvider(TimeProvider* time_provider) { | |
sky
2011/06/22 22:38:06
Rename to set_time_provider, inline it and wrap it
SteveT
2011/06/23 21:15:55
Done.
| |
641 DCHECK(time_provider); | |
642 time_provider_ = time_provider; | |
643 } | |
644 | |
645 void TemplateURLService::UninstallTimeProvider() { | |
646 time_provider_ = &base::Time::Now; | |
sky
2011/06/22 22:38:06
Let the tests that care handle this. In fact based
SteveT
2011/06/23 21:15:55
Removed it in favour of managing it with set_time_
| |
647 } | |
648 | |
637 void TemplateURLService::SetKeywordSearchTermsForURL(const TemplateURL* t_url, | 649 void TemplateURLService::SetKeywordSearchTermsForURL(const TemplateURL* t_url, |
638 const GURL& url, | 650 const GURL& url, |
639 const string16& term) { | 651 const string16& term) { |
640 HistoryService* history = profile_ ? | 652 HistoryService* history = profile_ ? |
641 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS) : NULL; | 653 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS) : NULL; |
642 if (!history) | 654 if (!history) |
643 return; | 655 return; |
644 history->SetKeywordSearchTermsForURL(url, t_url->id(), term); | 656 history->SetKeywordSearchTermsForURL(url, t_url->id(), term); |
645 } | 657 } |
646 | 658 |
(...skipping 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1319 | 1331 |
1320 i = template_urls->erase(i); | 1332 i = template_urls->erase(i); |
1321 if (service_.get()) | 1333 if (service_.get()) |
1322 service_->RemoveKeyword(*template_url); | 1334 service_->RemoveKeyword(*template_url); |
1323 delete template_url; | 1335 delete template_url; |
1324 } else { | 1336 } else { |
1325 ++i; | 1337 ++i; |
1326 } | 1338 } |
1327 } | 1339 } |
1328 } | 1340 } |
OLD | NEW |