Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(392)

Side by Side Diff: chrome/browser/search_engines/template_url.cc

Issue 7566036: Implement SyncableServices in TemplateURLService. Add related unittests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Recommitting patch. Repaired memory leaks and adjusted unittests to reflect changes. Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 keyword_generated_(false), 636 keyword_generated_(false),
636 show_in_default_list_(false), 637 show_in_default_list_(false),
637 safe_for_autoreplace_(false), 638 safe_for_autoreplace_(false),
638 id_(0), 639 id_(0),
639 date_created_(base::Time::Now()), 640 date_created_(base::Time::Now()),
640 last_modified_(base::Time::Now()), 641 last_modified_(base::Time::Now()),
641 created_by_policy_(false), 642 created_by_policy_(false),
642 usage_count_(0), 643 usage_count_(0),
643 search_engine_type_(SEARCH_ENGINE_OTHER), 644 search_engine_type_(SEARCH_ENGINE_OTHER),
644 logo_id_(kNoSearchEngineLogo), 645 logo_id_(kNoSearchEngineLogo),
645 prepopulate_id_(0) { 646 prepopulate_id_(0),
647 sync_guid_(guid::GenerateGUID()) {
646 } 648 }
647 649
648 TemplateURL::~TemplateURL() { 650 TemplateURL::~TemplateURL() {
649 } 651 }
650 652
651 string16 TemplateURL::AdjustedShortNameForLocaleDirection() const { 653 string16 TemplateURL::AdjustedShortNameForLocaleDirection() const {
652 string16 bidi_safe_short_name = short_name_; 654 string16 bidi_safe_short_name = short_name_;
653 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name); 655 base::i18n::AdjustStringForLocaleDirection(&bidi_safe_short_name);
654 return bidi_safe_short_name; 656 return bidi_safe_short_name;
655 } 657 }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
723 if ((i->type == "image/x-icon" || i->type == "image/vnd.microsoft.icon") 725 if ((i->type == "image/x-icon" || i->type == "image/vnd.microsoft.icon")
724 && i->width == kFaviconSize && i->height == kFaviconSize) { 726 && i->width == kFaviconSize && i->height == kFaviconSize) {
725 return i->url; 727 return i->url;
726 } 728 }
727 } 729 }
728 return GURL(); 730 return GURL();
729 } 731 }
730 732
731 void TemplateURL::SetPrepopulateId(int id) { 733 void TemplateURL::SetPrepopulateId(int id) {
732 prepopulate_id_ = id; 734 prepopulate_id_ = id;
733 if (id > 0) 735 SetTemplateURLRefsPrepopulated(id > 0);
734 SetTemplateURLRefsPrepopulated(true);
735 else
736 SetTemplateURLRefsPrepopulated(false);
737 } 736 }
738 737
739 void TemplateURL::InvalidateCachedValues() const { 738 void TemplateURL::InvalidateCachedValues() const {
740 url_.InvalidateCachedValues(); 739 url_.InvalidateCachedValues();
741 suggestions_url_.InvalidateCachedValues(); 740 suggestions_url_.InvalidateCachedValues();
742 if (autogenerate_keyword_) { 741 if (autogenerate_keyword_) {
743 keyword_.clear(); 742 keyword_.clear();
744 keyword_generated_ = false; 743 keyword_generated_ = false;
745 } 744 }
746 } 745 }
747 746
748 void TemplateURL::SetTemplateURLRefsPrepopulated(bool prepopulated) { 747 void TemplateURL::SetTemplateURLRefsPrepopulated(bool prepopulated) {
749 suggestions_url_.set_prepopulated(prepopulated); 748 suggestions_url_.set_prepopulated(prepopulated);
750 url_.set_prepopulated(prepopulated); 749 url_.set_prepopulated(prepopulated);
751 instant_url_.set_prepopulated(prepopulated); 750 instant_url_.set_prepopulated(prepopulated);
752 } 751 }
753 752
754 std::string TemplateURL::GetExtensionId() const { 753 std::string TemplateURL::GetExtensionId() const {
755 DCHECK(IsExtensionKeyword()); 754 DCHECK(IsExtensionKeyword());
756 return GURL(url_.url()).host(); 755 return GURL(url_.url()).host();
757 } 756 }
758 757
759 bool TemplateURL::IsExtensionKeyword() const { 758 bool TemplateURL::IsExtensionKeyword() const {
760 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme); 759 return GURL(url_.url()).SchemeIs(chrome::kExtensionScheme);
761 } 760 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698