| 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/utility/profile_import_handler.h" | 5 #include "chrome/utility/profile_import_handler.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
| 12 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
| 13 #include "build/build_config.h" |
| 13 #include "chrome/common/importer/profile_import_process_messages.h" | 14 #include "chrome/common/importer/profile_import_process_messages.h" |
| 14 #include "chrome/utility/importer/external_process_importer_bridge.h" | 15 #include "chrome/utility/importer/external_process_importer_bridge.h" |
| 15 #include "chrome/utility/importer/importer.h" | 16 #include "chrome/utility/importer/importer.h" |
| 16 #include "chrome/utility/importer/importer_creator.h" | 17 #include "chrome/utility/importer/importer_creator.h" |
| 17 #include "content/public/utility/utility_thread.h" | 18 #include "content/public/utility/utility_thread.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 bool Send(IPC::Message* message) { | 22 bool Send(IPC::Message* message) { |
| 22 return content::UtilityThread::Get()->Send(message); | 23 return content::UtilityThread::Get()->Send(message); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 35 IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_CancelImport, OnImportCancel) | 36 IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_CancelImport, OnImportCancel) |
| 36 IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_ReportImportItemFinished, | 37 IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_ReportImportItemFinished, |
| 37 OnImportItemFinished) | 38 OnImportItemFinished) |
| 38 IPC_MESSAGE_UNHANDLED(handled = false) | 39 IPC_MESSAGE_UNHANDLED(handled = false) |
| 39 IPC_END_MESSAGE_MAP() | 40 IPC_END_MESSAGE_MAP() |
| 40 return handled; | 41 return handled; |
| 41 } | 42 } |
| 42 | 43 |
| 43 void ProfileImportHandler::OnImportStart( | 44 void ProfileImportHandler::OnImportStart( |
| 44 const importer::SourceProfile& source_profile, | 45 const importer::SourceProfile& source_profile, |
| 45 uint16 items, | 46 uint16_t items, |
| 46 const base::DictionaryValue& localized_strings) { | 47 const base::DictionaryValue& localized_strings) { |
| 47 content::UtilityThread::Get()->EnsureBlinkInitialized(); | 48 content::UtilityThread::Get()->EnsureBlinkInitialized(); |
| 48 bridge_ = new ExternalProcessImporterBridge( | 49 bridge_ = new ExternalProcessImporterBridge( |
| 49 localized_strings, | 50 localized_strings, |
| 50 content::UtilityThread::Get(), | 51 content::UtilityThread::Get(), |
| 51 base::ThreadTaskRunnerHandle::Get().get()); | 52 base::ThreadTaskRunnerHandle::Get().get()); |
| 52 importer_ = importer::CreateImporterByType(source_profile.importer_type); | 53 importer_ = importer::CreateImporterByType(source_profile.importer_type); |
| 53 if (!importer_.get()) { | 54 if (!importer_.get()) { |
| 54 Send(new ProfileImportProcessHostMsg_Import_Finished( | 55 Send(new ProfileImportProcessHostMsg_Import_Finished( |
| 55 false, "Importer could not be created.")); | 56 false, "Importer could not be created.")); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 69 } | 70 } |
| 70 import_thread_->task_runner()->PostTask( | 71 import_thread_->task_runner()->PostTask( |
| 71 FROM_HERE, base::Bind(&Importer::StartImport, importer_.get(), | 72 FROM_HERE, base::Bind(&Importer::StartImport, importer_.get(), |
| 72 source_profile, items, bridge_)); | 73 source_profile, items, bridge_)); |
| 73 } | 74 } |
| 74 | 75 |
| 75 void ProfileImportHandler::OnImportCancel() { | 76 void ProfileImportHandler::OnImportCancel() { |
| 76 ImporterCleanup(); | 77 ImporterCleanup(); |
| 77 } | 78 } |
| 78 | 79 |
| 79 void ProfileImportHandler::OnImportItemFinished(uint16 item) { | 80 void ProfileImportHandler::OnImportItemFinished(uint16_t item) { |
| 80 items_to_import_ ^= item; // Remove finished item from mask. | 81 items_to_import_ ^= item; // Remove finished item from mask. |
| 81 // If we've finished with all items, notify the browser process. | 82 // If we've finished with all items, notify the browser process. |
| 82 if (items_to_import_ == 0) { | 83 if (items_to_import_ == 0) { |
| 83 Send(new ProfileImportProcessHostMsg_Import_Finished(true, std::string())); | 84 Send(new ProfileImportProcessHostMsg_Import_Finished(true, std::string())); |
| 84 ImporterCleanup(); | 85 ImporterCleanup(); |
| 85 } | 86 } |
| 86 } | 87 } |
| 87 | 88 |
| 88 void ProfileImportHandler::ImporterCleanup() { | 89 void ProfileImportHandler::ImporterCleanup() { |
| 89 importer_->Cancel(); | 90 importer_->Cancel(); |
| 90 importer_ = NULL; | 91 importer_ = NULL; |
| 91 bridge_ = NULL; | 92 bridge_ = NULL; |
| 92 import_thread_.reset(); | 93 import_thread_.reset(); |
| 93 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); | 94 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); |
| 94 } | 95 } |
| OLD | NEW |