| 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_data.h" | 5 #include "components/search_engines/template_url_data.h" |
| 6 | 6 |
| 7 #include "base/guid.h" | 7 #include "base/guid.h" |
| 8 #include "base/i18n/case_conversion.h" | 8 #include "base/i18n/case_conversion.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "components/search_engines/template_url.h" |
| 13 #include "components/search_engines/template_url_prepopulate_data.h" |
| 12 | 14 |
| 13 TemplateURLData::TemplateURLData() | 15 TemplateURLData::TemplateURLData() |
| 14 : show_in_default_list(false), | 16 : show_in_default_list(false), |
| 15 safe_for_autoreplace(false), | 17 safe_for_autoreplace(false), |
| 16 id(0), | 18 id(0), |
| 17 date_created(base::Time::Now()), | 19 date_created(base::Time::Now()), |
| 18 last_modified(base::Time::Now()), | 20 last_modified(base::Time::Now()), |
| 19 created_by_policy(false), | 21 created_by_policy(false), |
| 20 usage_count(0), | 22 usage_count(0), |
| 23 engine_type_(SEARCH_ENGINE_UNKNOWN), |
| 21 prepopulate_id(0), | 24 prepopulate_id(0), |
| 22 sync_guid(base::GenerateGUID()), | 25 sync_guid(base::GenerateGUID()), |
| 23 keyword_(base::ASCIIToUTF16("dummy")), | 26 keyword_(base::ASCIIToUTF16("dummy")), |
| 24 url_("x") { | 27 url_("x") { |
| 25 } | 28 } |
| 26 | 29 |
| 27 TemplateURLData::TemplateURLData(const TemplateURLData& other) = default; | 30 TemplateURLData::TemplateURLData(const TemplateURLData& other) = default; |
| 28 | 31 |
| 29 TemplateURLData::~TemplateURLData() { | 32 TemplateURLData::~TemplateURLData() { |
| 30 } | 33 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 41 DCHECK(!keyword.empty()); | 44 DCHECK(!keyword.empty()); |
| 42 | 45 |
| 43 // Case sensitive keyword matching is confusing. As such, we force all | 46 // Case sensitive keyword matching is confusing. As such, we force all |
| 44 // keywords to be lower case. | 47 // keywords to be lower case. |
| 45 keyword_ = base::i18n::ToLower(keyword); | 48 keyword_ = base::i18n::ToLower(keyword); |
| 46 } | 49 } |
| 47 | 50 |
| 48 void TemplateURLData::SetURL(const std::string& url) { | 51 void TemplateURLData::SetURL(const std::string& url) { |
| 49 DCHECK(!url.empty()); | 52 DCHECK(!url.empty()); |
| 50 url_ = url; | 53 url_ = url; |
| 54 engine_type_ = SEARCH_ENGINE_UNKNOWN; |
| 51 } | 55 } |
| 56 |
| 57 SearchEngineType TemplateURLData::GetEngineType( |
| 58 const SearchTermsData& search_terms_data, |
| 59 const TemplateURL* template_url_hint) const { |
| 60 if (engine_type_ == SEARCH_ENGINE_UNKNOWN) { |
| 61 std::unique_ptr<TemplateURL> temp_template_url; |
| 62 if (!template_url_hint || (&template_url_hint->data() != this)) { |
| 63 temp_template_url.reset(new TemplateURL(*this)); |
| 64 template_url_hint = temp_template_url.get(); |
| 65 } |
| 66 const GURL url = template_url_hint->GenerateSearchURL(search_terms_data); |
| 67 if (url.is_valid()) { |
| 68 engine_type_ = TemplateURLPrepopulateData::GetEngineType(url); |
| 69 DCHECK_NE(SEARCH_ENGINE_UNKNOWN, engine_type_); |
| 70 } else { |
| 71 engine_type_ = SEARCH_ENGINE_OTHER; |
| 72 } |
| 73 } |
| 74 return engine_type_; |
| 75 } |
| OLD | NEW |