| 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 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1319 | 1322 |
| 1320 i = template_urls->erase(i); | 1323 i = template_urls->erase(i); |
| 1321 if (service_.get()) | 1324 if (service_.get()) |
| 1322 service_->RemoveKeyword(*template_url); | 1325 service_->RemoveKeyword(*template_url); |
| 1323 delete template_url; | 1326 delete template_url; |
| 1324 } else { | 1327 } else { |
| 1325 ++i; | 1328 ++i; |
| 1326 } | 1329 } |
| 1327 } | 1330 } |
| 1328 } | 1331 } |
| OLD | NEW |