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" |
18 #include "chrome/common/url_constants.h" | 19 #include "chrome/common/url_constants.h" |
19 #include "chrome/installer/util/google_update_settings.h" | 20 #include "chrome/installer/util/google_update_settings.h" |
20 #include "content/browser/user_metrics.h" | 21 #include "content/browser/user_metrics.h" |
21 #include "net/base/escape.h" | 22 #include "net/base/escape.h" |
22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/gfx/favicon_size.h" | 24 #include "ui/gfx/favicon_size.h" |
24 // TODO(pastarmovj): Remove google_update_settings and user_metrics when the | 25 // TODO(pastarmovj): Remove google_update_settings and user_metrics when the |
25 // CollectRLZMetrics function is not needed anymore. | 26 // CollectRLZMetrics function is not needed anymore. |
26 | 27 |
27 // The TemplateURLRef has any number of terms that need to be replaced. Each of | 28 // The TemplateURLRef has any number of terms that need to be replaced. Each of |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
612 keyword_generated_(false), | 613 keyword_generated_(false), |
613 show_in_default_list_(false), | 614 show_in_default_list_(false), |
614 safe_for_autoreplace_(false), | 615 safe_for_autoreplace_(false), |
615 id_(0), | 616 id_(0), |
616 date_created_(base::Time::Now()), | 617 date_created_(base::Time::Now()), |
617 last_modified_(base::Time::Now()), | 618 last_modified_(base::Time::Now()), |
618 created_by_policy_(false), | 619 created_by_policy_(false), |
619 usage_count_(0), | 620 usage_count_(0), |
620 search_engine_type_(SEARCH_ENGINE_OTHER), | 621 search_engine_type_(SEARCH_ENGINE_OTHER), |
621 logo_id_(kNoSearchEngineLogo), | 622 logo_id_(kNoSearchEngineLogo), |
622 prepopulate_id_(0) { | 623 prepopulate_id_(0), |
| 624 sync_guid_(guid::GenerateGUID()) { |
623 } | 625 } |
624 | 626 |
625 TemplateURL::~TemplateURL() { | 627 TemplateURL::~TemplateURL() { |
626 } | 628 } |
627 | 629 |
628 string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { | 630 string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { |
629 string16 bidi_safe_short_name = short_name_; | 631 string16 bidi_safe_short_name = short_name_; |
630 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); | 632 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); |
631 return bidi_safe_short_name; | 633 return bidi_safe_short_name; |
632 } | 634 } |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 if ((i->type == "image/x-icon" || i->type == "image/vnd.microsoft.icon") | 702 if ((i->type == "image/x-icon" || i->type == "image/vnd.microsoft.icon") |
701 && i->width == kFaviconSize && i->height == kFaviconSize) { | 703 && i->width == kFaviconSize && i->height == kFaviconSize) { |
702 return i->url; | 704 return i->url; |
703 } | 705 } |
704 } | 706 } |
705 return GURL(); | 707 return GURL(); |
706 } | 708 } |
707 | 709 |
708 void TemplateURL::SetPrepopulateId(int id) { | 710 void TemplateURL::SetPrepopulateId(int id) { |
709 prepopulate_id_ = id; | 711 prepopulate_id_ = id; |
710 if (id > 0) | 712 SetTemplateURLRefsPrepopulated(id > 0); |
711 SetTemplateURLRefsPrepopulated(true); | |
712 else | |
713 SetTemplateURLRefsPrepopulated(false); | |
714 } | 713 } |
715 | 714 |
716 void TemplateURL::InvalidateCachedValues() const { | 715 void TemplateURL::InvalidateCachedValues() const { |
717 url_.InvalidateCachedValues(); | 716 url_.InvalidateCachedValues(); |
718 suggestions_url_.InvalidateCachedValues(); | 717 suggestions_url_.InvalidateCachedValues(); |
719 if (autogenerate_keyword_) { | 718 if (autogenerate_keyword_) { |
720 keyword_.clear(); | 719 keyword_.clear(); |
721 keyword_generated_ = false; | 720 keyword_generated_ = false; |
722 } | 721 } |
723 } | 722 } |
724 | 723 |
725 void TemplateURL::SetTemplateURLRefsPrepopulated(bool prepopulated) { | 724 void TemplateURL::SetTemplateURLRefsPrepopulated(bool prepopulated) { |
726 suggestions_url_.set_prepopulated(prepopulated); | 725 suggestions_url_.set_prepopulated(prepopulated); |
727 url_.set_prepopulated(prepopulated); | 726 url_.set_prepopulated(prepopulated); |
728 instant_url_.set_prepopulated(prepopulated); | 727 instant_url_.set_prepopulated(prepopulated); |
729 } | 728 } |
730 | 729 |
731 std::string TemplateURL::GetExtensionId() const { | 730 std::string TemplateURL::GetExtensionId() const { |
732 DCHECK(IsExtensionKeyword()); | 731 DCHECK(IsExtensionKeyword()); |
733 return GURL(url_.url()).host(); | 732 return GURL(url_.url()).host(); |
734 } | 733 } |
735 | 734 |
736 bool TemplateURL::IsExtensionKeyword() const { | 735 bool TemplateURL::IsExtensionKeyword() const { |
737 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme); | 736 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme); |
738 } | 737 } |
OLD | NEW |