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

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: Revised approach, see bug description 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"
11 #include "base/guid.h" 11 #include "base/guid.h"
12 #include "base/i18n/case_conversion.h" 12 #include "base/i18n/case_conversion.h"
13 #include "base/memory/scoped_vector.h"
13 #include "base/metrics/histogram.h" 14 #include "base/metrics/histogram.h"
14 #include "base/stl_util.h" 15 #include "base/stl_util.h"
15 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
16 #include "base/string_split.h" 17 #include "base/string_split.h"
17 #include "base/string_util.h" 18 #include "base/string_util.h"
18 #include "base/time.h" 19 #include "base/time.h"
19 #include "base/utf_string_conversions.h" 20 #include "base/utf_string_conversions.h"
20 #include "chrome/browser/google/google_url_tracker.h" 21 #include "chrome/browser/google/google_url_tracker.h"
21 #include "chrome/browser/history/history_notifications.h" 22 #include "chrome/browser/history/history_notifications.h"
22 #include "chrome/browser/history/history_service.h" 23 #include "chrome/browser/history/history_service.h"
(...skipping 1726 matching lines...) Expand 10 before | Expand all | Expand 10 after
1749 1750
1750 string16 old_keyword(existing_turl->keyword()); 1751 string16 old_keyword(existing_turl->keyword());
1751 keyword_to_template_map_.erase(old_keyword); 1752 keyword_to_template_map_.erase(old_keyword);
1752 if (!existing_turl->sync_guid().empty()) 1753 if (!existing_turl->sync_guid().empty())
1753 guid_to_template_map_.erase(existing_turl->sync_guid()); 1754 guid_to_template_map_.erase(existing_turl->sync_guid());
1754 1755
1755 provider_map_->Remove(existing_turl, old_search_terms_data); 1756 provider_map_->Remove(existing_turl, old_search_terms_data);
1756 TemplateURLID previous_id = existing_turl->id(); 1757 TemplateURLID previous_id = existing_turl->id();
1757 existing_turl->CopyFrom(new_values); 1758 existing_turl->CopyFrom(new_values);
1758 existing_turl->data_.id = previous_id; 1759 existing_turl->data_.id = previous_id;
1760 UpdateTemplateURLIfPrepopulated(existing_turl);
1761
1759 UIThreadSearchTermsData new_search_terms_data(profile_); 1762 UIThreadSearchTermsData new_search_terms_data(profile_);
1760 provider_map_->Add(existing_turl, new_search_terms_data); 1763 provider_map_->Add(existing_turl, new_search_terms_data);
1761 1764
1762 const string16& keyword = existing_turl->keyword(); 1765 const string16& keyword = existing_turl->keyword();
1763 KeywordToTemplateMap::const_iterator i = 1766 KeywordToTemplateMap::const_iterator i =
1764 keyword_to_template_map_.find(keyword); 1767 keyword_to_template_map_.find(keyword);
1765 if (i == keyword_to_template_map_.end()) { 1768 if (i == keyword_to_template_map_.end()) {
1766 keyword_to_template_map_[keyword] = existing_turl; 1769 keyword_to_template_map_[keyword] = existing_turl;
1767 } else { 1770 } else {
1768 // We can theoretically reach here in two cases: 1771 // We can theoretically reach here in two cases:
(...skipping 29 matching lines...) Expand all
1798 existing_turl, 1801 existing_turl,
1799 syncer::SyncChange::ACTION_UPDATE); 1802 syncer::SyncChange::ACTION_UPDATE);
1800 1803
1801 if (default_search_provider_ == existing_turl) { 1804 if (default_search_provider_ == existing_turl) {
1802 bool success = SetDefaultSearchProviderNoNotify(existing_turl); 1805 bool success = SetDefaultSearchProviderNoNotify(existing_turl);
1803 DCHECK(success); 1806 DCHECK(success);
1804 } 1807 }
1805 return true; 1808 return true;
1806 } 1809 }
1807 1810
1811 void TemplateURLService::UpdateTemplateURLIfPrepopulated(
1812 TemplateURL* template_url) {
1813 int prepopulate_id = template_url->prepopulate_id();
1814 if (template_url->prepopulate_id() == 0)
1815 return;
1816
1817 ScopedVector<TemplateURL> prepopulated_urls;
1818 size_t default_search_index;
1819 TemplateURLPrepopulateData::GetPrepopulatedEngines(profile_,
1820 &prepopulated_urls.get(), &default_search_index);
1821
1822 for (size_t i = 0; i < prepopulated_urls.size(); ++i) {
1823 if (prepopulated_urls[i]->prepopulate_id() == prepopulate_id) {
1824 MergeIntoPrepopulatedEngineData(&prepopulated_urls[i]->data_,
1825 template_url);
1826 template_url->CopyFrom(*prepopulated_urls[i]);
1827 }
1828 }
1829 }
1830
1808 PrefService* TemplateURLService::GetPrefs() { 1831 PrefService* TemplateURLService::GetPrefs() {
1809 return profile_ ? profile_->GetPrefs() : NULL; 1832 return profile_ ? profile_->GetPrefs() : NULL;
1810 } 1833 }
1811 1834
1812 void TemplateURLService::UpdateKeywordSearchTermsForURL( 1835 void TemplateURLService::UpdateKeywordSearchTermsForURL(
1813 const history::URLVisitedDetails& details) { 1836 const history::URLVisitedDetails& details) {
1814 const history::URLRow& row = details.row; 1837 const history::URLRow& row = details.row;
1815 if (!row.url().is_valid() || 1838 if (!row.url().is_valid() ||
1816 !row.url().parsed_for_possibly_invalid_spec().query.is_nonempty()) { 1839 !row.url().parsed_for_possibly_invalid_spec().query.is_nonempty()) {
1817 return; 1840 return;
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
2128 if (url) 2151 if (url)
2129 ProcessTemplateURLChange(FROM_HERE, 2152 ProcessTemplateURLChange(FROM_HERE,
2130 url, 2153 url,
2131 syncer::SyncChange::ACTION_UPDATE); 2154 syncer::SyncChange::ACTION_UPDATE);
2132 return true; 2155 return true;
2133 } 2156 }
2134 2157
2135 bool TemplateURLService::AddNoNotify(TemplateURL* template_url, 2158 bool TemplateURLService::AddNoNotify(TemplateURL* template_url,
2136 bool newly_adding) { 2159 bool newly_adding) {
2137 DCHECK(template_url); 2160 DCHECK(template_url);
2138 2161 UpdateTemplateURLIfPrepopulated(template_url);
2139 if (newly_adding) { 2162 if (newly_adding) {
2140 DCHECK_EQ(kInvalidTemplateURLID, template_url->id()); 2163 DCHECK_EQ(kInvalidTemplateURLID, template_url->id());
2141 DCHECK(std::find(template_urls_.begin(), template_urls_.end(), 2164 DCHECK(std::find(template_urls_.begin(), template_urls_.end(),
2142 template_url) == template_urls_.end()); 2165 template_url) == template_urls_.end());
2143 template_url->data_.id = ++next_id_; 2166 template_url->data_.id = ++next_id_;
2144 } 2167 }
2145 2168
2146 template_url->ResetKeywordIfNecessary(false); 2169 template_url->ResetKeywordIfNecessary(false);
2147 if (!template_url->IsExtensionKeyword()) { 2170 if (!template_url->IsExtensionKeyword()) {
2148 // Check whether |template_url|'s keyword conflicts with any already in the 2171 // 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 2522 // TODO(mpcomplete): If we allow editing extension keywords, then those
2500 // should be persisted to disk and synced. 2523 // should be persisted to disk and synced.
2501 if (template_url->sync_guid().empty() && 2524 if (template_url->sync_guid().empty() &&
2502 !template_url->IsExtensionKeyword()) { 2525 !template_url->IsExtensionKeyword()) {
2503 template_url->data_.sync_guid = base::GenerateGUID(); 2526 template_url->data_.sync_guid = base::GenerateGUID();
2504 if (service_.get()) 2527 if (service_.get())
2505 service_->UpdateKeyword(template_url->data()); 2528 service_->UpdateKeyword(template_url->data());
2506 } 2529 }
2507 } 2530 }
2508 } 2531 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698