Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/search_engines/util.h" | 5 #include "components/search_engines/util.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | |
| 10 #include <map> | 11 #include <map> |
| 11 #include <set> | 12 #include <set> |
| 12 #include <string> | 13 #include <string> |
| 13 #include <vector> | 14 #include <vector> |
| 14 | 15 |
| 15 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/memory/ptr_util.h" | |
| 16 #include "base/memory/scoped_vector.h" | 18 #include "base/memory/scoped_vector.h" |
| 17 #include "base/time/time.h" | 19 #include "base/time/time.h" |
| 18 #include "components/prefs/pref_service.h" | 20 #include "components/prefs/pref_service.h" |
| 19 #include "components/search_engines/template_url.h" | 21 #include "components/search_engines/template_url.h" |
| 20 #include "components/search_engines/template_url_prepopulate_data.h" | 22 #include "components/search_engines/template_url_prepopulate_data.h" |
| 21 #include "components/search_engines/template_url_service.h" | 23 #include "components/search_engines/template_url_service.h" |
| 22 | 24 |
| 23 base::string16 GetDefaultSearchEngineName(TemplateURLService* service) { | 25 base::string16 GetDefaultSearchEngineName(TemplateURLService* service) { |
| 24 DCHECK(service); | 26 DCHECK(service); |
| 25 const TemplateURL* const default_provider = | 27 const TemplateURL* const default_provider = |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 44 TemplateURLRef::SearchTermsArgs search_terms_args(terms); | 46 TemplateURLRef::SearchTermsArgs search_terms_args(terms); |
| 45 search_terms_args.append_extra_query_params = true; | 47 search_terms_args.append_extra_query_params = true; |
| 46 return GURL(search_url.ReplaceSearchTerms(search_terms_args, | 48 return GURL(search_url.ReplaceSearchTerms(search_terms_args, |
| 47 service->search_terms_data())); | 49 service->search_terms_data())); |
| 48 } | 50 } |
| 49 | 51 |
| 50 void RemoveDuplicatePrepopulateIDs( | 52 void RemoveDuplicatePrepopulateIDs( |
| 51 KeywordWebDataService* service, | 53 KeywordWebDataService* service, |
| 52 const ScopedVector<TemplateURLData>& prepopulated_urls, | 54 const ScopedVector<TemplateURLData>& prepopulated_urls, |
| 53 TemplateURL* default_search_provider, | 55 TemplateURL* default_search_provider, |
| 54 TemplateURLService::TemplateURLVector* template_urls, | 56 TemplateURLService::OwnedTemplateURLVector* template_urls, |
| 55 const SearchTermsData& search_terms_data, | 57 const SearchTermsData& search_terms_data, |
| 56 std::set<std::string>* removed_keyword_guids) { | 58 std::set<std::string>* removed_keyword_guids) { |
| 57 DCHECK(template_urls); | 59 DCHECK(template_urls); |
| 58 | 60 |
| 59 // For convenience construct an ID->TemplateURL* map from |prepopulated_urls|. | 61 // For convenience construct an ID->TemplateURL* map from |prepopulated_urls|. |
| 60 typedef std::map<int, TemplateURLData*> PrepopulatedURLMap; | 62 std::map<int, TemplateURLData*> prepopulated_url_map; |
| 61 PrepopulatedURLMap prepopulated_url_map; | |
| 62 for (std::vector<TemplateURLData*>::const_iterator i( | 63 for (std::vector<TemplateURLData*>::const_iterator i( |
| 63 prepopulated_urls.begin()); | 64 prepopulated_urls.begin()); |
| 64 i != prepopulated_urls.end(); | 65 i != prepopulated_urls.end(); |
| 65 ++i) | 66 ++i) |
| 66 prepopulated_url_map[(*i)->prepopulate_id] = *i; | 67 prepopulated_url_map[(*i)->prepopulate_id] = *i; |
| 67 | 68 |
| 68 // Separate |template_urls| into prepopulated and non-prepopulated groups. | 69 // Separate |template_urls| into prepopulated and non-prepopulated groups. |
| 69 typedef std::multimap<int, TemplateURL*> UncheckedURLMap; | 70 std::multimap<int, std::unique_ptr<TemplateURL>> unchecked_urls; |
| 70 UncheckedURLMap unchecked_urls; | 71 TemplateURLService::OwnedTemplateURLVector checked_urls; |
| 71 TemplateURLService::TemplateURLVector checked_urls; | 72 for (auto& turl : *template_urls) { |
| 72 for (TemplateURLService::TemplateURLVector::iterator i( | |
| 73 template_urls->begin()); i != template_urls->end(); ++i) { | |
| 74 TemplateURL* turl = *i; | |
| 75 int prepopulate_id = turl->prepopulate_id(); | 73 int prepopulate_id = turl->prepopulate_id(); |
| 76 if (prepopulate_id) | 74 if (prepopulate_id) |
| 77 unchecked_urls.insert(std::make_pair(prepopulate_id, turl)); | 75 unchecked_urls.insert(std::make_pair(prepopulate_id, std::move(turl))); |
| 78 else | 76 else |
| 79 checked_urls.push_back(turl); | 77 checked_urls.push_back(std::move(turl)); |
| 80 } | 78 } |
| 81 | 79 |
| 82 // For each group of prepopulated URLs with one ID, find the best URL to use | 80 // For each group of prepopulated URLs with one ID, find the best URL to use |
| 83 // and add it to the (initially all non-prepopulated) URLs we've already OKed. | 81 // and add it to the (initially all non-prepopulated) URLs we've already OKed. |
| 84 // Delete the others from the service and from memory. | 82 // Delete the others from the service and from memory. |
| 85 while (!unchecked_urls.empty()) { | 83 while (!unchecked_urls.empty()) { |
| 86 // Find the best URL. | 84 // Find the best URL. |
| 87 int prepopulate_id = unchecked_urls.begin()->first; | 85 int prepopulate_id = unchecked_urls.begin()->first; |
| 88 PrepopulatedURLMap::const_iterator prepopulated_url = | 86 auto prepopulated_url = prepopulated_url_map.find(prepopulate_id); |
| 89 prepopulated_url_map.find(prepopulate_id); | 87 auto end = unchecked_urls.upper_bound(prepopulate_id); |
| 90 UncheckedURLMap::iterator end = unchecked_urls.upper_bound(prepopulate_id); | 88 auto best = unchecked_urls.begin(); |
| 91 UncheckedURLMap::iterator best = unchecked_urls.begin(); | |
| 92 bool matched_keyword = false; | 89 bool matched_keyword = false; |
| 93 for (UncheckedURLMap::iterator i = unchecked_urls.begin(); i != end; ++i) { | 90 for (auto i = unchecked_urls.begin(); i != end; ++i) { |
| 94 // If the user-selected DSE is a prepopulated engine its properties will | 91 // If the user-selected DSE is a prepopulated engine its properties will |
| 95 // either come from the prepopulation origin or from the user preferences | 92 // either come from the prepopulation origin or from the user preferences |
| 96 // file (see DefaultSearchManager). Those properties will end up | 93 // file (see DefaultSearchManager). Those properties will end up |
| 97 // overwriting whatever we load now anyway. If we are eliminating | 94 // overwriting whatever we load now anyway. If we are eliminating |
| 98 // duplicates, then, we err on the side of keeping the thing that looks | 95 // duplicates, then, we err on the side of keeping the thing that looks |
| 99 // more like the value we will end up with in the end. | 96 // more like the value we will end up with in the end. |
| 100 if (default_search_provider && | 97 if (default_search_provider && |
| 101 (default_search_provider->prepopulate_id() == | 98 (default_search_provider->prepopulate_id() == |
| 102 i->second->prepopulate_id()) && | 99 i->second->prepopulate_id()) && |
| 103 default_search_provider->HasSameKeywordAs(i->second->data(), | 100 default_search_provider->HasSameKeywordAs(i->second->data(), |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 114 i->second->HasSameKeywordAs(*prepopulated_url->second, | 111 i->second->HasSameKeywordAs(*prepopulated_url->second, |
| 115 search_terms_data)) { | 112 search_terms_data)) { |
| 116 best = i; | 113 best = i; |
| 117 matched_keyword = true; | 114 matched_keyword = true; |
| 118 } else if (i->second->id() < best->second->id()) { | 115 } else if (i->second->id() < best->second->id()) { |
| 119 best = i; | 116 best = i; |
| 120 } | 117 } |
| 121 } | 118 } |
| 122 | 119 |
| 123 // Add the best URL to the checked group and delete the rest. | 120 // Add the best URL to the checked group and delete the rest. |
| 124 checked_urls.push_back(best->second); | 121 checked_urls.push_back(std::move(best->second)); |
| 125 for (UncheckedURLMap::iterator i = unchecked_urls.begin(); i != end; ++i) { | 122 for (auto i = unchecked_urls.begin(); i != end; ++i) { |
| 126 if (i == best) | 123 if (i == best) |
| 127 continue; | 124 continue; |
| 128 if (service) { | 125 if (service) { |
| 129 service->RemoveKeyword(i->second->id()); | 126 service->RemoveKeyword(i->second->id()); |
| 130 if (removed_keyword_guids) | 127 if (removed_keyword_guids) |
| 131 removed_keyword_guids->insert(i->second->sync_guid()); | 128 removed_keyword_guids->insert(i->second->sync_guid()); |
| 132 } | 129 } |
| 133 delete i->second; | |
| 134 } | 130 } |
| 135 | 131 |
| 136 // Done with this group. | 132 // Done with this group. |
| 137 unchecked_urls.erase(unchecked_urls.begin(), end); | 133 unchecked_urls.erase(unchecked_urls.begin(), end); |
| 138 } | 134 } |
| 139 | 135 |
| 140 // Return the checked URLs. | 136 // Return the checked URLs. |
| 141 template_urls->swap(checked_urls); | 137 template_urls->swap(checked_urls); |
| 142 } | 138 } |
| 143 | 139 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 ActionsFromPrepopulateData::~ActionsFromPrepopulateData() {} | 184 ActionsFromPrepopulateData::~ActionsFromPrepopulateData() {} |
| 189 | 185 |
| 190 // This is invoked when the version of the prepopulate data changes. | 186 // This is invoked when the version of the prepopulate data changes. |
| 191 // If |removed_keyword_guids| is not NULL, the Sync GUID of each item removed | 187 // If |removed_keyword_guids| is not NULL, the Sync GUID of each item removed |
| 192 // from the DB will be added to it. Note that this function will take | 188 // from the DB will be added to it. Note that this function will take |
| 193 // ownership of |prepopulated_urls| and will clear the vector. | 189 // ownership of |prepopulated_urls| and will clear the vector. |
| 194 void MergeEnginesFromPrepopulateData( | 190 void MergeEnginesFromPrepopulateData( |
| 195 KeywordWebDataService* service, | 191 KeywordWebDataService* service, |
| 196 ScopedVector<TemplateURLData>* prepopulated_urls, | 192 ScopedVector<TemplateURLData>* prepopulated_urls, |
| 197 size_t default_search_index, | 193 size_t default_search_index, |
| 198 TemplateURLService::TemplateURLVector* template_urls, | 194 TemplateURLService::OwnedTemplateURLVector* template_urls, |
| 199 TemplateURL* default_search_provider, | 195 TemplateURL* default_search_provider, |
| 200 std::set<std::string>* removed_keyword_guids) { | 196 std::set<std::string>* removed_keyword_guids) { |
| 201 DCHECK(prepopulated_urls); | 197 DCHECK(prepopulated_urls); |
| 202 DCHECK(template_urls); | 198 DCHECK(template_urls); |
| 203 | 199 |
| 204 ActionsFromPrepopulateData actions(CreateActionsFromCurrentPrepopulateData( | 200 ActionsFromPrepopulateData actions(CreateActionsFromCurrentPrepopulateData( |
| 205 prepopulated_urls, *template_urls, default_search_provider)); | 201 prepopulated_urls, *template_urls, default_search_provider)); |
| 206 | 202 |
| 207 // Remove items. | 203 // Remove items. |
| 208 for (std::vector<TemplateURL*>::iterator i = actions.removed_engines.begin(); | 204 for (auto removed_engine : actions.removed_engines) { |
|
Peter Kasting
2016/08/31 04:12:57
Nit: const auto* (requires FindTemplateURL() signa
Avi (use Gerrit)
2016/09/01 00:34:27
Done.
| |
| 209 i < actions.removed_engines.end(); ++i) { | 205 auto j = FindTemplateURL(template_urls, removed_engine); |
| 210 std::unique_ptr<TemplateURL> template_url(*i); | |
| 211 TemplateURLService::TemplateURLVector::iterator j = std::find( | |
| 212 template_urls->begin(), template_urls->end(), template_url.get()); | |
| 213 DCHECK(j != template_urls->end()); | 206 DCHECK(j != template_urls->end()); |
| 207 std::unique_ptr<TemplateURL> template_url = std::move(*j); | |
| 214 DCHECK(!default_search_provider || | 208 DCHECK(!default_search_provider || |
| 215 (*j)->prepopulate_id() != default_search_provider->prepopulate_id()); | 209 (*j)->prepopulate_id() != default_search_provider->prepopulate_id()); |
| 216 template_urls->erase(j); | 210 template_urls->erase(j); |
| 217 if (service) { | 211 if (service) { |
| 218 service->RemoveKeyword(template_url->id()); | 212 service->RemoveKeyword(template_url->id()); |
| 219 if (removed_keyword_guids) | 213 if (removed_keyword_guids) |
| 220 removed_keyword_guids->insert(template_url->sync_guid()); | 214 removed_keyword_guids->insert(template_url->sync_guid()); |
| 221 } | 215 } |
| 222 } | 216 } |
| 223 | 217 |
| 224 // Edit items. | 218 // Edit items. |
| 225 for (EditedEngines::iterator i(actions.edited_engines.begin()); | 219 for (auto edited_engine : actions.edited_engines) { |
|
Peter Kasting
2016/08/31 04:12:57
Nit: const auto&?
Avi (use Gerrit)
2016/09/01 00:34:27
Done.
| |
| 226 i < actions.edited_engines.end(); ++i) { | 220 TemplateURLData& data = edited_engine.second; |
|
Peter Kasting
2016/08/31 04:12:57
Nit: const TemplateURLData&
Avi (use Gerrit)
2016/09/01 00:34:27
Done.
| |
| 227 TemplateURLData& data = i->second; | |
| 228 std::unique_ptr<TemplateURL> existing_url(i->first); | |
| 229 if (service) | 221 if (service) |
| 230 service->UpdateKeyword(data); | 222 service->UpdateKeyword(data); |
| 231 | 223 |
| 232 // Replace the entry in |template_urls| with the updated one. | 224 // Replace the entry in |template_urls| with the updated one. |
| 233 TemplateURLService::TemplateURLVector::iterator j = std::find( | 225 auto j = FindTemplateURL(template_urls, edited_engine.first); |
| 234 template_urls->begin(), template_urls->end(), existing_url.get()); | 226 *j = base::MakeUnique<TemplateURL>(data); |
| 235 *j = new TemplateURL(data); | |
| 236 } | 227 } |
| 237 | 228 |
| 238 // Add items. | 229 // Add items. |
| 239 for (std::vector<TemplateURLData>::const_iterator it = | 230 for (const auto& added_engine : actions.added_engines) { |
|
Peter Kasting
2016/08/31 04:12:57
Nit: {} unnecessary
Avi (use Gerrit)
2016/09/01 00:34:27
Done.
| |
| 240 actions.added_engines.begin(); | 231 template_urls->push_back(base::MakeUnique<TemplateURL>(added_engine)); |
| 241 it != actions.added_engines.end(); | |
| 242 ++it) { | |
| 243 template_urls->push_back(new TemplateURL(*it)); | |
| 244 } | 232 } |
| 245 } | 233 } |
| 246 | 234 |
| 247 ActionsFromPrepopulateData CreateActionsFromCurrentPrepopulateData( | 235 ActionsFromPrepopulateData CreateActionsFromCurrentPrepopulateData( |
| 248 ScopedVector<TemplateURLData>* prepopulated_urls, | 236 ScopedVector<TemplateURLData>* prepopulated_urls, |
| 249 const TemplateURLService::TemplateURLVector& existing_urls, | 237 const TemplateURLService::OwnedTemplateURLVector& existing_urls, |
| 250 const TemplateURL* default_search_provider) { | 238 const TemplateURL* default_search_provider) { |
| 251 // Create a map to hold all provided |template_urls| that originally came from | 239 // Create a map to hold all provided |template_urls| that originally came from |
| 252 // prepopulate data (i.e. have a non-zero prepopulate_id()). | 240 // prepopulate data (i.e. have a non-zero prepopulate_id()). |
| 253 typedef std::map<int, TemplateURL*> IDMap; | 241 typedef std::map<int, TemplateURL*> IDMap; |
| 254 IDMap id_to_turl; | 242 IDMap id_to_turl; |
| 255 for (TemplateURLService::TemplateURLVector::const_iterator i( | 243 for (auto& turl : existing_urls) { |
| 256 existing_urls.begin()); i != existing_urls.end(); ++i) { | 244 int prepopulate_id = turl->prepopulate_id(); |
| 257 int prepopulate_id = (*i)->prepopulate_id(); | |
| 258 if (prepopulate_id > 0) | 245 if (prepopulate_id > 0) |
| 259 id_to_turl[prepopulate_id] = *i; | 246 id_to_turl[prepopulate_id] = turl.get(); |
| 260 } | 247 } |
| 261 | 248 |
| 262 // For each current prepopulated URL, check whether |template_urls| contained | 249 // For each current prepopulated URL, check whether |template_urls| contained |
| 263 // a matching prepopulated URL. If so, update the passed-in URL to match the | 250 // a matching prepopulated URL. If so, update the passed-in URL to match the |
| 264 // current data. (If the passed-in URL was user-edited, we persist the user's | 251 // current data. (If the passed-in URL was user-edited, we persist the user's |
| 265 // name and keyword.) If not, add the prepopulated URL. | 252 // name and keyword.) If not, add the prepopulated URL. |
| 266 ActionsFromPrepopulateData actions; | 253 ActionsFromPrepopulateData actions; |
| 267 for (size_t i = 0; i < prepopulated_urls->size(); ++i) { | 254 for (size_t i = 0; i < prepopulated_urls->size(); ++i) { |
| 268 // We take ownership of |prepopulated_urls[i]|. | 255 // We take ownership of |prepopulated_urls[i]|. |
| 269 std::unique_ptr<TemplateURLData> prepopulated_url((*prepopulated_urls)[i]); | 256 std::unique_ptr<TemplateURLData> prepopulated_url((*prepopulated_urls)[i]); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 308 actions.removed_engines.push_back(template_url); | 295 actions.removed_engines.push_back(template_url); |
| 309 } | 296 } |
| 310 | 297 |
| 311 return actions; | 298 return actions; |
| 312 } | 299 } |
| 313 | 300 |
| 314 void GetSearchProvidersUsingKeywordResult( | 301 void GetSearchProvidersUsingKeywordResult( |
| 315 const WDTypedResult& result, | 302 const WDTypedResult& result, |
| 316 KeywordWebDataService* service, | 303 KeywordWebDataService* service, |
| 317 PrefService* prefs, | 304 PrefService* prefs, |
| 318 TemplateURLService::TemplateURLVector* template_urls, | 305 TemplateURLService::OwnedTemplateURLVector* template_urls, |
| 319 TemplateURL* default_search_provider, | 306 TemplateURL* default_search_provider, |
| 320 const SearchTermsData& search_terms_data, | 307 const SearchTermsData& search_terms_data, |
| 321 int* new_resource_keyword_version, | 308 int* new_resource_keyword_version, |
| 322 std::set<std::string>* removed_keyword_guids) { | 309 std::set<std::string>* removed_keyword_guids) { |
| 323 DCHECK(template_urls); | 310 DCHECK(template_urls); |
| 324 DCHECK(template_urls->empty()); | 311 DCHECK(template_urls->empty()); |
| 325 DCHECK_EQ(KEYWORDS_RESULT, result.GetType()); | 312 DCHECK_EQ(KEYWORDS_RESULT, result.GetType()); |
| 326 DCHECK(new_resource_keyword_version); | 313 DCHECK(new_resource_keyword_version); |
| 327 | 314 |
| 328 WDKeywordsResult keyword_result = reinterpret_cast< | 315 WDKeywordsResult keyword_result = reinterpret_cast< |
| 329 const WDResult<WDKeywordsResult>*>(&result)->GetValue(); | 316 const WDResult<WDKeywordsResult>*>(&result)->GetValue(); |
| 330 | 317 |
| 331 for (KeywordTable::Keywords::iterator i(keyword_result.keywords.begin()); | 318 for (auto& keyword : keyword_result.keywords) { |
| 332 i != keyword_result.keywords.end(); ++i) { | |
| 333 // Fix any duplicate encodings in the local database. Note that we don't | 319 // Fix any duplicate encodings in the local database. Note that we don't |
| 334 // adjust the last_modified time of this keyword; this way, we won't later | 320 // adjust the last_modified time of this keyword; this way, we won't later |
| 335 // overwrite any changes on the sync server that happened to this keyword | 321 // overwrite any changes on the sync server that happened to this keyword |
| 336 // since the last time we synced. Instead, we also run a de-duping pass on | 322 // since the last time we synced. Instead, we also run a de-duping pass on |
| 337 // the server-provided data in | 323 // the server-provided data in |
| 338 // TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData() and | 324 // TemplateURLService::CreateTemplateURLFromTemplateURLAndSyncData() and |
| 339 // update the server with the merged, de-duped results at that time. We | 325 // update the server with the merged, de-duped results at that time. We |
| 340 // still fix here, though, to correct problems in clients that have disabled | 326 // still fix here, though, to correct problems in clients that have disabled |
| 341 // search engine sync, since in that case that code will never be reached. | 327 // search engine sync, since in that case that code will never be reached. |
| 342 if (DeDupeEncodings(&i->input_encodings) && service) | 328 if (DeDupeEncodings(&keyword.input_encodings) && service) |
| 343 service->UpdateKeyword(*i); | 329 service->UpdateKeyword(keyword); |
| 344 template_urls->push_back(new TemplateURL(*i)); | 330 template_urls->push_back(base::MakeUnique<TemplateURL>(keyword)); |
| 345 } | 331 } |
| 346 | 332 |
| 347 *new_resource_keyword_version = keyword_result.builtin_keyword_version; | 333 *new_resource_keyword_version = keyword_result.builtin_keyword_version; |
| 348 GetSearchProvidersUsingLoadedEngines(service, prefs, template_urls, | 334 GetSearchProvidersUsingLoadedEngines(service, prefs, template_urls, |
| 349 default_search_provider, | 335 default_search_provider, |
| 350 search_terms_data, | 336 search_terms_data, |
| 351 new_resource_keyword_version, | 337 new_resource_keyword_version, |
| 352 removed_keyword_guids); | 338 removed_keyword_guids); |
| 353 } | 339 } |
| 354 | 340 |
| 355 void GetSearchProvidersUsingLoadedEngines( | 341 void GetSearchProvidersUsingLoadedEngines( |
| 356 KeywordWebDataService* service, | 342 KeywordWebDataService* service, |
| 357 PrefService* prefs, | 343 PrefService* prefs, |
| 358 TemplateURLService::TemplateURLVector* template_urls, | 344 TemplateURLService::OwnedTemplateURLVector* template_urls, |
| 359 TemplateURL* default_search_provider, | 345 TemplateURL* default_search_provider, |
| 360 const SearchTermsData& search_terms_data, | 346 const SearchTermsData& search_terms_data, |
| 361 int* resource_keyword_version, | 347 int* resource_keyword_version, |
| 362 std::set<std::string>* removed_keyword_guids) { | 348 std::set<std::string>* removed_keyword_guids) { |
| 363 DCHECK(template_urls); | 349 DCHECK(template_urls); |
| 364 DCHECK(resource_keyword_version); | 350 DCHECK(resource_keyword_version); |
| 365 size_t default_search_index; | 351 size_t default_search_index; |
| 366 ScopedVector<TemplateURLData> prepopulated_urls = | 352 ScopedVector<TemplateURLData> prepopulated_urls = |
| 367 TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, | 353 TemplateURLPrepopulateData::GetPrepopulatedEngines(prefs, |
| 368 &default_search_index); | 354 &default_search_index); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 386 std::vector<std::string> deduped_encodings; | 372 std::vector<std::string> deduped_encodings; |
| 387 std::set<std::string> encoding_set; | 373 std::set<std::string> encoding_set; |
| 388 for (std::vector<std::string>::const_iterator i(encodings->begin()); | 374 for (std::vector<std::string>::const_iterator i(encodings->begin()); |
| 389 i != encodings->end(); ++i) { | 375 i != encodings->end(); ++i) { |
| 390 if (encoding_set.insert(*i).second) | 376 if (encoding_set.insert(*i).second) |
| 391 deduped_encodings.push_back(*i); | 377 deduped_encodings.push_back(*i); |
| 392 } | 378 } |
| 393 encodings->swap(deduped_encodings); | 379 encodings->swap(deduped_encodings); |
| 394 return encodings->size() != deduped_encodings.size(); | 380 return encodings->size() != deduped_encodings.size(); |
| 395 } | 381 } |
| 382 | |
| 383 TemplateURLService::OwnedTemplateURLVector::iterator FindTemplateURL( | |
| 384 TemplateURLService::OwnedTemplateURLVector* urls, | |
| 385 TemplateURL* url) { | |
|
Peter Kasting
2016/08/31 04:12:57
Nit: const TemplateURL*
Avi (use Gerrit)
2016/09/01 00:34:28
Done.
| |
| 386 return std::find_if(urls->begin(), urls->end(), | |
| 387 [url](const std::unique_ptr<TemplateURL>& ptr) { | |
| 388 return ptr.get() == url; | |
| 389 }); | |
| 390 } | |
| OLD | NEW |