Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ui/webui/settings/settings_import_data_handler.h" | 5 #include "chrome/browser/ui/webui/settings/settings_import_data_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
| 19 #include "base/threading/thread_restrictions.h" | 19 #include "base/threading/thread_restrictions.h" |
| 20 #include "base/values.h" | 20 #include "base/values.h" |
| 21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
| 22 #include "chrome/browser/importer/external_process_importer_host.h" | 22 #include "chrome/browser/importer/external_process_importer_host.h" |
| 23 #include "chrome/browser/importer/importer_list.h" | 23 #include "chrome/browser/importer/importer_list.h" |
| 24 #include "chrome/browser/importer/importer_uma.h" | 24 #include "chrome/browser/importer/importer_uma.h" |
| 25 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 26 #include "chrome/browser/ui/browser_finder.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
| 27 #include "chrome/browser/ui/browser_window.h" | 27 #include "chrome/browser/ui/browser_window.h" |
| 28 #include "chrome/browser/ui/chrome_select_file_policy.h" | 28 #include "chrome/browser/ui/chrome_select_file_policy.h" |
| 29 #include "chrome/common/pref_names.h" | |
| 29 #include "chrome/grit/chromium_strings.h" | 30 #include "chrome/grit/chromium_strings.h" |
| 30 #include "chrome/grit/generated_resources.h" | 31 #include "chrome/grit/generated_resources.h" |
| 31 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 32 #include "content/public/browser/web_ui.h" | 33 #include "content/public/browser/web_ui.h" |
| 33 | 34 |
| 34 using content::BrowserThread; | 35 using content::BrowserThread; |
| 35 | 36 |
| 36 namespace settings { | 37 namespace settings { |
| 37 | 38 |
| 38 namespace { | 39 namespace { |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 104 imported_items, | 105 imported_items, |
| 105 new ProfileWriter(profile)); | 106 new ProfileWriter(profile)); |
| 106 | 107 |
| 107 importer::LogImporterUseToMetrics("ImportDataHandler", | 108 importer::LogImporterUseToMetrics("ImportDataHandler", |
| 108 source_profile.importer_type); | 109 source_profile.importer_type); |
| 109 } | 110 } |
| 110 | 111 |
| 111 void ImportDataHandler::ImportData(const base::ListValue* args) { | 112 void ImportDataHandler::ImportData(const base::ListValue* args) { |
| 112 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 113 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 113 | 114 |
| 114 std::string string_value; | 115 int browser_index; |
| 116 CHECK(args->GetInteger(0, &browser_index)); | |
| 115 | 117 |
| 116 int browser_index; | 118 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); |
| 117 if (!args->GetString(0, &string_value) || | |
| 118 !base::StringToInt(string_value, &browser_index)) { | |
| 119 NOTREACHED(); | |
| 120 return; | |
| 121 } | |
| 122 | 119 |
| 123 uint16_t selected_items = importer::NONE; | 120 uint16_t selected_items = importer::NONE; |
| 124 if (args->GetString(1, &string_value) && string_value == "true") { | 121 if (prefs->GetBoolean(prefs::kImportAutofillFormData)) |
| 122 selected_items |= importer::AUTOFILL_FORM_DATA; | |
| 123 if (prefs->GetBoolean(prefs::kImportBookmarks)) | |
| 124 selected_items |= importer::FAVORITES; | |
| 125 if (prefs->GetBoolean(prefs::kImportHistory)) | |
| 125 selected_items |= importer::HISTORY; | 126 selected_items |= importer::HISTORY; |
| 126 } | 127 if (prefs->GetBoolean(prefs::kImportSavedPasswords)) |
| 127 if (args->GetString(2, &string_value) && string_value == "true") { | |
| 128 selected_items |= importer::FAVORITES; | |
| 129 } | |
| 130 if (args->GetString(3, &string_value) && string_value == "true") { | |
| 131 selected_items |= importer::PASSWORDS; | 128 selected_items |= importer::PASSWORDS; |
| 132 } | 129 if (prefs->GetBoolean(prefs::kImportSearchEngine)) |
|
tommycli
2016/11/16 17:23:53
^ nice...
dpapad
2016/11/16 21:33:02
Thanks!
| |
| 133 if (args->GetString(4, &string_value) && string_value == "true") { | |
| 134 selected_items |= importer::SEARCH_ENGINES; | 130 selected_items |= importer::SEARCH_ENGINES; |
| 135 } | |
| 136 if (args->GetString(5, &string_value) && string_value == "true") { | |
| 137 selected_items |= importer::AUTOFILL_FORM_DATA; | |
| 138 } | |
| 139 | 131 |
| 140 const importer::SourceProfile& source_profile = | 132 const importer::SourceProfile& source_profile = |
| 141 importer_list_->GetSourceProfileAt(browser_index); | 133 importer_list_->GetSourceProfileAt(browser_index); |
| 142 uint16_t supported_items = source_profile.services_supported; | 134 uint16_t supported_items = source_profile.services_supported; |
| 143 | 135 |
| 144 uint16_t imported_items = (selected_items & supported_items); | 136 uint16_t imported_items = (selected_items & supported_items); |
| 145 if (imported_items) { | 137 if (imported_items) { |
| 146 StartImport(source_profile, imported_items); | 138 StartImport(source_profile, imported_items); |
| 147 } else { | 139 } else { |
| 148 LOG(WARNING) << "There were no settings to import from '" | 140 LOG(WARNING) << "There were no settings to import from '" |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 base::string16(), | 248 base::string16(), |
| 257 base::FilePath(), | 249 base::FilePath(), |
| 258 &file_type_info, | 250 &file_type_info, |
| 259 0, | 251 0, |
| 260 base::FilePath::StringType(), | 252 base::FilePath::StringType(), |
| 261 browser->window()->GetNativeWindow(), | 253 browser->window()->GetNativeWindow(), |
| 262 NULL); | 254 NULL); |
| 263 } | 255 } |
| 264 | 256 |
| 265 } // namespace settings | 257 } // namespace settings |
| OLD | NEW |