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

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

Issue 12084076: Ensure post-sync TemplateURL of prepopulated engines use built-in version. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_service.h" 5 #include "chrome/browser/search_engines/template_url_service.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 1738 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 1749
1750 string16 old_keyword(existing_turl->keyword()); 1750 string16 old_keyword(existing_turl->keyword());
1751 keyword_to_template_map_.erase(old_keyword); 1751 keyword_to_template_map_.erase(old_keyword);
1752 if (!existing_turl->sync_guid().empty()) 1752 if (!existing_turl->sync_guid().empty())
1753 guid_to_template_map_.erase(existing_turl->sync_guid()); 1753 guid_to_template_map_.erase(existing_turl->sync_guid());
1754 1754
1755 provider_map_->Remove(existing_turl, old_search_terms_data); 1755 provider_map_->Remove(existing_turl, old_search_terms_data);
1756 TemplateURLID previous_id = existing_turl->id(); 1756 TemplateURLID previous_id = existing_turl->id();
1757 existing_turl->CopyFrom(new_values); 1757 existing_turl->CopyFrom(new_values);
1758 existing_turl->data_.id = previous_id; 1758 existing_turl->data_.id = previous_id;
1759 UpdatePrepopulatedTemplateURL(existing_turl);
1760
1759 UIThreadSearchTermsData new_search_terms_data(profile_); 1761 UIThreadSearchTermsData new_search_terms_data(profile_);
1760 provider_map_->Add(existing_turl, new_search_terms_data); 1762 provider_map_->Add(existing_turl, new_search_terms_data);
1761 1763
1762 const string16& keyword = existing_turl->keyword(); 1764 const string16& keyword = existing_turl->keyword();
1763 KeywordToTemplateMap::const_iterator i = 1765 KeywordToTemplateMap::const_iterator i =
1764 keyword_to_template_map_.find(keyword); 1766 keyword_to_template_map_.find(keyword);
1765 if (i == keyword_to_template_map_.end()) { 1767 if (i == keyword_to_template_map_.end()) {
1766 keyword_to_template_map_[keyword] = existing_turl; 1768 keyword_to_template_map_[keyword] = existing_turl;
1767 } else { 1769 } else {
1768 // We can theoretically reach here in two cases: 1770 // We can theoretically reach here in two cases:
(...skipping 29 matching lines...) Expand all
1798 existing_turl, 1800 existing_turl,
1799 syncer::SyncChange::ACTION_UPDATE); 1801 syncer::SyncChange::ACTION_UPDATE);
1800 1802
1801 if (default_search_provider_ == existing_turl) { 1803 if (default_search_provider_ == existing_turl) {
1802 bool success = SetDefaultSearchProviderNoNotify(existing_turl); 1804 bool success = SetDefaultSearchProviderNoNotify(existing_turl);
1803 DCHECK(success); 1805 DCHECK(success);
1804 } 1806 }
1805 return true; 1807 return true;
1806 } 1808 }
1807 1809
1810 void TemplateURLService::UpdatePrepopulatedTemplateURL(
1811 TemplateURL* template_url) {
1812 scoped_ptr<TemplateURL> prepopulated_turl(
1813 TemplateURLPrepopulateData::MakeTemplateURLFromPrepopulateId(
1814 template_url->profile(), template_url->prepopulate_id()));
1815 if (prepopulated_turl.get() != NULL) {
Peter Kasting 2013/01/30 22:32:33 Nit: You can remove ".get() != NULL" at this point
1816 TemplateURLID id = template_url->id();
1817 string16 short_name = template_url->short_name();
1818 string16 keyword = template_url->keyword();
1819 template_url->CopyFrom(*prepopulated_turl.get());
1820 template_url->data_.short_name = short_name;
1821 template_url->data_.SetKeyword(keyword);
1822 template_url->data_.id = id;
1823 }
1824 }
1825
1808 PrefService* TemplateURLService::GetPrefs() { 1826 PrefService* TemplateURLService::GetPrefs() {
1809 return profile_ ? profile_->GetPrefs() : NULL; 1827 return profile_ ? profile_->GetPrefs() : NULL;
1810 } 1828 }
1811 1829
1812 void TemplateURLService::UpdateKeywordSearchTermsForURL( 1830 void TemplateURLService::UpdateKeywordSearchTermsForURL(
1813 const history::URLVisitedDetails& details) { 1831 const history::URLVisitedDetails& details) {
1814 const history::URLRow& row = details.row; 1832 const history::URLRow& row = details.row;
1815 if (!row.url().is_valid() || 1833 if (!row.url().is_valid() ||
1816 !row.url().parsed_for_possibly_invalid_spec().query.is_nonempty()) { 1834 !row.url().parsed_for_possibly_invalid_spec().query.is_nonempty()) {
1817 return; 1835 return;
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
2128 if (url) 2146 if (url)
2129 ProcessTemplateURLChange(FROM_HERE, 2147 ProcessTemplateURLChange(FROM_HERE,
2130 url, 2148 url,
2131 syncer::SyncChange::ACTION_UPDATE); 2149 syncer::SyncChange::ACTION_UPDATE);
2132 return true; 2150 return true;
2133 } 2151 }
2134 2152
2135 bool TemplateURLService::AddNoNotify(TemplateURL* template_url, 2153 bool TemplateURLService::AddNoNotify(TemplateURL* template_url,
2136 bool newly_adding) { 2154 bool newly_adding) {
2137 DCHECK(template_url); 2155 DCHECK(template_url);
2138 2156 UpdatePrepopulatedTemplateURL(template_url);
2139 if (newly_adding) { 2157 if (newly_adding) {
2140 DCHECK_EQ(kInvalidTemplateURLID, template_url->id()); 2158 DCHECK_EQ(kInvalidTemplateURLID, template_url->id());
2141 DCHECK(std::find(template_urls_.begin(), template_urls_.end(), 2159 DCHECK(std::find(template_urls_.begin(), template_urls_.end(),
2142 template_url) == template_urls_.end()); 2160 template_url) == template_urls_.end());
2143 template_url->data_.id = ++next_id_; 2161 template_url->data_.id = ++next_id_;
2144 } 2162 }
2145 2163
2146 template_url->ResetKeywordIfNecessary(false); 2164 template_url->ResetKeywordIfNecessary(false);
2147 if (!template_url->IsExtensionKeyword()) { 2165 if (!template_url->IsExtensionKeyword()) {
2148 // Check whether |template_url|'s keyword conflicts with any already in the 2166 // Check whether |template_url|'s keyword conflicts with any already in the
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
2499 // TODO(mpcomplete): If we allow editing extension keywords, then those 2517 // TODO(mpcomplete): If we allow editing extension keywords, then those
2500 // should be persisted to disk and synced. 2518 // should be persisted to disk and synced.
2501 if (template_url->sync_guid().empty() && 2519 if (template_url->sync_guid().empty() &&
2502 !template_url->IsExtensionKeyword()) { 2520 !template_url->IsExtensionKeyword()) {
2503 template_url->data_.sync_guid = base::GenerateGUID(); 2521 template_url->data_.sync_guid = base::GenerateGUID();
2504 if (service_.get()) 2522 if (service_.get())
2505 service_->UpdateKeyword(template_url->data()); 2523 service_->UpdateKeyword(template_url->data());
2506 } 2524 }
2507 } 2525 }
2508 } 2526 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698