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" | |
10 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
11 #include "base/macros.h" | 10 #include "base/macros.h" |
12 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
13 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
14 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
15 #include "build/build_config.h" | 14 #include "build/build_config.h" |
16 #include "chrome/browser/importer/external_process_importer_host.h" | 15 #include "chrome/browser/importer/external_process_importer_host.h" |
17 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" | 16 #include "chrome/browser/search_engines/ui_thread_search_terms_data.h" |
18 #include "chrome/common/importer/imported_bookmark_entry.h" | 17 #include "chrome/common/importer/imported_bookmark_entry.h" |
19 #include "chrome/common/importer/importer_autofill_form_data_entry.h" | 18 #include "chrome/common/importer/importer_autofill_form_data_entry.h" |
20 #include "components/autofill/core/browser/webdata/autofill_entry.h" | 19 #include "components/autofill/core/browser/webdata/autofill_entry.h" |
21 #include "components/autofill/core/common/password_form.h" | 20 #include "components/autofill/core/common/password_form.h" |
22 #include "components/favicon_base/favicon_usage_data.h" | 21 #include "components/favicon_base/favicon_usage_data.h" |
23 #include "components/search_engines/template_url.h" | 22 #include "components/search_engines/template_url.h" |
24 #include "components/search_engines/template_url_parser.h" | 23 #include "components/search_engines/template_url_parser.h" |
25 #include "components/search_engines/template_url_prepopulate_data.h" | 24 #include "components/search_engines/template_url_prepopulate_data.h" |
26 #include "content/public/browser/browser_thread.h" | |
27 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
28 | 26 |
29 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
30 #include "components/os_crypt/ie7_password_win.h" | 28 #include "components/os_crypt/ie7_password_win.h" |
31 #endif | 29 #endif |
32 | 30 |
33 #include <iterator> | 31 #include <iterator> |
34 | 32 |
35 namespace { | 33 namespace { |
36 | 34 |
(...skipping 25 matching lines...) Expand all Loading... |
62 return history::SOURCE_IE_IMPORTED; | 60 return history::SOURCE_IE_IMPORTED; |
63 case importer::VISIT_SOURCE_SAFARI_IMPORTED: | 61 case importer::VISIT_SOURCE_SAFARI_IMPORTED: |
64 return history::SOURCE_SAFARI_IMPORTED; | 62 return history::SOURCE_SAFARI_IMPORTED; |
65 } | 63 } |
66 NOTREACHED(); | 64 NOTREACHED(); |
67 return history::SOURCE_SYNCED; | 65 return history::SOURCE_SYNCED; |
68 } | 66 } |
69 | 67 |
70 } // namespace | 68 } // namespace |
71 | 69 |
72 using content::BrowserThread; | |
73 | |
74 namespace { | 70 namespace { |
75 | 71 |
76 // FirefoxURLParameterFilter is used to remove parameter mentioning Firefox from | 72 // FirefoxURLParameterFilter is used to remove parameter mentioning Firefox from |
77 // the search URL when importing search engines. | 73 // the search URL when importing search engines. |
78 class FirefoxURLParameterFilter : public TemplateURLParser::ParameterFilter { | 74 class FirefoxURLParameterFilter : public TemplateURLParser::ParameterFilter { |
79 public: | 75 public: |
80 FirefoxURLParameterFilter() {} | 76 FirefoxURLParameterFilter() {} |
81 ~FirefoxURLParameterFilter() override {} | 77 ~FirefoxURLParameterFilter() override {} |
82 | 78 |
83 // TemplateURLParser::ParameterFilter method. | 79 // TemplateURLParser::ParameterFilter method. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 | 159 |
164 InProcessImporterBridge::InProcessImporterBridge( | 160 InProcessImporterBridge::InProcessImporterBridge( |
165 ProfileWriter* writer, | 161 ProfileWriter* writer, |
166 base::WeakPtr<ExternalProcessImporterHost> host) : writer_(writer), | 162 base::WeakPtr<ExternalProcessImporterHost> host) : writer_(writer), |
167 host_(host) { | 163 host_(host) { |
168 } | 164 } |
169 | 165 |
170 void InProcessImporterBridge::AddBookmarks( | 166 void InProcessImporterBridge::AddBookmarks( |
171 const std::vector<ImportedBookmarkEntry>& bookmarks, | 167 const std::vector<ImportedBookmarkEntry>& bookmarks, |
172 const base::string16& first_folder_name) { | 168 const base::string16& first_folder_name) { |
173 BrowserThread::PostTask( | 169 writer_->AddBookmarks(bookmarks, first_folder_name); |
174 BrowserThread::UI, FROM_HERE, | |
175 base::Bind(&ProfileWriter::AddBookmarks, writer_, bookmarks, | |
176 first_folder_name)); | |
177 } | 170 } |
178 | 171 |
179 void InProcessImporterBridge::AddHomePage(const GURL& home_page) { | 172 void InProcessImporterBridge::AddHomePage(const GURL& home_page) { |
180 BrowserThread::PostTask( | 173 writer_->AddHomepage(home_page); |
181 BrowserThread::UI, FROM_HERE, | |
182 base::Bind(&ProfileWriter::AddHomepage, writer_, home_page)); | |
183 } | 174 } |
184 | 175 |
185 #if defined(OS_WIN) | 176 #if defined(OS_WIN) |
186 void InProcessImporterBridge::AddIE7PasswordInfo( | 177 void InProcessImporterBridge::AddIE7PasswordInfo( |
187 const importer::ImporterIE7PasswordInfo& password_info) { | 178 const importer::ImporterIE7PasswordInfo& password_info) { |
188 IE7PasswordInfo ie7_password_info; | 179 IE7PasswordInfo ie7_password_info; |
189 ie7_password_info.url_hash = password_info.url_hash; | 180 ie7_password_info.url_hash = password_info.url_hash; |
190 ie7_password_info.encrypted_data = password_info.encrypted_data; | 181 ie7_password_info.encrypted_data = password_info.encrypted_data; |
191 ie7_password_info.date_created = password_info.date_created; | 182 ie7_password_info.date_created = password_info.date_created; |
192 | 183 |
193 BrowserThread::PostTask( | 184 writer_->AddIE7PasswordInfo(ie7_password_info); |
194 BrowserThread::UI, FROM_HERE, | |
195 base::Bind(&ProfileWriter::AddIE7PasswordInfo, writer_, | |
196 ie7_password_info)); | |
197 } | 185 } |
198 #endif // OS_WIN | 186 #endif // OS_WIN |
199 | 187 |
200 void InProcessImporterBridge::SetFavicons( | 188 void InProcessImporterBridge::SetFavicons( |
201 const favicon_base::FaviconUsageDataList& favicons) { | 189 const favicon_base::FaviconUsageDataList& favicons) { |
202 BrowserThread::PostTask( | 190 writer_->AddFavicons(favicons); |
203 BrowserThread::UI, FROM_HERE, | |
204 base::Bind(&ProfileWriter::AddFavicons, writer_, favicons)); | |
205 } | 191 } |
206 | 192 |
207 void InProcessImporterBridge::SetHistoryItems( | 193 void InProcessImporterBridge::SetHistoryItems( |
208 const std::vector<ImporterURLRow>& rows, | 194 const std::vector<ImporterURLRow>& rows, |
209 importer::VisitSource visit_source) { | 195 importer::VisitSource visit_source) { |
210 history::URLRows converted_rows = | 196 history::URLRows converted_rows = |
211 ConvertImporterURLRowsToHistoryURLRows(rows); | 197 ConvertImporterURLRowsToHistoryURLRows(rows); |
212 history::VisitSource converted_visit_source = | 198 history::VisitSource converted_visit_source = |
213 ConvertImporterVisitSourceToHistoryVisitSource(visit_source); | 199 ConvertImporterVisitSourceToHistoryVisitSource(visit_source); |
214 BrowserThread::PostTask(BrowserThread::UI, | 200 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 } | 201 } |
221 | 202 |
222 void InProcessImporterBridge::SetKeywords( | 203 void InProcessImporterBridge::SetKeywords( |
223 const std::vector<importer::SearchEngineInfo>& search_engines, | 204 const std::vector<importer::SearchEngineInfo>& search_engines, |
224 bool unique_on_host_and_path) { | 205 bool unique_on_host_and_path) { |
225 TemplateURLService::OwnedTemplateURLVector owned_template_urls; | 206 TemplateURLService::OwnedTemplateURLVector owned_template_urls; |
226 for (const auto& search_engine : search_engines) { | 207 for (const auto& search_engine : search_engines) { |
227 std::unique_ptr<TemplateURL> owned_template_url = CreateTemplateURL( | 208 std::unique_ptr<TemplateURL> owned_template_url = CreateTemplateURL( |
228 search_engine.url, search_engine.keyword, search_engine.display_name); | 209 search_engine.url, search_engine.keyword, search_engine.display_name); |
229 if (owned_template_url) | 210 if (owned_template_url) |
230 owned_template_urls.push_back(std::move(owned_template_url)); | 211 owned_template_urls.push_back(std::move(owned_template_url)); |
231 } | 212 } |
232 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 213 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 } | 214 } |
236 | 215 |
237 void InProcessImporterBridge::SetFirefoxSearchEnginesXMLData( | 216 void InProcessImporterBridge::SetFirefoxSearchEnginesXMLData( |
238 const std::vector<std::string>& search_engine_data) { | 217 const std::vector<std::string>& search_engine_data) { |
239 TemplateURLService::OwnedTemplateURLVector search_engines; | 218 TemplateURLService::OwnedTemplateURLVector search_engines; |
240 ParseSearchEnginesFromFirefoxXMLData(search_engine_data, &search_engines); | 219 ParseSearchEnginesFromFirefoxXMLData(search_engine_data, &search_engines); |
241 | 220 |
242 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 221 writer_->AddKeywords(std::move(search_engines), true); |
243 base::Bind(&ProfileWriter::AddKeywords, writer_, | |
244 base::Passed(&search_engines), true)); | |
245 } | 222 } |
246 | 223 |
247 void InProcessImporterBridge::SetPasswordForm( | 224 void InProcessImporterBridge::SetPasswordForm( |
248 const autofill::PasswordForm& form) { | 225 const autofill::PasswordForm& form) { |
249 BrowserThread::PostTask( | 226 writer_->AddPasswordForm(form); |
250 BrowserThread::UI, FROM_HERE, | |
251 base::Bind(&ProfileWriter::AddPasswordForm, writer_, form)); | |
252 } | 227 } |
253 | 228 |
254 void InProcessImporterBridge::SetAutofillFormData( | 229 void InProcessImporterBridge::SetAutofillFormData( |
255 const std::vector<ImporterAutofillFormDataEntry>& entries) { | 230 const std::vector<ImporterAutofillFormDataEntry>& entries) { |
256 std::vector<autofill::AutofillEntry> autofill_entries; | 231 std::vector<autofill::AutofillEntry> autofill_entries; |
257 for (size_t i = 0; i < entries.size(); ++i) { | 232 for (size_t i = 0; i < entries.size(); ++i) { |
258 autofill_entries.push_back(autofill::AutofillEntry( | 233 autofill_entries.push_back(autofill::AutofillEntry( |
259 autofill::AutofillKey(entries[i].name, entries[i].value), | 234 autofill::AutofillKey(entries[i].name, entries[i].value), |
260 entries[i].first_used, | 235 entries[i].first_used, |
261 entries[i].last_used)); | 236 entries[i].last_used)); |
262 } | 237 } |
263 | 238 |
264 BrowserThread::PostTask(BrowserThread::UI, | 239 writer_->AddAutofillFormDataEntries(autofill_entries); |
265 FROM_HERE, | |
266 base::Bind(&ProfileWriter::AddAutofillFormDataEntries, | |
267 writer_, | |
268 autofill_entries)); | |
269 } | 240 } |
270 | 241 |
271 void InProcessImporterBridge::NotifyStarted() { | 242 void InProcessImporterBridge::NotifyStarted() { |
272 BrowserThread::PostTask( | 243 host_->NotifyImportStarted(); |
273 BrowserThread::UI, FROM_HERE, | |
274 base::Bind(&ExternalProcessImporterHost::NotifyImportStarted, host_)); | |
275 } | 244 } |
276 | 245 |
277 void InProcessImporterBridge::NotifyItemStarted(importer::ImportItem item) { | 246 void InProcessImporterBridge::NotifyItemStarted(importer::ImportItem item) { |
278 BrowserThread::PostTask( | 247 host_->NotifyImportItemStarted(item); |
279 BrowserThread::UI, FROM_HERE, | |
280 base::Bind(&ExternalProcessImporterHost::NotifyImportItemStarted, | |
281 host_, item)); | |
282 } | 248 } |
283 | 249 |
284 void InProcessImporterBridge::NotifyItemEnded(importer::ImportItem item) { | 250 void InProcessImporterBridge::NotifyItemEnded(importer::ImportItem item) { |
285 BrowserThread::PostTask( | 251 host_->NotifyImportItemEnded(item); |
286 BrowserThread::UI, FROM_HERE, | |
287 base::Bind(&ExternalProcessImporterHost::NotifyImportItemEnded, | |
288 host_, item)); | |
289 } | 252 } |
290 | 253 |
291 void InProcessImporterBridge::NotifyEnded() { | 254 void InProcessImporterBridge::NotifyEnded() { |
292 BrowserThread::PostTask( | 255 host_->NotifyImportEnded(); |
293 BrowserThread::UI, FROM_HERE, | |
294 base::Bind(&ExternalProcessImporterHost::NotifyImportEnded, host_)); | |
295 } | 256 } |
296 | 257 |
297 base::string16 InProcessImporterBridge::GetLocalizedString(int message_id) { | 258 base::string16 InProcessImporterBridge::GetLocalizedString(int message_id) { |
298 return l10n_util::GetStringUTF16(message_id); | 259 return l10n_util::GetStringUTF16(message_id); |
299 } | 260 } |
300 | 261 |
301 InProcessImporterBridge::~InProcessImporterBridge() {} | 262 InProcessImporterBridge::~InProcessImporterBridge() {} |
OLD | NEW |