Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: chrome/utility/profile_import_handler.cc

Issue 2470283002: Convert profile import IPCs to Mojo (Closed)
Patch Set: Fix incorrect merge Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
sky 2016/11/29 23:56:28 Remove any includes that are no longer applicable.
tibell 2016/11/30 03:36:47 Still used below by the call to task_runner().
11 #include "base/threading/thread.h" 11 #include "base/threading/thread.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/common/importer/profile_import_process_messages.h"
15 #include "chrome/utility/importer/external_process_importer_bridge.h" 14 #include "chrome/utility/importer/external_process_importer_bridge.h"
16 #include "chrome/utility/importer/importer.h" 15 #include "chrome/utility/importer/importer.h"
17 #include "chrome/utility/importer/importer_creator.h" 16 #include "chrome/utility/importer/importer_creator.h"
18 #include "content/public/utility/utility_thread.h" 17 #include "content/public/utility/utility_thread.h"
18 #include "mojo/public/cpp/bindings/strong_binding.h"
19 19
20 namespace { 20 // static
sky 2016/11/29 23:56:28 Declaration and definition order should match (see
tibell 2016/11/30 03:36:47 Done.
sky 2016/11/30 16:19:07 Did you miss this one? This function should be aft
tibell 2016/11/30 23:56:26 Done.
21 21 void ProfileImportHandler::Create(
22 bool Send(IPC::Message* message) { 22 mojo::InterfaceRequest<chrome::mojom::ProfileImport> request) {
23 return content::UtilityThread::Get()->Send(message); 23 mojo::MakeStrongBinding(base::MakeUnique<ProfileImportHandler>(),
24 std::move(request));
24 } 25 }
25 26
26 } // namespace
27
28 ProfileImportHandler::ProfileImportHandler() : items_to_import_(0) {} 27 ProfileImportHandler::ProfileImportHandler() : items_to_import_(0) {}
29 28
30 ProfileImportHandler::~ProfileImportHandler() {} 29 ProfileImportHandler::~ProfileImportHandler() {}
31 30
32 bool ProfileImportHandler::OnMessageReceived(const IPC::Message& message) { 31 void ProfileImportHandler::StartImport(
33 bool handled = true;
34 IPC_BEGIN_MESSAGE_MAP(ProfileImportHandler, message)
35 IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_StartImport, OnImportStart)
36 IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_CancelImport, OnImportCancel)
37 IPC_MESSAGE_HANDLER(ProfileImportProcessMsg_ReportImportItemFinished,
38 OnImportItemFinished)
39 IPC_MESSAGE_UNHANDLED(handled = false)
40 IPC_END_MESSAGE_MAP()
41 return handled;
42 }
43
44 void ProfileImportHandler::OnImportStart(
45 const importer::SourceProfile& source_profile, 32 const importer::SourceProfile& source_profile,
46 uint16_t items, 33 uint16_t items,
47 const base::DictionaryValue& localized_strings) { 34 const base::DictionaryValue& localized_strings,
35 chrome::mojom::ProfileImportObserverPtr observer) {
48 content::UtilityThread::Get()->EnsureBlinkInitialized(); 36 content::UtilityThread::Get()->EnsureBlinkInitialized();
49 bridge_ = new ExternalProcessImporterBridge(
50 localized_strings,
51 content::UtilityThread::Get(),
52 base::ThreadTaskRunnerHandle::Get().get());
53 importer_ = importer::CreateImporterByType(source_profile.importer_type); 37 importer_ = importer::CreateImporterByType(source_profile.importer_type);
54 if (!importer_.get()) { 38 if (!importer_.get()) {
55 Send(new ProfileImportProcessHostMsg_Import_Finished( 39 observer->OnImportFinished(false, "Importer could not be created.");
56 false, "Importer could not be created."));
57 return; 40 return;
58 } 41 }
59 42
60 items_to_import_ = items; 43 items_to_import_ = items;
61 44
62 // Create worker thread in which importer runs. 45 // Create worker thread in which importer runs.
63 import_thread_.reset(new base::Thread("import_thread")); 46 import_thread_.reset(new base::Thread("import_thread"));
64 #if defined(OS_WIN) 47 #if defined(OS_WIN)
65 import_thread_->init_com_with_mta(false); 48 import_thread_->init_com_with_mta(false);
66 #endif 49 #endif
67 if (!import_thread_->Start()) { 50 if (!import_thread_->Start()) {
68 NOTREACHED(); 51 NOTREACHED();
69 ImporterCleanup(); 52 ImporterCleanup();
70 } 53 }
54 // Move the InterfacePtr to the import thread, as remaining messages will be
55 // sent from there:
56 observer.Bind(observer.PassInterface(), import_thread_->task_runner());
sky 2016/11/29 23:56:28 The description of Bind indicates the runner "must
tibell 2016/11/30 03:36:47 Talked this through with sammc@ and we decided tha
yzshen1 2016/12/01 18:15:48 Sorry for late reply. Just realized that I missed
57 bridge_ =
58 new ExternalProcessImporterBridge(localized_strings, std::move(observer));
71 import_thread_->task_runner()->PostTask( 59 import_thread_->task_runner()->PostTask(
72 FROM_HERE, base::Bind(&Importer::StartImport, importer_, 60 FROM_HERE, base::Bind(&Importer::StartImport, importer_,
73 source_profile, items, base::RetainedRef(bridge_))); 61 source_profile, items, base::RetainedRef(bridge_)));
74 } 62 }
75 63
76 void ProfileImportHandler::OnImportCancel() { 64 void ProfileImportHandler::CancelImport() {
77 ImporterCleanup(); 65 ImporterCleanup();
78 } 66 }
79 67
80 void ProfileImportHandler::OnImportItemFinished(uint16_t item) { 68 void ProfileImportHandler::ReportImportItemFinished(importer::ImportItem item) {
81 items_to_import_ ^= item; // Remove finished item from mask. 69 items_to_import_ ^= item; // Remove finished item from mask.
82 // If we've finished with all items, notify the browser process.
83 if (items_to_import_ == 0) { 70 if (items_to_import_ == 0) {
84 Send(new ProfileImportProcessHostMsg_Import_Finished(true, std::string()));
85 ImporterCleanup(); 71 ImporterCleanup();
86 } 72 }
87 } 73 }
88 74
89 void ProfileImportHandler::ImporterCleanup() { 75 void ProfileImportHandler::ImporterCleanup() {
90 importer_->Cancel(); 76 importer_->Cancel();
91 importer_ = NULL; 77 importer_ = NULL;
92 bridge_ = NULL; 78 bridge_ = NULL;
93 import_thread_.reset(); 79 import_thread_.reset();
94 content::UtilityThread::Get()->ReleaseProcessIfNeeded(); 80 content::UtilityThread::Get()->ReleaseProcessIfNeeded();
95 } 81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698