Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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(original_turl->prepopulate_id() == prepopulated_url->prepopulate_id); | |
|
Peter Kasting
2013/02/01 22:47:06
Nit: DCHECK_EQ
| |
| 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 } | |
| 149 | |
| 138 // Loads engines from prepopulate data and merges them in with the existing | 150 // 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. | 151 // 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 | 152 // 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 | 153 // from the DB will be added to it. Note that this function will take |
| 142 // ownership of |prepopulated_urls| and will clear the vector. | 154 // ownership of |prepopulated_urls| and will clear the vector. |
| 143 void MergeEnginesFromPrepopulateData( | 155 void MergeEnginesFromPrepopulateData( |
| 144 Profile* profile, | 156 Profile* profile, |
| 145 WebDataService* service, | 157 WebDataService* service, |
| 146 ScopedVector<TemplateURL>* prepopulated_urls, | 158 ScopedVector<TemplateURL>* prepopulated_urls, |
| 147 size_t default_search_index, | 159 size_t default_search_index, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 176 DCHECK_NE(0, prepopulated_id); | 188 DCHECK_NE(0, prepopulated_id); |
| 177 | 189 |
| 178 TemplateURL* url_in_vector = NULL; | 190 TemplateURL* url_in_vector = NULL; |
| 179 IDMap::iterator existing_url_iter(id_to_turl.find(prepopulated_id)); | 191 IDMap::iterator existing_url_iter(id_to_turl.find(prepopulated_id)); |
| 180 if (existing_url_iter != id_to_turl.end()) { | 192 if (existing_url_iter != id_to_turl.end()) { |
| 181 // Update the data store with the new prepopulated data. Preserve user | 193 // Update the data store with the new prepopulated data. Preserve user |
| 182 // edits to the name and keyword. | 194 // edits to the name and keyword. |
| 183 TemplateURLData data(prepopulated_url->data()); | 195 TemplateURLData data(prepopulated_url->data()); |
| 184 scoped_ptr<TemplateURL> existing_url(existing_url_iter->second); | 196 scoped_ptr<TemplateURL> existing_url(existing_url_iter->second); |
| 185 id_to_turl.erase(existing_url_iter); | 197 id_to_turl.erase(existing_url_iter); |
| 186 if (!existing_url->safe_for_autoreplace()) { | 198 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 | 199 // 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 | 200 // entries from Sync, the conflict resolution logic knows that this was |
| 194 // updated and propagates the new values to the server. | 201 // updated and propagates the new values to the server. |
| 195 data.last_modified = base::Time::Now(); | 202 data.last_modified = base::Time::Now(); |
| 196 data.sync_guid = existing_url->sync_guid(); | |
| 197 if (service) | 203 if (service) |
| 198 service->UpdateKeyword(data); | 204 service->UpdateKeyword(data); |
| 199 | 205 |
| 200 // Replace the entry in |template_urls| with the updated one. | 206 // Replace the entry in |template_urls| with the updated one. |
| 201 TemplateURLService::TemplateURLVector::iterator j = std::find( | 207 TemplateURLService::TemplateURLVector::iterator j = std::find( |
| 202 template_urls->begin(), template_urls->end(), existing_url.get()); | 208 template_urls->begin(), template_urls->end(), existing_url.get()); |
| 203 *j = new TemplateURL(profile, data); | 209 *j = new TemplateURL(profile, data); |
| 204 url_in_vector = *j; | 210 url_in_vector = *j; |
| 205 if (*default_search_provider == existing_url.get()) | 211 if (*default_search_provider == existing_url.get()) |
| 206 *default_search_provider = url_in_vector; | 212 *default_search_provider = url_in_vector; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 std::vector<std::string> deduped_encodings; | 309 std::vector<std::string> deduped_encodings; |
| 304 std::set<std::string> encoding_set; | 310 std::set<std::string> encoding_set; |
| 305 for (std::vector<std::string>::const_iterator i(encodings->begin()); | 311 for (std::vector<std::string>::const_iterator i(encodings->begin()); |
| 306 i != encodings->end(); ++i) { | 312 i != encodings->end(); ++i) { |
| 307 if (encoding_set.insert(*i).second) | 313 if (encoding_set.insert(*i).second) |
| 308 deduped_encodings.push_back(*i); | 314 deduped_encodings.push_back(*i); |
| 309 } | 315 } |
| 310 encodings->swap(deduped_encodings); | 316 encodings->swap(deduped_encodings); |
| 311 return encodings->size() != deduped_encodings.size(); | 317 return encodings->size() != deduped_encodings.size(); |
| 312 } | 318 } |
| OLD | NEW |