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.h" | 5 #include "chrome/browser/search_engines/template_url.h" |
6 | 6 |
7 #include "base/i18n/case_conversion.h" | 7 #include "base/i18n/case_conversion.h" |
8 #include "base/i18n/icu_string_conversions.h" | 8 #include "base/i18n/icu_string_conversions.h" |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
13 #include "base/string_number_conversions.h" | 13 #include "base/string_number_conversions.h" |
14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/search_engines/search_engine_type.h" | 15 #include "chrome/browser/search_engines/search_engine_type.h" |
16 #include "chrome/browser/search_engines/search_terms_data.h" | 16 #include "chrome/browser/search_engines/search_terms_data.h" |
17 #include "chrome/browser/search_engines/template_url_service.h" | 17 #include "chrome/browser/search_engines/template_url_service.h" |
18 #include "chrome/common/guid.h" | |
19 #include "chrome/common/url_constants.h" | 18 #include "chrome/common/url_constants.h" |
20 #include "chrome/installer/util/google_update_settings.h" | 19 #include "chrome/installer/util/google_update_settings.h" |
21 #include "content/browser/user_metrics.h" | 20 #include "content/browser/user_metrics.h" |
22 #include "net/base/escape.h" | 21 #include "net/base/escape.h" |
23 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/gfx/favicon_size.h" | 23 #include "ui/gfx/favicon_size.h" |
25 // TODO(pastarmovj): Remove google_update_settings and user_metrics when the | 24 // TODO(pastarmovj): Remove google_update_settings and user_metrics when the |
26 // CollectRLZMetrics function is not needed anymore. | 25 // CollectRLZMetrics function is not needed anymore. |
27 | 26 |
28 // The TemplateURLRef has any number of terms that need to be replaced. Each of | 27 // The TemplateURLRef has any number of terms that need to be replaced. Each of |
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
636 keyword_generated_(false), | 635 keyword_generated_(false), |
637 show_in_default_list_(false), | 636 show_in_default_list_(false), |
638 safe_for_autoreplace_(false), | 637 safe_for_autoreplace_(false), |
639 id_(0), | 638 id_(0), |
640 date_created_(base::Time::Now()), | 639 date_created_(base::Time::Now()), |
641 last_modified_(base::Time::Now()), | 640 last_modified_(base::Time::Now()), |
642 created_by_policy_(false), | 641 created_by_policy_(false), |
643 usage_count_(0), | 642 usage_count_(0), |
644 search_engine_type_(SEARCH_ENGINE_OTHER), | 643 search_engine_type_(SEARCH_ENGINE_OTHER), |
645 logo_id_(kNoSearchEngineLogo), | 644 logo_id_(kNoSearchEngineLogo), |
646 prepopulate_id_(0), | 645 prepopulate_id_(0) { |
647 sync_guid_(guid::GenerateGUID()) { | |
648 } | 646 } |
649 | 647 |
650 TemplateURL::~TemplateURL() { | 648 TemplateURL::~TemplateURL() { |
651 } | 649 } |
652 | 650 |
653 string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { | 651 string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { |
654 string16 bidi_safe_short_name = short_name_; | 652 string16 bidi_safe_short_name = short_name_; |
655 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); | 653 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); |
656 return bidi_safe_short_name; | 654 return bidi_safe_short_name; |
657 } | 655 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 if ((i->type == "image/x-icon" || i->type == "image/vnd.microsoft.icon") | 723 if ((i->type == "image/x-icon" || i->type == "image/vnd.microsoft.icon") |
726 && i->width == kFaviconSize && i->height == kFaviconSize) { | 724 && i->width == kFaviconSize && i->height == kFaviconSize) { |
727 return i->url; | 725 return i->url; |
728 } | 726 } |
729 } | 727 } |
730 return GURL(); | 728 return GURL(); |
731 } | 729 } |
732 | 730 |
733 void TemplateURL::SetPrepopulateId(int id) { | 731 void TemplateURL::SetPrepopulateId(int id) { |
734 prepopulate_id_ = id; | 732 prepopulate_id_ = id; |
735 SetTemplateURLRefsPrepopulated(id > 0); | 733 if (id > 0) |
| 734 SetTemplateURLRefsPrepopulated(true); |
| 735 else |
| 736 SetTemplateURLRefsPrepopulated(false); |
736 } | 737 } |
737 | 738 |
738 void TemplateURL::InvalidateCachedValues() const { | 739 void TemplateURL::InvalidateCachedValues() const { |
739 url_.InvalidateCachedValues(); | 740 url_.InvalidateCachedValues(); |
740 suggestions_url_.InvalidateCachedValues(); | 741 suggestions_url_.InvalidateCachedValues(); |
741 if (autogenerate_keyword_) { | 742 if (autogenerate_keyword_) { |
742 keyword_.clear(); | 743 keyword_.clear(); |
743 keyword_generated_ = false; | 744 keyword_generated_ = false; |
744 } | 745 } |
745 } | 746 } |
746 | 747 |
747 void TemplateURL::SetTemplateURLRefsPrepopulated(bool prepopulated) { | 748 void TemplateURL::SetTemplateURLRefsPrepopulated(bool prepopulated) { |
748 suggestions_url_.set_prepopulated(prepopulated); | 749 suggestions_url_.set_prepopulated(prepopulated); |
749 url_.set_prepopulated(prepopulated); | 750 url_.set_prepopulated(prepopulated); |
750 instant_url_.set_prepopulated(prepopulated); | 751 instant_url_.set_prepopulated(prepopulated); |
751 } | 752 } |
752 | 753 |
753 std::string TemplateURL::GetExtensionId() const { | 754 std::string TemplateURL::GetExtensionId() const { |
754 DCHECK(IsExtensionKeyword()); | 755 DCHECK(IsExtensionKeyword()); |
755 return GURL(url_.url()).host(); | 756 return GURL(url_.url()).host(); |
756 } | 757 } |
757 | 758 |
758 bool TemplateURL::IsExtensionKeyword() const { | 759 bool TemplateURL::IsExtensionKeyword() const { |
759 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme); | 760 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme); |
760 } | 761 } |
OLD | NEW |