| 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/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
| 13 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 14 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
| 15 #include "chrome/browser/google/google_util.h" | 15 #include "chrome/browser/google/google_util.h" |
| 16 #include "chrome/browser/search_engines/search_engine_type.h" | 16 #include "chrome/browser/search_engines/search_engine_type.h" |
| 17 #include "chrome/browser/search_engines/search_terms_data.h" | 17 #include "chrome/browser/search_engines/search_terms_data.h" |
| 18 #include "chrome/browser/search_engines/template_url_service.h" | 18 #include "chrome/browser/search_engines/template_url_service.h" |
| 19 #include "chrome/common/guid.h" | 19 #include "chrome/common/guid.h" |
| 20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 21 #include "content/browser/user_metrics.h" | 21 #include "content/public/browser/user_metrics.h" |
| 22 #include "net/base/escape.h" | 22 #include "net/base/escape.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/gfx/favicon_size.h" | 24 #include "ui/gfx/favicon_size.h" |
| 25 |
| 26 using content::UserMetricsAction; |
| 27 |
| 25 // TODO(pastarmovj): Remove google_update_settings and user_metrics when the | 28 // TODO(pastarmovj): Remove google_update_settings and user_metrics when the |
| 26 // CollectRLZMetrics function is not needed anymore. | 29 // CollectRLZMetrics function is not needed anymore. |
| 27 | 30 |
| 28 // The TemplateURLRef has any number of terms that need to be replaced. Each of | 31 // The TemplateURLRef has any number of terms that need to be replaced. Each of |
| 29 // the terms is enclosed in braces. If the character preceeding the final | 32 // the terms is enclosed in braces. If the character preceeding the final |
| 30 // brace is a ?, it indicates the term is optional and can be replaced with | 33 // brace is a ?, it indicates the term is optional and can be replaced with |
| 31 // an empty string. | 34 // an empty string. |
| 32 static const char kStartParameter = '{'; | 35 static const char kStartParameter = '{'; |
| 33 static const char kEndParameter = '}'; | 36 static const char kEndParameter = '}'; |
| 34 static const char kOptional = '?'; | 37 static const char kOptional = '?'; |
| (...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 ParseIfNecessary(); | 573 ParseIfNecessary(); |
| 571 for (size_t i = 0; i < replacements_.size(); ++i) { | 574 for (size_t i = 0; i < replacements_.size(); ++i) { |
| 572 // We are interesed in searches that were supposed to send the RLZ token. | 575 // We are interesed in searches that were supposed to send the RLZ token. |
| 573 if (replacements_[i].type == GOOGLE_RLZ) { | 576 if (replacements_[i].type == GOOGLE_RLZ) { |
| 574 std::string brand; | 577 std::string brand; |
| 575 // We only have RLZ tocken on a branded browser version. | 578 // We only have RLZ tocken on a branded browser version. |
| 576 if (google_util::GetBrand(&brand) && !brand.empty() && | 579 if (google_util::GetBrand(&brand) && !brand.empty() && |
| 577 !google_util::IsOrganic(brand)) { | 580 !google_util::IsOrganic(brand)) { |
| 578 // Now we know we should have had RLZ token check if there was one. | 581 // Now we know we should have had RLZ token check if there was one. |
| 579 if (url().find("rlz=") != std::string::npos) | 582 if (url().find("rlz=") != std::string::npos) |
| 580 UserMetrics::RecordAction(UserMetricsAction("SearchWithRLZ")); | 583 content::RecordAction(UserMetricsAction("SearchWithRLZ")); |
| 581 else | 584 else |
| 582 UserMetrics::RecordAction(UserMetricsAction("SearchWithoutRLZ")); | 585 content::RecordAction(UserMetricsAction("SearchWithoutRLZ")); |
| 583 } | 586 } |
| 584 return; | 587 return; |
| 585 } | 588 } |
| 586 } | 589 } |
| 587 #endif | 590 #endif |
| 588 } | 591 } |
| 589 | 592 |
| 590 void TemplateURLRef::InvalidateCachedValues() const { | 593 void TemplateURLRef::InvalidateCachedValues() const { |
| 591 supports_replacements_ = valid_ = parsed_ = false; | 594 supports_replacements_ = valid_ = parsed_ = false; |
| 592 host_.clear(); | 595 host_.clear(); |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 747 } | 750 } |
| 748 | 751 |
| 749 std::string TemplateURL::GetExtensionId() const { | 752 std::string TemplateURL::GetExtensionId() const { |
| 750 DCHECK(IsExtensionKeyword()); | 753 DCHECK(IsExtensionKeyword()); |
| 751 return GURL(url_.url()).host(); | 754 return GURL(url_.url()).host(); |
| 752 } | 755 } |
| 753 | 756 |
| 754 bool TemplateURL::IsExtensionKeyword() const { | 757 bool TemplateURL::IsExtensionKeyword() const { |
| 755 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme); | 758 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme); |
| 756 } | 759 } |
| OLD | NEW |