| 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/in_process_importer_bridge.h" | 5 #include "chrome/browser/importer/in_process_importer_bridge.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 | 163 |
| 164 InProcessImporterBridge::InProcessImporterBridge( | 164 InProcessImporterBridge::InProcessImporterBridge( |
| 165 ProfileWriter* writer, | 165 ProfileWriter* writer, |
| 166 base::WeakPtr<ExternalProcessImporterHost> host) : writer_(writer), | 166 base::WeakPtr<ExternalProcessImporterHost> host) : writer_(writer), |
| 167 host_(host) { | 167 host_(host) { |
| 168 } | 168 } |
| 169 | 169 |
| 170 void InProcessImporterBridge::AddBookmarks( | 170 void InProcessImporterBridge::AddBookmarks( |
| 171 const std::vector<ImportedBookmarkEntry>& bookmarks, | 171 const std::vector<ImportedBookmarkEntry>& bookmarks, |
| 172 const base::string16& first_folder_name) { | 172 const base::string16& first_folder_name) { |
| 173 BrowserThread::PostTask( | 173 writer_->AddBookmarks(bookmarks, first_folder_name); |
| 174 BrowserThread::UI, FROM_HERE, | |
| 175 base::Bind(&ProfileWriter::AddBookmarks, writer_, bookmarks, | |
| 176 first_folder_name)); | |
| 177 } | 174 } |
| 178 | 175 |
| 179 void InProcessImporterBridge::AddHomePage(const GURL& home_page) { | 176 void InProcessImporterBridge::AddHomePage(const GURL& home_page) { |
| 180 BrowserThread::PostTask( | 177 writer_->AddHomepage(home_page); |
| 181 BrowserThread::UI, FROM_HERE, | |
| 182 base::Bind(&ProfileWriter::AddHomepage, writer_, home_page)); | |
| 183 } | 178 } |
| 184 | 179 |
| 185 #if defined(OS_WIN) | 180 #if defined(OS_WIN) |
| 186 void InProcessImporterBridge::AddIE7PasswordInfo( | 181 void InProcessImporterBridge::AddIE7PasswordInfo( |
| 187 const importer::ImporterIE7PasswordInfo& password_info) { | 182 const importer::ImporterIE7PasswordInfo& password_info) { |
| 188 IE7PasswordInfo ie7_password_info; | 183 IE7PasswordInfo ie7_password_info; |
| 189 ie7_password_info.url_hash = password_info.url_hash; | 184 ie7_password_info.url_hash = password_info.url_hash; |
| 190 ie7_password_info.encrypted_data = password_info.encrypted_data; | 185 ie7_password_info.encrypted_data = password_info.encrypted_data; |
| 191 ie7_password_info.date_created = password_info.date_created; | 186 ie7_password_info.date_created = password_info.date_created; |
| 192 | 187 |
| 193 BrowserThread::PostTask( | 188 writer_->AddIE7PasswordInfo(ie7_password_info); |
| 194 BrowserThread::UI, FROM_HERE, | |
| 195 base::Bind(&ProfileWriter::AddIE7PasswordInfo, writer_, | |
| 196 ie7_password_info)); | |
| 197 } | 189 } |
| 198 #endif // OS_WIN | 190 #endif // OS_WIN |
| 199 | 191 |
| 200 void InProcessImporterBridge::SetFavicons( | 192 void InProcessImporterBridge::SetFavicons( |
| 201 const favicon_base::FaviconUsageDataList& favicons) { | 193 const favicon_base::FaviconUsageDataList& favicons) { |
| 202 BrowserThread::PostTask( | 194 writer_->AddFavicons(favicons); |
| 203 BrowserThread::UI, FROM_HERE, | |
| 204 base::Bind(&ProfileWriter::AddFavicons, writer_, favicons)); | |
| 205 } | 195 } |
| 206 | 196 |
| 207 void InProcessImporterBridge::SetHistoryItems( | 197 void InProcessImporterBridge::SetHistoryItems( |
| 208 const std::vector<ImporterURLRow>& rows, | 198 const std::vector<ImporterURLRow>& rows, |
| 209 importer::VisitSource visit_source) { | 199 importer::VisitSource visit_source) { |
| 210 history::URLRows converted_rows = | 200 history::URLRows converted_rows = |
| 211 ConvertImporterURLRowsToHistoryURLRows(rows); | 201 ConvertImporterURLRowsToHistoryURLRows(rows); |
| 212 history::VisitSource converted_visit_source = | 202 history::VisitSource converted_visit_source = |
| 213 ConvertImporterVisitSourceToHistoryVisitSource(visit_source); | 203 ConvertImporterVisitSourceToHistoryVisitSource(visit_source); |
| 214 BrowserThread::PostTask(BrowserThread::UI, | 204 writer_->AddHistoryPage(converted_rows, converted_visit_source); |
| 215 FROM_HERE, | |
| 216 base::Bind(&ProfileWriter::AddHistoryPage, | |
| 217 writer_, | |
| 218 converted_rows, | |
| 219 converted_visit_source)); | |
| 220 } | 205 } |
| 221 | 206 |
| 222 void InProcessImporterBridge::SetKeywords( | 207 void InProcessImporterBridge::SetKeywords( |
| 223 const std::vector<importer::SearchEngineInfo>& search_engines, | 208 const std::vector<importer::SearchEngineInfo>& search_engines, |
| 224 bool unique_on_host_and_path) { | 209 bool unique_on_host_and_path) { |
| 225 TemplateURLService::OwnedTemplateURLVector owned_template_urls; | 210 TemplateURLService::OwnedTemplateURLVector owned_template_urls; |
| 226 for (const auto& search_engine : search_engines) { | 211 for (const auto& search_engine : search_engines) { |
| 227 std::unique_ptr<TemplateURL> owned_template_url = CreateTemplateURL( | 212 std::unique_ptr<TemplateURL> owned_template_url = CreateTemplateURL( |
| 228 search_engine.url, search_engine.keyword, search_engine.display_name); | 213 search_engine.url, search_engine.keyword, search_engine.display_name); |
| 229 if (owned_template_url) | 214 if (owned_template_url) |
| 230 owned_template_urls.push_back(std::move(owned_template_url)); | 215 owned_template_urls.push_back(std::move(owned_template_url)); |
| 231 } | 216 } |
| 232 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 217 writer_->AddKeywords(std::move(owned_template_urls), unique_on_host_and_path); |
| 233 base::Bind(&ProfileWriter::AddKeywords, writer_, | |
| 234 base::Passed(&owned_template_urls), unique_on_host_and_path)); | |
| 235 } | 218 } |
| 236 | 219 |
| 237 void InProcessImporterBridge::SetFirefoxSearchEnginesXMLData( | 220 void InProcessImporterBridge::SetFirefoxSearchEnginesXMLData( |
| 238 const std::vector<std::string>& search_engine_data) { | 221 const std::vector<std::string>& search_engine_data) { |
| 239 TemplateURLService::OwnedTemplateURLVector search_engines; | 222 TemplateURLService::OwnedTemplateURLVector search_engines; |
| 240 ParseSearchEnginesFromFirefoxXMLData(search_engine_data, &search_engines); | 223 ParseSearchEnginesFromFirefoxXMLData(search_engine_data, &search_engines); |
| 241 | 224 |
| 242 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 225 writer_->AddKeywords(std::move(search_engines), true); |
| 243 base::Bind(&ProfileWriter::AddKeywords, writer_, | |
| 244 base::Passed(&search_engines), true)); | |
| 245 } | 226 } |
| 246 | 227 |
| 247 void InProcessImporterBridge::SetPasswordForm( | 228 void InProcessImporterBridge::SetPasswordForm( |
| 248 const autofill::PasswordForm& form) { | 229 const autofill::PasswordForm& form) { |
| 249 BrowserThread::PostTask( | 230 writer_->AddPasswordForm(form); |
| 250 BrowserThread::UI, FROM_HERE, | |
| 251 base::Bind(&ProfileWriter::AddPasswordForm, writer_, form)); | |
| 252 } | 231 } |
| 253 | 232 |
| 254 void InProcessImporterBridge::SetAutofillFormData( | 233 void InProcessImporterBridge::SetAutofillFormData( |
| 255 const std::vector<ImporterAutofillFormDataEntry>& entries) { | 234 const std::vector<ImporterAutofillFormDataEntry>& entries) { |
| 256 std::vector<autofill::AutofillEntry> autofill_entries; | 235 std::vector<autofill::AutofillEntry> autofill_entries; |
| 257 for (size_t i = 0; i < entries.size(); ++i) { | 236 for (size_t i = 0; i < entries.size(); ++i) { |
| 258 autofill_entries.push_back(autofill::AutofillEntry( | 237 autofill_entries.push_back(autofill::AutofillEntry( |
| 259 autofill::AutofillKey(entries[i].name, entries[i].value), | 238 autofill::AutofillKey(entries[i].name, entries[i].value), |
| 260 entries[i].first_used, | 239 entries[i].first_used, |
| 261 entries[i].last_used)); | 240 entries[i].last_used)); |
| 262 } | 241 } |
| 263 | 242 |
| 264 BrowserThread::PostTask(BrowserThread::UI, | 243 writer_->AddAutofillFormDataEntries(autofill_entries); |
| 265 FROM_HERE, | |
| 266 base::Bind(&ProfileWriter::AddAutofillFormDataEntries, | |
| 267 writer_, | |
| 268 autofill_entries)); | |
| 269 } | 244 } |
| 270 | 245 |
| 271 void InProcessImporterBridge::NotifyStarted() { | 246 void InProcessImporterBridge::NotifyStarted() { |
| 272 BrowserThread::PostTask( | 247 host_->NotifyImportStarted(); |
| 273 BrowserThread::UI, FROM_HERE, | |
| 274 base::Bind(&ExternalProcessImporterHost::NotifyImportStarted, host_)); | |
| 275 } | 248 } |
| 276 | 249 |
| 277 void InProcessImporterBridge::NotifyItemStarted(importer::ImportItem item) { | 250 void InProcessImporterBridge::NotifyItemStarted(importer::ImportItem item) { |
| 278 BrowserThread::PostTask( | 251 host_->NotifyImportItemStarted(item); |
| 279 BrowserThread::UI, FROM_HERE, | |
| 280 base::Bind(&ExternalProcessImporterHost::NotifyImportItemStarted, | |
| 281 host_, item)); | |
| 282 } | 252 } |
| 283 | 253 |
| 284 void InProcessImporterBridge::NotifyItemEnded(importer::ImportItem item) { | 254 void InProcessImporterBridge::NotifyItemEnded(importer::ImportItem item) { |
| 285 BrowserThread::PostTask( | 255 host_->NotifyImportItemEnded(item); |
| 286 BrowserThread::UI, FROM_HERE, | |
| 287 base::Bind(&ExternalProcessImporterHost::NotifyImportItemEnded, | |
| 288 host_, item)); | |
| 289 } | 256 } |
| 290 | 257 |
| 291 void InProcessImporterBridge::NotifyEnded() { | 258 void InProcessImporterBridge::NotifyEnded() { |
| 292 BrowserThread::PostTask( | 259 host_->NotifyImportEnded(); |
| 293 BrowserThread::UI, FROM_HERE, | |
| 294 base::Bind(&ExternalProcessImporterHost::NotifyImportEnded, host_)); | |
| 295 } | 260 } |
| 296 | 261 |
| 297 base::string16 InProcessImporterBridge::GetLocalizedString(int message_id) { | 262 base::string16 InProcessImporterBridge::GetLocalizedString(int message_id) { |
| 298 return l10n_util::GetStringUTF16(message_id); | 263 return l10n_util::GetStringUTF16(message_id); |
| 299 } | 264 } |
| 300 | 265 |
| 301 InProcessImporterBridge::~InProcessImporterBridge() {} | 266 InProcessImporterBridge::~InProcessImporterBridge() {} |
| OLD | NEW |