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/icu_string_conversions.h" | 7 #include "base/i18n/icu_string_conversions.h" |
8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/metrics/user_metrics.h" |
12 #include "chrome/browser/search_engines/search_engine_type.h" | 13 #include "chrome/browser/search_engines/search_engine_type.h" |
13 #include "chrome/browser/search_engines/search_terms_data.h" | 14 #include "chrome/browser/search_engines/search_terms_data.h" |
14 #include "chrome/browser/search_engines/template_url_model.h" | 15 #include "chrome/browser/search_engines/template_url_model.h" |
15 #include "chrome/common/url_constants.h" | 16 #include "chrome/common/url_constants.h" |
| 17 #include "chrome/installer/util/google_update_settings.h" |
16 #include "net/base/escape.h" | 18 #include "net/base/escape.h" |
17 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/gfx/favicon_size.h" | 20 #include "ui/gfx/favicon_size.h" |
| 21 // TODO(pastarmovj): Remove google_update_settings and user_metrics when the |
| 22 // CollectRLZMetrics function is not needed anymore. |
19 | 23 |
20 // The TemplateURLRef has any number of terms that need to be replaced. Each of | 24 // The TemplateURLRef has any number of terms that need to be replaced. Each of |
21 // the terms is enclosed in braces. If the character preceeding the final | 25 // the terms is enclosed in braces. If the character preceeding the final |
22 // brace is a ?, it indicates the term is optional and can be replaced with | 26 // brace is a ?, it indicates the term is optional and can be replaced with |
23 // an empty string. | 27 // an empty string. |
24 static const char kStartParameter = '{'; | 28 static const char kStartParameter = '{'; |
25 static const char kEndParameter = '}'; | 29 static const char kEndParameter = '}'; |
26 static const char kOptional = '?'; | 30 static const char kOptional = '?'; |
27 | 31 |
28 // Known parameters found in the URL. | 32 // Known parameters found in the URL. |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 } | 515 } |
512 return false; | 516 return false; |
513 } | 517 } |
514 | 518 |
515 // static | 519 // static |
516 bool TemplateURLRef::SameUrlRefs(const TemplateURLRef* ref1, | 520 bool TemplateURLRef::SameUrlRefs(const TemplateURLRef* ref1, |
517 const TemplateURLRef* ref2) { | 521 const TemplateURLRef* ref2) { |
518 return ref1 == ref2 || (ref1 && ref2 && ref1->url() == ref2->url()); | 522 return ref1 == ref2 || (ref1 && ref2 && ref1->url() == ref2->url()); |
519 } | 523 } |
520 | 524 |
| 525 void TemplateURLRef::CollectRLZMetrics() const { |
| 526 #if defined(OS_WIN) && defined(GOOGLE_CHROME_BUILD) |
| 527 ParseIfNecessary(); |
| 528 for (size_t i = 0; i < replacements_.size(); ++i) { |
| 529 // We are interesed in searches that were supposed to send the RLZ token. |
| 530 if (replacements_[i].type == GOOGLE_RLZ) { |
| 531 string16 brand; |
| 532 // We only have RLZ tocken on a branded browser version. |
| 533 if (GoogleUpdateSettings::GetBrand(&brand) && !brand.empty() && |
| 534 !GoogleUpdateSettings::IsOrganic(brand)) { |
| 535 // Now we know we should have had RLZ token check if there was one. |
| 536 if (url().find("rlz=") != std::string::npos) |
| 537 UserMetrics::RecordAction(UserMetricsAction("SearchWithRLZ")); |
| 538 else |
| 539 UserMetrics::RecordAction(UserMetricsAction("SearchWithoutRLZ")); |
| 540 } |
| 541 return; |
| 542 } |
| 543 } |
| 544 #endif |
| 545 } |
| 546 |
521 void TemplateURLRef::InvalidateCachedValues() const { | 547 void TemplateURLRef::InvalidateCachedValues() const { |
522 supports_replacements_ = valid_ = parsed_ = false; | 548 supports_replacements_ = valid_ = parsed_ = false; |
523 host_.clear(); | 549 host_.clear(); |
524 path_.clear(); | 550 path_.clear(); |
525 search_term_key_.clear(); | 551 search_term_key_.clear(); |
526 replacements_.clear(); | 552 replacements_.clear(); |
527 } | 553 } |
528 | 554 |
529 // TemplateURL ---------------------------------------------------------------- | 555 // TemplateURL ---------------------------------------------------------------- |
530 | 556 |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 } | 691 } |
666 | 692 |
667 std::string TemplateURL::GetExtensionId() const { | 693 std::string TemplateURL::GetExtensionId() const { |
668 DCHECK(IsExtensionKeyword()); | 694 DCHECK(IsExtensionKeyword()); |
669 return GURL(url_.url()).host(); | 695 return GURL(url_.url()).host(); |
670 } | 696 } |
671 | 697 |
672 bool TemplateURL::IsExtensionKeyword() const { | 698 bool TemplateURL::IsExtensionKeyword() const { |
673 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme); | 699 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme); |
674 } | 700 } |
OLD | NEW |