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

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

Issue 10676012: De-dupe input encodings in TemplateURLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 5 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
« no previous file with comments | « no previous file | chrome/browser/search_engines/template_url_service_sync_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/environment.h" 9 #include "base/environment.h"
10 #include "base/guid.h" 10 #include "base/guid.h"
(...skipping 1232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1243 keyword = ASCIIToUTF16("dummy"); // Will be replaced below. 1243 keyword = ASCIIToUTF16("dummy"); // Will be replaced below.
1244 DCHECK(!keyword.empty()); 1244 DCHECK(!keyword.empty());
1245 data.SetKeyword(keyword); 1245 data.SetKeyword(keyword);
1246 data.SetURL(specifics.url()); 1246 data.SetURL(specifics.url());
1247 data.suggestions_url = specifics.suggestions_url(); 1247 data.suggestions_url = specifics.suggestions_url();
1248 data.instant_url = specifics.instant_url(); 1248 data.instant_url = specifics.instant_url();
1249 data.favicon_url = GURL(specifics.favicon_url()); 1249 data.favicon_url = GURL(specifics.favicon_url());
1250 data.show_in_default_list = specifics.show_in_default_list(); 1250 data.show_in_default_list = specifics.show_in_default_list();
1251 data.safe_for_autoreplace = specifics.safe_for_autoreplace(); 1251 data.safe_for_autoreplace = specifics.safe_for_autoreplace();
1252 base::SplitString(specifics.input_encodings(), ';', &data.input_encodings); 1252 base::SplitString(specifics.input_encodings(), ';', &data.input_encodings);
1253 // If the server data has duplicate encodings, we'll want to push an update
1254 // below to correct it. Note that we also fix this in
1255 // GetSearchProvidersUsingKeywordResult(), since otherwise we'd never correct
1256 // local problems for clients which have disabled search engine sync.
1257 bool deduped = DeDupeEncodings(&data.input_encodings);
1253 data.date_created = base::Time::FromInternalValue(specifics.date_created()); 1258 data.date_created = base::Time::FromInternalValue(specifics.date_created());
1254 data.last_modified = base::Time::FromInternalValue(specifics.last_modified()); 1259 data.last_modified = base::Time::FromInternalValue(specifics.last_modified());
1255 data.prepopulate_id = specifics.prepopulate_id(); 1260 data.prepopulate_id = specifics.prepopulate_id();
1256 data.sync_guid = specifics.sync_guid(); 1261 data.sync_guid = specifics.sync_guid();
1257 1262
1258 TemplateURL* turl = new TemplateURL(profile, data); 1263 TemplateURL* turl = new TemplateURL(profile, data);
1259 DCHECK(!turl->IsExtensionKeyword()); 1264 DCHECK(!turl->IsExtensionKeyword());
1260 if (reset_keyword) { 1265 if (reset_keyword || deduped) {
1261 turl->ResetKeywordIfNecessary(true); 1266 if (reset_keyword)
1267 turl->ResetKeywordIfNecessary(true);
1262 SyncData sync_data = CreateSyncDataFromTemplateURL(*turl); 1268 SyncData sync_data = CreateSyncDataFromTemplateURL(*turl);
1263 change_list->push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data)); 1269 change_list->push_back(SyncChange(SyncChange::ACTION_UPDATE, sync_data));
1264 } else if (turl->IsGoogleSearchURLWithReplaceableKeyword()) { 1270 } else if (turl->IsGoogleSearchURLWithReplaceableKeyword()) {
1265 if (!existing_turl) { 1271 if (!existing_turl) {
1266 // We're adding a new TemplateURL that uses the Google base URL, so set 1272 // We're adding a new TemplateURL that uses the Google base URL, so set
1267 // its keyword appropriately for the local environment. 1273 // its keyword appropriately for the local environment.
1268 turl->ResetKeywordIfNecessary(false); 1274 turl->ResetKeywordIfNecessary(false);
1269 } else if (existing_turl->IsGoogleSearchURLWithReplaceableKeyword()) { 1275 } else if (existing_turl->IsGoogleSearchURLWithReplaceableKeyword()) {
1270 // Ignore keyword changes triggered by the Google base URL changing on 1276 // Ignore keyword changes triggered by the Google base URL changing on
1271 // another client. If the base URL changes in this client as well, we'll 1277 // another client. If the base URL changes in this client as well, we'll
(...skipping 1114 matching lines...) Expand 10 before | Expand all | Expand 10 after
2386 // TODO(mpcomplete): If we allow editing extension keywords, then those 2392 // TODO(mpcomplete): If we allow editing extension keywords, then those
2387 // should be persisted to disk and synced. 2393 // should be persisted to disk and synced.
2388 if (template_url->sync_guid().empty() && 2394 if (template_url->sync_guid().empty() &&
2389 !template_url->IsExtensionKeyword()) { 2395 !template_url->IsExtensionKeyword()) {
2390 template_url->data_.sync_guid = base::GenerateGUID(); 2396 template_url->data_.sync_guid = base::GenerateGUID();
2391 if (service_.get()) 2397 if (service_.get())
2392 service_->UpdateKeyword(template_url->data()); 2398 service_->UpdateKeyword(template_url->data());
2393 } 2399 }
2394 } 2400 }
2395 } 2401 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/search_engines/template_url_service_sync_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698