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

Side by Side Diff: chrome/browser/search_engines/util.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: Change according to pkasting comments. 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
« no previous file with comments | « chrome/browser/search_engines/util.h ('k') | no next file » | 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/util.h" 5 #include "chrome/browser/search_engines/util.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 #include <map> 9 #include <map>
10 #include <vector> 10 #include <vector>
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 int64 id) { 128 int64 id) {
129 for (TemplateURLService::TemplateURLVector::const_iterator i( 129 for (TemplateURLService::TemplateURLVector::const_iterator i(
130 template_urls.begin()); i != template_urls.end(); ++i) { 130 template_urls.begin()); i != template_urls.end(); ++i) {
131 if ((*i)->id() == id) { 131 if ((*i)->id() == id) {
132 return *i; 132 return *i;
133 } 133 }
134 } 134 }
135 return NULL; 135 return NULL;
136 } 136 }
137 137
138 void MergeIntoPrepopulatedEngineData(TemplateURLData* prepopulated_url,
139 const TemplateURL* original_turl) {
140 DCHECK_EQ(original_turl->prepopulate_id(), prepopulated_url->prepopulate_id);
141 if (!original_turl->safe_for_autoreplace()) {
142 prepopulated_url->safe_for_autoreplace = false;
143 prepopulated_url->SetKeyword(original_turl->keyword());
144 prepopulated_url->short_name = original_turl->short_name();
145 }
146 prepopulated_url->id = original_turl->id();
147 prepopulated_url->sync_guid = original_turl->sync_guid();
148 prepopulated_url->date_created = original_turl->date_created();
149 prepopulated_url->last_modified = original_turl->last_modified();
150 }
151
138 // Loads engines from prepopulate data and merges them in with the existing 152 // Loads engines from prepopulate data and merges them in with the existing
139 // engines. This is invoked when the version of the prepopulate data changes. 153 // engines. This is invoked when the version of the prepopulate data changes.
140 // If |removed_keyword_guids| is not NULL, the Sync GUID of each item removed 154 // If |removed_keyword_guids| is not NULL, the Sync GUID of each item removed
141 // from the DB will be added to it. Note that this function will take 155 // from the DB will be added to it. Note that this function will take
142 // ownership of |prepopulated_urls| and will clear the vector. 156 // ownership of |prepopulated_urls| and will clear the vector.
143 void MergeEnginesFromPrepopulateData( 157 void MergeEnginesFromPrepopulateData(
144 Profile* profile, 158 Profile* profile,
145 WebDataService* service, 159 WebDataService* service,
146 ScopedVector<TemplateURL>* prepopulated_urls, 160 ScopedVector<TemplateURL>* prepopulated_urls,
147 size_t default_search_index, 161 size_t default_search_index,
(...skipping 28 matching lines...) Expand all
176 DCHECK_NE(0, prepopulated_id); 190 DCHECK_NE(0, prepopulated_id);
177 191
178 TemplateURL* url_in_vector = NULL; 192 TemplateURL* url_in_vector = NULL;
179 IDMap::iterator existing_url_iter(id_to_turl.find(prepopulated_id)); 193 IDMap::iterator existing_url_iter(id_to_turl.find(prepopulated_id));
180 if (existing_url_iter != id_to_turl.end()) { 194 if (existing_url_iter != id_to_turl.end()) {
181 // Update the data store with the new prepopulated data. Preserve user 195 // Update the data store with the new prepopulated data. Preserve user
182 // edits to the name and keyword. 196 // edits to the name and keyword.
183 TemplateURLData data(prepopulated_url->data()); 197 TemplateURLData data(prepopulated_url->data());
184 scoped_ptr<TemplateURL> existing_url(existing_url_iter->second); 198 scoped_ptr<TemplateURL> existing_url(existing_url_iter->second);
185 id_to_turl.erase(existing_url_iter); 199 id_to_turl.erase(existing_url_iter);
186 if (!existing_url->safe_for_autoreplace()) { 200 MergeIntoPrepopulatedEngineData(&data, existing_url.get());
187 data.safe_for_autoreplace = false;
188 data.SetKeyword(existing_url->keyword());
189 data.short_name = existing_url->short_name();
190 }
191 data.id = existing_url->id();
192 // Update last_modified to ensure that if this entry is later merged with 201 // Update last_modified to ensure that if this entry is later merged with
193 // entries from Sync, the conflict resolution logic knows that this was 202 // entries from Sync, the conflict resolution logic knows that this was
194 // updated and propagates the new values to the server. 203 // updated and propagates the new values to the server.
195 data.last_modified = base::Time::Now(); 204 data.last_modified = base::Time::Now();
196 data.sync_guid = existing_url->sync_guid();
197 if (service) 205 if (service)
198 service->UpdateKeyword(data); 206 service->UpdateKeyword(data);
199 207
200 // Replace the entry in |template_urls| with the updated one. 208 // Replace the entry in |template_urls| with the updated one.
201 TemplateURLService::TemplateURLVector::iterator j = std::find( 209 TemplateURLService::TemplateURLVector::iterator j = std::find(
202 template_urls->begin(), template_urls->end(), existing_url.get()); 210 template_urls->begin(), template_urls->end(), existing_url.get());
203 *j = new TemplateURL(profile, data); 211 *j = new TemplateURL(profile, data);
204 url_in_vector = *j; 212 url_in_vector = *j;
205 if (*default_search_provider == existing_url.get()) 213 if (*default_search_provider == existing_url.get())
206 *default_search_provider = url_in_vector; 214 *default_search_provider = url_in_vector;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 std::vector<std::string> deduped_encodings; 311 std::vector<std::string> deduped_encodings;
304 std::set<std::string> encoding_set; 312 std::set<std::string> encoding_set;
305 for (std::vector<std::string>::const_iterator i(encodings->begin()); 313 for (std::vector<std::string>::const_iterator i(encodings->begin());
306 i != encodings->end(); ++i) { 314 i != encodings->end(); ++i) {
307 if (encoding_set.insert(*i).second) 315 if (encoding_set.insert(*i).second)
308 deduped_encodings.push_back(*i); 316 deduped_encodings.push_back(*i);
309 } 317 }
310 encodings->swap(deduped_encodings); 318 encodings->swap(deduped_encodings);
311 return encodings->size() != deduped_encodings.size(); 319 return encodings->size() != deduped_encodings.size();
312 } 320 }
OLDNEW
« no previous file with comments | « chrome/browser/search_engines/util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698