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/importer/profile_writer.h" | 5 #include "chrome/browser/importer/profile_writer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 // those shown in the default list. If there are multiple potential | 308 // those shown in the default list. If there are multiple potential |
309 // defaults, favor the first one, which should be the more commonly used | 309 // defaults, favor the first one, which should be the more commonly used |
310 // one. | 310 // one. |
311 (*host_path_map)[host_path] = template_urls[i]; | 311 (*host_path_map)[host_path] = template_urls[i]; |
312 } | 312 } |
313 } // else case, TemplateURL doesn't have a search url, doesn't support | 313 } // else case, TemplateURL doesn't have a search url, doesn't support |
314 // replacement, or doesn't have valid GURL. Ignore it. | 314 // replacement, or doesn't have valid GURL. Ignore it. |
315 } | 315 } |
316 } | 316 } |
317 | 317 |
318 void ProfileWriter::AddKeywords(ScopedVector<TemplateURL> template_urls, | 318 void ProfileWriter::AddKeywords( |
319 bool unique_on_host_and_path) { | 319 TemplateURLService::OwnedTemplateURLVector template_urls, |
| 320 bool unique_on_host_and_path) { |
320 TemplateURLService* model = | 321 TemplateURLService* model = |
321 TemplateURLServiceFactory::GetForProfile(profile_); | 322 TemplateURLServiceFactory::GetForProfile(profile_); |
322 HostPathMap host_path_map; | 323 HostPathMap host_path_map; |
323 if (unique_on_host_and_path) | 324 if (unique_on_host_and_path) |
324 BuildHostPathMap(model, &host_path_map); | 325 BuildHostPathMap(model, &host_path_map); |
325 | 326 |
326 for (ScopedVector<TemplateURL>::iterator i = template_urls.begin(); | 327 for (auto& turl : template_urls) { |
327 i != template_urls.end(); ++i) { | |
328 // TemplateURLService requires keywords to be unique. If there is already a | 328 // TemplateURLService requires keywords to be unique. If there is already a |
329 // TemplateURL with this keyword, don't import it again. | 329 // TemplateURL with this keyword, don't import it again. |
330 if (model->GetTemplateURLForKeyword((*i)->keyword()) != nullptr) | 330 if (model->GetTemplateURLForKeyword(turl->keyword()) != nullptr) |
331 continue; | 331 continue; |
332 | 332 |
333 // For search engines if there is already a keyword with the same | 333 // For search engines if there is already a keyword with the same |
334 // host+path, we don't import it. This is done to avoid both duplicate | 334 // host+path, we don't import it. This is done to avoid both duplicate |
335 // search providers (such as two Googles, or two Yahoos) as well as making | 335 // search providers (such as two Googles, or two Yahoos) as well as making |
336 // sure the search engines we provide aren't replaced by those from the | 336 // sure the search engines we provide aren't replaced by those from the |
337 // imported browser. | 337 // imported browser. |
338 if (unique_on_host_and_path && | 338 if (unique_on_host_and_path && (host_path_map.find(BuildHostPathKey( |
339 (host_path_map.find(BuildHostPathKey( | 339 turl.get(), model->search_terms_data(), |
340 *i, model->search_terms_data(), true)) != host_path_map.end())) | 340 true)) != host_path_map.end())) |
341 continue; | 341 continue; |
342 | 342 |
343 // Only add valid TemplateURLs to the model. | 343 // Only add valid TemplateURLs to the model. |
344 if ((*i)->url_ref().IsValid(model->search_terms_data())) { | 344 if (turl->url_ref().IsValid(model->search_terms_data())) |
345 model->Add(base::WrapUnique(*i)); | 345 model->Add(std::move(turl)); |
346 *i = nullptr; // Prevent the vector from deleting *i later. | |
347 } | |
348 } | 346 } |
349 } | 347 } |
350 | 348 |
351 void ProfileWriter::AddAutofillFormDataEntries( | 349 void ProfileWriter::AddAutofillFormDataEntries( |
352 const std::vector<autofill::AutofillEntry>& autofill_entries) { | 350 const std::vector<autofill::AutofillEntry>& autofill_entries) { |
353 scoped_refptr<autofill::AutofillWebDataService> web_data_service = | 351 scoped_refptr<autofill::AutofillWebDataService> web_data_service = |
354 WebDataServiceFactory::GetAutofillWebDataForProfile( | 352 WebDataServiceFactory::GetAutofillWebDataForProfile( |
355 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 353 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
356 if (web_data_service.get()) | 354 if (web_data_service.get()) |
357 web_data_service->UpdateAutofillEntries(autofill_entries); | 355 web_data_service->UpdateAutofillEntries(autofill_entries); |
358 } | 356 } |
359 | 357 |
360 ProfileWriter::~ProfileWriter() {} | 358 ProfileWriter::~ProfileWriter() {} |
OLD | NEW |