| 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/external_process_importer_client.h" | 5 #include "chrome/browser/importer/external_process_importer_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/importer/external_process_importer_host.h" | 10 #include "chrome/browser/importer/external_process_importer_host.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 total_history_rows_count_(0), | 31 total_history_rows_count_(0), |
| 32 total_favicons_count_(0), | 32 total_favicons_count_(0), |
| 33 process_importer_host_(importer_host), | 33 process_importer_host_(importer_host), |
| 34 source_profile_(source_profile), | 34 source_profile_(source_profile), |
| 35 items_(items), | 35 items_(items), |
| 36 bridge_(bridge), | 36 bridge_(bridge), |
| 37 cancelled_(false) { | 37 cancelled_(false) { |
| 38 process_importer_host_->NotifyImportStarted(); | 38 process_importer_host_->NotifyImportStarted(); |
| 39 } | 39 } |
| 40 | 40 |
| 41 ExternalProcessImporterClient::~ExternalProcessImporterClient() { | |
| 42 } | |
| 43 | |
| 44 void ExternalProcessImporterClient::CancelImportProcessOnIOThread() { | |
| 45 if (utility_process_host_) | |
| 46 utility_process_host_->Send(new ProfileImportProcessMsg_CancelImport()); | |
| 47 } | |
| 48 | |
| 49 void ExternalProcessImporterClient::NotifyItemFinishedOnIOThread( | |
| 50 importer::ImportItem import_item) { | |
| 51 utility_process_host_->Send( | |
| 52 new ProfileImportProcessMsg_ReportImportItemFinished(import_item)); | |
| 53 } | |
| 54 | |
| 55 void ExternalProcessImporterClient::Cleanup() { | |
| 56 if (cancelled_) | |
| 57 return; | |
| 58 | |
| 59 if (process_importer_host_) | |
| 60 process_importer_host_->NotifyImportEnded(); | |
| 61 Release(); | |
| 62 } | |
| 63 | |
| 64 void ExternalProcessImporterClient::Start() { | 41 void ExternalProcessImporterClient::Start() { |
| 65 AddRef(); // balanced in Cleanup. | 42 AddRef(); // balanced in Cleanup. |
| 66 BrowserThread::ID thread_id; | 43 BrowserThread::ID thread_id; |
| 67 CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_id)); | 44 CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_id)); |
| 68 BrowserThread::PostTask( | 45 BrowserThread::PostTask( |
| 69 BrowserThread::IO, FROM_HERE, | 46 BrowserThread::IO, FROM_HERE, |
| 70 base::Bind(&ExternalProcessImporterClient::StartProcessOnIOThread, | 47 base::Bind(&ExternalProcessImporterClient::StartProcessOnIOThread, |
| 71 this, | 48 this, |
| 72 thread_id)); | 49 thread_id)); |
| 73 } | 50 } |
| 74 | 51 |
| 75 void ExternalProcessImporterClient::StartProcessOnIOThread( | |
| 76 BrowserThread::ID thread_id) { | |
| 77 utility_process_host_ = | |
| 78 UtilityProcessHost::Create(this, thread_id)->AsWeakPtr(); | |
| 79 utility_process_host_->DisableSandbox(); | |
| 80 | |
| 81 #if defined(OS_MACOSX) | |
| 82 base::EnvironmentVector env; | |
| 83 std::string dylib_path = GetFirefoxDylibPath().value(); | |
| 84 if (!dylib_path.empty()) | |
| 85 env.push_back(std::make_pair("DYLD_FALLBACK_LIBRARY_PATH", dylib_path)); | |
| 86 utility_process_host_->SetEnv(env); | |
| 87 #endif | |
| 88 | |
| 89 // Dictionary of all localized strings that could be needed by the importer | |
| 90 // in the external process. | |
| 91 DictionaryValue localized_strings; | |
| 92 localized_strings.SetString( | |
| 93 base::IntToString(IDS_BOOKMARK_GROUP_FROM_FIREFOX), | |
| 94 l10n_util::GetStringUTF8(IDS_BOOKMARK_GROUP_FROM_FIREFOX)); | |
| 95 localized_strings.SetString( | |
| 96 base::IntToString(IDS_BOOKMARK_GROUP_FROM_SAFARI), | |
| 97 l10n_util::GetStringUTF8(IDS_BOOKMARK_GROUP_FROM_SAFARI)); | |
| 98 localized_strings.SetString( | |
| 99 base::IntToString(IDS_IMPORT_FROM_FIREFOX), | |
| 100 l10n_util::GetStringUTF8(IDS_IMPORT_FROM_FIREFOX)); | |
| 101 localized_strings.SetString( | |
| 102 base::IntToString(IDS_IMPORT_FROM_GOOGLE_TOOLBAR), | |
| 103 l10n_util::GetStringUTF8(IDS_IMPORT_FROM_GOOGLE_TOOLBAR)); | |
| 104 localized_strings.SetString( | |
| 105 base::IntToString(IDS_IMPORT_FROM_SAFARI), | |
| 106 l10n_util::GetStringUTF8(IDS_IMPORT_FROM_SAFARI)); | |
| 107 localized_strings.SetString( | |
| 108 base::IntToString(IDS_BOOKMARK_BAR_FOLDER_NAME), | |
| 109 l10n_util::GetStringUTF8(IDS_BOOKMARK_BAR_FOLDER_NAME)); | |
| 110 | |
| 111 utility_process_host_->Send(new ProfileImportProcessMsg_StartImport( | |
| 112 source_profile_, items_, localized_strings)); | |
| 113 } | |
| 114 | |
| 115 void ExternalProcessImporterClient::Cancel() { | 52 void ExternalProcessImporterClient::Cancel() { |
| 116 if (cancelled_) | 53 if (cancelled_) |
| 117 return; | 54 return; |
| 118 | 55 |
| 119 cancelled_ = true; | 56 cancelled_ = true; |
| 120 BrowserThread::PostTask( | 57 BrowserThread::PostTask( |
| 121 BrowserThread::IO, FROM_HERE, | 58 BrowserThread::IO, FROM_HERE, |
| 122 base::Bind( | 59 base::Bind( |
| 123 &ExternalProcessImporterClient::CancelImportProcessOnIOThread, | 60 &ExternalProcessImporterClient::CancelImportProcessOnIOThread, |
| 124 this)); | 61 this)); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 | 228 |
| 292 void ExternalProcessImporterClient::OnKeywordsImportReady( | 229 void ExternalProcessImporterClient::OnKeywordsImportReady( |
| 293 const std::vector<TemplateURL*>& template_urls, | 230 const std::vector<TemplateURL*>& template_urls, |
| 294 bool unique_on_host_and_path) { | 231 bool unique_on_host_and_path) { |
| 295 if (cancelled_) | 232 if (cancelled_) |
| 296 return; | 233 return; |
| 297 | 234 |
| 298 bridge_->SetKeywords(template_urls, unique_on_host_and_path); | 235 bridge_->SetKeywords(template_urls, unique_on_host_and_path); |
| 299 // The pointers in |template_urls| have now been deleted. | 236 // The pointers in |template_urls| have now been deleted. |
| 300 } | 237 } |
| 238 |
| 239 ExternalProcessImporterClient::~ExternalProcessImporterClient() {} |
| 240 |
| 241 void ExternalProcessImporterClient::Cleanup() { |
| 242 if (cancelled_) |
| 243 return; |
| 244 |
| 245 if (process_importer_host_) |
| 246 process_importer_host_->NotifyImportEnded(); |
| 247 Release(); |
| 248 } |
| 249 |
| 250 void ExternalProcessImporterClient::CancelImportProcessOnIOThread() { |
| 251 if (utility_process_host_) |
| 252 utility_process_host_->Send(new ProfileImportProcessMsg_CancelImport()); |
| 253 } |
| 254 |
| 255 void ExternalProcessImporterClient::NotifyItemFinishedOnIOThread( |
| 256 importer::ImportItem import_item) { |
| 257 utility_process_host_->Send( |
| 258 new ProfileImportProcessMsg_ReportImportItemFinished(import_item)); |
| 259 } |
| 260 |
| 261 void ExternalProcessImporterClient::StartProcessOnIOThread( |
| 262 BrowserThread::ID thread_id) { |
| 263 utility_process_host_ = |
| 264 UtilityProcessHost::Create(this, thread_id)->AsWeakPtr(); |
| 265 utility_process_host_->DisableSandbox(); |
| 266 |
| 267 #if defined(OS_MACOSX) |
| 268 base::EnvironmentVector env; |
| 269 std::string dylib_path = GetFirefoxDylibPath().value(); |
| 270 if (!dylib_path.empty()) |
| 271 env.push_back(std::make_pair("DYLD_FALLBACK_LIBRARY_PATH", dylib_path)); |
| 272 utility_process_host_->SetEnv(env); |
| 273 #endif |
| 274 |
| 275 // Dictionary of all localized strings that could be needed by the importer |
| 276 // in the external process. |
| 277 DictionaryValue localized_strings; |
| 278 localized_strings.SetString( |
| 279 base::IntToString(IDS_BOOKMARK_GROUP_FROM_FIREFOX), |
| 280 l10n_util::GetStringUTF8(IDS_BOOKMARK_GROUP_FROM_FIREFOX)); |
| 281 localized_strings.SetString( |
| 282 base::IntToString(IDS_BOOKMARK_GROUP_FROM_SAFARI), |
| 283 l10n_util::GetStringUTF8(IDS_BOOKMARK_GROUP_FROM_SAFARI)); |
| 284 localized_strings.SetString( |
| 285 base::IntToString(IDS_IMPORT_FROM_FIREFOX), |
| 286 l10n_util::GetStringUTF8(IDS_IMPORT_FROM_FIREFOX)); |
| 287 localized_strings.SetString( |
| 288 base::IntToString(IDS_IMPORT_FROM_GOOGLE_TOOLBAR), |
| 289 l10n_util::GetStringUTF8(IDS_IMPORT_FROM_GOOGLE_TOOLBAR)); |
| 290 localized_strings.SetString( |
| 291 base::IntToString(IDS_IMPORT_FROM_SAFARI), |
| 292 l10n_util::GetStringUTF8(IDS_IMPORT_FROM_SAFARI)); |
| 293 localized_strings.SetString( |
| 294 base::IntToString(IDS_BOOKMARK_BAR_FOLDER_NAME), |
| 295 l10n_util::GetStringUTF8(IDS_BOOKMARK_BAR_FOLDER_NAME)); |
| 296 |
| 297 utility_process_host_->Send(new ProfileImportProcessMsg_StartImport( |
| 298 source_profile_, items_, localized_strings)); |
| 299 } |
| OLD | NEW |