OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/profile_import/profile_import_thread.h" | 5 #include "chrome/profile_import/profile_import_thread.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/values.h" | 9 #include "base/values.h" |
10 #include "chrome/browser/importer/importer.h" | 10 #include "chrome/browser/importer/importer.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 OnImportItemFinished) | 44 OnImportItemFinished) |
45 IPC_END_MESSAGE_MAP() | 45 IPC_END_MESSAGE_MAP() |
46 } | 46 } |
47 | 47 |
48 void ProfileImportThread::OnImportStart( | 48 void ProfileImportThread::OnImportStart( |
49 const ProfileInfo& profile_info, | 49 const ProfileInfo& profile_info, |
50 int items, | 50 int items, |
51 const DictionaryValue& localized_strings, | 51 const DictionaryValue& localized_strings, |
52 bool import_to_bookmark_bar) { | 52 bool import_to_bookmark_bar) { |
53 bridge_ = new ExternalProcessImporterBridge(this, localized_strings); | 53 bridge_ = new ExternalProcessImporterBridge(this, localized_strings); |
54 bridge_->AddRef(); // Balanced in Cleanup(). | |
55 | 54 |
56 ImporterList importer_list; | 55 ImporterList importer_list; |
57 importer_ = importer_list.CreateImporterByType(profile_info.browser_type); | 56 importer_ = importer_list.CreateImporterByType(profile_info.browser_type); |
58 if (!importer_) { | 57 if (!importer_) { |
59 Send(new ProfileImportProcessHostMsg_Import_Finished(false, | 58 Send(new ProfileImportProcessHostMsg_Import_Finished(false, |
60 "Importer could not be created.")); | 59 "Importer could not be created.")); |
61 return; | 60 return; |
62 } | 61 } |
63 | 62 |
64 importer_->AddRef(); // Balanced in Cleanup(). | |
65 importer_->set_import_to_bookmark_bar(import_to_bookmark_bar); | 63 importer_->set_import_to_bookmark_bar(import_to_bookmark_bar); |
66 items_to_import_ = items; | 64 items_to_import_ = items; |
67 | 65 |
68 // Create worker thread in which importer runs. | 66 // Create worker thread in which importer runs. |
69 import_thread_.reset(new base::Thread("import_thread")); | 67 import_thread_.reset(new base::Thread("import_thread")); |
70 base::Thread::Options options; | 68 base::Thread::Options options; |
71 options.message_loop_type = MessageLoop::TYPE_IO; | 69 options.message_loop_type = MessageLoop::TYPE_IO; |
72 if (!import_thread_->StartWithOptions(options)) { | 70 if (!import_thread_->StartWithOptions(options)) { |
73 NOTREACHED(); | 71 NOTREACHED(); |
74 Cleanup(); | 72 Cleanup(); |
75 } | 73 } |
76 import_thread_->message_loop()->PostTask(FROM_HERE, | 74 import_thread_->message_loop()->PostTask( |
77 NewRunnableMethod(importer_, &Importer::StartImport, | 75 FROM_HERE, |
78 profile_info, items, bridge_)); | 76 NewRunnableMethod( |
| 77 importer_.get(), |
| 78 &Importer::StartImport, |
| 79 profile_info, |
| 80 items, |
| 81 bridge_)); |
79 } | 82 } |
80 | 83 |
81 void ProfileImportThread::OnImportCancel() { | 84 void ProfileImportThread::OnImportCancel() { |
82 Cleanup(); | 85 Cleanup(); |
83 } | 86 } |
84 | 87 |
85 void ProfileImportThread::OnImportItemFinished(uint16 item) { | 88 void ProfileImportThread::OnImportItemFinished(uint16 item) { |
86 items_to_import_ ^= item; // Remove finished item from mask. | 89 items_to_import_ ^= item; // Remove finished item from mask. |
87 // If we've finished with all items, notify the browser process. | 90 // If we've finished with all items, notify the browser process. |
88 if (items_to_import_ == 0) | 91 if (items_to_import_ == 0) |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 std::vector<TemplateURL> urls; | 182 std::vector<TemplateURL> urls; |
180 for (size_t i = 0; i < template_urls.size(); ++i) { | 183 for (size_t i = 0; i < template_urls.size(); ++i) { |
181 urls.push_back(*template_urls[i]); | 184 urls.push_back(*template_urls[i]); |
182 } | 185 } |
183 Send(new ProfileImportProcessHostMsg_NotifyKeywordsReady(urls, | 186 Send(new ProfileImportProcessHostMsg_NotifyKeywordsReady(urls, |
184 default_keyword_index, unique_on_host_and_path)); | 187 default_keyword_index, unique_on_host_and_path)); |
185 } | 188 } |
186 | 189 |
187 void ProfileImportThread::Cleanup() { | 190 void ProfileImportThread::Cleanup() { |
188 importer_->Cancel(); | 191 importer_->Cancel(); |
189 importer_->Release(); | 192 importer_ = NULL; |
190 bridge_->Release(); | 193 bridge_ = NULL; |
191 ChildProcess::current()->ReleaseProcess(); | 194 ChildProcess::current()->ReleaseProcess(); |
192 } | 195 } |
OLD | NEW |