| 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 <map> | 7 #include <map> |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 for (EditedEngines::iterator i(actions.edited_engines.begin()); | 233 for (EditedEngines::iterator i(actions.edited_engines.begin()); |
| 234 i < actions.edited_engines.end(); ++i) { | 234 i < actions.edited_engines.end(); ++i) { |
| 235 TemplateURLData& data = i->second; | 235 TemplateURLData& data = i->second; |
| 236 scoped_ptr<TemplateURL> existing_url(i->first); | 236 scoped_ptr<TemplateURL> existing_url(i->first); |
| 237 if (service) | 237 if (service) |
| 238 service->UpdateKeyword(data); | 238 service->UpdateKeyword(data); |
| 239 | 239 |
| 240 // Replace the entry in |template_urls| with the updated one. | 240 // Replace the entry in |template_urls| with the updated one. |
| 241 TemplateURLService::TemplateURLVector::iterator j = std::find( | 241 TemplateURLService::TemplateURLVector::iterator j = std::find( |
| 242 template_urls->begin(), template_urls->end(), existing_url.get()); | 242 template_urls->begin(), template_urls->end(), existing_url.get()); |
| 243 *j = new TemplateURL(profile, data); | 243 *j = new TemplateURL(data); |
| 244 } | 244 } |
| 245 | 245 |
| 246 // Add items. | 246 // Add items. |
| 247 for (std::vector<TemplateURLData>::const_iterator it = | 247 for (std::vector<TemplateURLData>::const_iterator it = |
| 248 actions.added_engines.begin(); | 248 actions.added_engines.begin(); |
| 249 it != actions.added_engines.end(); | 249 it != actions.added_engines.end(); |
| 250 ++it) { | 250 ++it) { |
| 251 template_urls->push_back(new TemplateURL(profile, *it)); | 251 template_urls->push_back(new TemplateURL(*it)); |
| 252 } | 252 } |
| 253 } | 253 } |
| 254 | 254 |
| 255 ActionsFromPrepopulateData CreateActionsFromCurrentPrepopulateData( | 255 ActionsFromPrepopulateData CreateActionsFromCurrentPrepopulateData( |
| 256 ScopedVector<TemplateURLData>* prepopulated_urls, | 256 ScopedVector<TemplateURLData>* prepopulated_urls, |
| 257 const TemplateURLService::TemplateURLVector& existing_urls, | 257 const TemplateURLService::TemplateURLVector& existing_urls, |
| 258 const TemplateURL* default_search_provider) { | 258 const TemplateURL* default_search_provider) { |
| 259 // Create a map to hold all provided |template_urls| that originally came from | 259 // Create a map to hold all provided |template_urls| that originally came from |
| 260 // prepopulate data (i.e. have a non-zero prepopulate_id()). | 260 // prepopulate data (i.e. have a non-zero prepopulate_id()). |
| 261 typedef std::map<int, TemplateURL*> IDMap; | 261 typedef std::map<int, TemplateURL*> IDMap; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 // adjust the last_modified time of this keyword; this way, we won't later | 343 // adjust the last_modified time of this keyword; this way, we won't later |
| 344 // overwrite any changes on the sync server that happened to this keyword | 344 // overwrite any changes on the sync server that happened to this keyword |
| 345 // since the last time we synced. Instead, we also run a de-duping pass on | 345 // since the last time we synced. Instead, we also run a de-duping pass on |
| 346 // the server-provided data in | 346 // the server-provided data in |
| 347 // TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData() and | 347 // TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData() and |
| 348 // update the server with the merged, de-duped results at that time. We | 348 // update the server with the merged, de-duped results at that time. We |
| 349 // still fix here, though, to correct problems in clients that have disabled | 349 // still fix here, though, to correct problems in clients that have disabled |
| 350 // search engine sync, since in that case that code will never be reached. | 350 // search engine sync, since in that case that code will never be reached. |
| 351 if (DeDupeEncodings(&i->input_encodings) && service) | 351 if (DeDupeEncodings(&i->input_encodings) && service) |
| 352 service->UpdateKeyword(*i); | 352 service->UpdateKeyword(*i); |
| 353 template_urls->push_back(new TemplateURL(profile, *i)); | 353 template_urls->push_back(new TemplateURL(*i)); |
| 354 } | 354 } |
| 355 | 355 |
| 356 *new_resource_keyword_version = keyword_result.builtin_keyword_version; | 356 *new_resource_keyword_version = keyword_result.builtin_keyword_version; |
| 357 GetSearchProvidersUsingLoadedEngines(service, profile, template_urls, | 357 GetSearchProvidersUsingLoadedEngines(service, profile, template_urls, |
| 358 default_search_provider, | 358 default_search_provider, |
| 359 search_terms_data, | 359 search_terms_data, |
| 360 new_resource_keyword_version, | 360 new_resource_keyword_version, |
| 361 removed_keyword_guids); | 361 removed_keyword_guids); |
| 362 } | 362 } |
| 363 | 363 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 std::vector<std::string> deduped_encodings; | 397 std::vector<std::string> deduped_encodings; |
| 398 std::set<std::string> encoding_set; | 398 std::set<std::string> encoding_set; |
| 399 for (std::vector<std::string>::const_iterator i(encodings->begin()); | 399 for (std::vector<std::string>::const_iterator i(encodings->begin()); |
| 400 i != encodings->end(); ++i) { | 400 i != encodings->end(); ++i) { |
| 401 if (encoding_set.insert(*i).second) | 401 if (encoding_set.insert(*i).second) |
| 402 deduped_encodings.push_back(*i); | 402 deduped_encodings.push_back(*i); |
| 403 } | 403 } |
| 404 encodings->swap(deduped_encodings); | 404 encodings->swap(deduped_encodings); |
| 405 return encodings->size() != deduped_encodings.size(); | 405 return encodings->size() != deduped_encodings.size(); |
| 406 } | 406 } |
| OLD | NEW |