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> |
11 #include <string> | 11 #include <string> |
12 | 12 |
| 13 #include "base/memory/ptr_util.h" |
13 #include "base/metrics/histogram_macros.h" | 14 #include "base/metrics/histogram_macros.h" |
14 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
17 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "chrome/browser/bookmarks/bookmark_model_factory.h" | 20 #include "chrome/browser/bookmarks/bookmark_model_factory.h" |
20 #include "chrome/browser/chrome_notification_types.h" | 21 #include "chrome/browser/chrome_notification_types.h" |
21 #include "chrome/browser/favicon/favicon_service_factory.h" | 22 #include "chrome/browser/favicon/favicon_service_factory.h" |
22 #include "chrome/browser/first_run/first_run.h" | 23 #include "chrome/browser/first_run/first_run.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 TemplateURLService* model = | 320 TemplateURLService* model = |
320 TemplateURLServiceFactory::GetForProfile(profile_); | 321 TemplateURLServiceFactory::GetForProfile(profile_); |
321 HostPathMap host_path_map; | 322 HostPathMap host_path_map; |
322 if (unique_on_host_and_path) | 323 if (unique_on_host_and_path) |
323 BuildHostPathMap(model, &host_path_map); | 324 BuildHostPathMap(model, &host_path_map); |
324 | 325 |
325 for (ScopedVector<TemplateURL>::iterator i = template_urls.begin(); | 326 for (ScopedVector<TemplateURL>::iterator i = template_urls.begin(); |
326 i != template_urls.end(); ++i) { | 327 i != template_urls.end(); ++i) { |
327 // TemplateURLService requires keywords to be unique. If there is already a | 328 // TemplateURLService requires keywords to be unique. If there is already a |
328 // TemplateURL with this keyword, don't import it again. | 329 // TemplateURL with this keyword, don't import it again. |
329 if (model->GetTemplateURLForKeyword((*i)->keyword()) != NULL) | 330 if (model->GetTemplateURLForKeyword((*i)->keyword()) != nullptr) |
330 continue; | 331 continue; |
331 | 332 |
332 // 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 |
333 // 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 |
334 // 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 |
335 // 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 |
336 // imported browser. | 337 // imported browser. |
337 if (unique_on_host_and_path && | 338 if (unique_on_host_and_path && |
338 (host_path_map.find(BuildHostPathKey( | 339 (host_path_map.find(BuildHostPathKey( |
339 *i, model->search_terms_data(), true)) != host_path_map.end())) | 340 *i, model->search_terms_data(), true)) != host_path_map.end())) |
340 continue; | 341 continue; |
341 | 342 |
342 // Only add valid TemplateURLs to the model. | 343 // Only add valid TemplateURLs to the model. |
343 if ((*i)->url_ref().IsValid(model->search_terms_data())) { | 344 if ((*i)->url_ref().IsValid(model->search_terms_data())) { |
344 model->Add(*i); // Takes ownership. | 345 model->Add(base::WrapUnique(*i)); |
345 *i = NULL; // Prevent the vector from deleting *i later. | 346 *i = nullptr; // Prevent the vector from deleting *i later. |
346 } | 347 } |
347 } | 348 } |
348 } | 349 } |
349 | 350 |
350 void ProfileWriter::AddAutofillFormDataEntries( | 351 void ProfileWriter::AddAutofillFormDataEntries( |
351 const std::vector<autofill::AutofillEntry>& autofill_entries) { | 352 const std::vector<autofill::AutofillEntry>& autofill_entries) { |
352 scoped_refptr<autofill::AutofillWebDataService> web_data_service = | 353 scoped_refptr<autofill::AutofillWebDataService> web_data_service = |
353 WebDataServiceFactory::GetAutofillWebDataForProfile( | 354 WebDataServiceFactory::GetAutofillWebDataForProfile( |
354 profile_, ServiceAccessType::EXPLICIT_ACCESS); | 355 profile_, ServiceAccessType::EXPLICIT_ACCESS); |
355 if (web_data_service.get()) | 356 if (web_data_service.get()) |
356 web_data_service->UpdateAutofillEntries(autofill_entries); | 357 web_data_service->UpdateAutofillEntries(autofill_entries); |
357 } | 358 } |
358 | 359 |
359 ProfileWriter::~ProfileWriter() {} | 360 ProfileWriter::~ProfileWriter() {} |
OLD | NEW |