OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/importer/firefox_importer.h" | 5 #include "chrome/utility/importer/firefox_importer.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
11 #include "base/json/json_file_value_serializer.h" | 11 #include "base/json/json_file_value_serializer.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
16 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
17 #include "chrome/common/importer/firefox_importer_utils.h" | 17 #include "chrome/common/importer/firefox_importer_utils.h" |
18 #include "chrome/common/importer/firefox_importer_utils.h" | 18 #include "chrome/common/importer/firefox_importer_utils.h" |
19 #include "chrome/common/importer/imported_bookmark_entry.h" | 19 #include "chrome/common/importer/imported_bookmark_entry.h" |
20 #include "chrome/common/importer/imported_favicon_usage.h" | 20 #include "chrome/common/importer/imported_favicon_usage.h" |
21 #include "chrome/common/importer/importer_autofill_form_data_entry.h" | |
21 #include "chrome/common/importer/importer_bridge.h" | 22 #include "chrome/common/importer/importer_bridge.h" |
22 #include "chrome/common/importer/importer_url_row.h" | 23 #include "chrome/common/importer/importer_url_row.h" |
23 #include "chrome/grit/generated_resources.h" | 24 #include "chrome/grit/generated_resources.h" |
24 #include "chrome/utility/importer/bookmark_html_reader.h" | 25 #include "chrome/utility/importer/bookmark_html_reader.h" |
25 #include "chrome/utility/importer/favicon_reencode.h" | 26 #include "chrome/utility/importer/favicon_reencode.h" |
26 #include "chrome/utility/importer/nss_decryptor.h" | 27 #include "chrome/utility/importer/nss_decryptor.h" |
27 #include "components/autofill/core/common/password_form.h" | 28 #include "components/autofill/core/common/password_form.h" |
28 #include "sql/connection.h" | 29 #include "sql/connection.h" |
29 #include "sql/statement.h" | 30 #include "sql/statement.h" |
30 #include "url/gurl.h" | 31 #include "url/gurl.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 if ((items & importer::SEARCH_ENGINES) && !cancelled()) { | 134 if ((items & importer::SEARCH_ENGINES) && !cancelled()) { |
134 bridge_->NotifyItemStarted(importer::SEARCH_ENGINES); | 135 bridge_->NotifyItemStarted(importer::SEARCH_ENGINES); |
135 ImportSearchEngines(); | 136 ImportSearchEngines(); |
136 bridge_->NotifyItemEnded(importer::SEARCH_ENGINES); | 137 bridge_->NotifyItemEnded(importer::SEARCH_ENGINES); |
137 } | 138 } |
138 if ((items & importer::PASSWORDS) && !cancelled()) { | 139 if ((items & importer::PASSWORDS) && !cancelled()) { |
139 bridge_->NotifyItemStarted(importer::PASSWORDS); | 140 bridge_->NotifyItemStarted(importer::PASSWORDS); |
140 ImportPasswords(); | 141 ImportPasswords(); |
141 bridge_->NotifyItemEnded(importer::PASSWORDS); | 142 bridge_->NotifyItemEnded(importer::PASSWORDS); |
142 } | 143 } |
144 if ((items & importer::AUTOFILL_FORM_DATA) && !cancelled()) { | |
145 bridge_->NotifyItemStarted(importer::AUTOFILL_FORM_DATA); | |
146 ImportAutofillFormData(); | |
147 bridge_->NotifyItemEnded(importer::AUTOFILL_FORM_DATA); | |
148 } | |
143 bridge_->NotifyEnded(); | 149 bridge_->NotifyEnded(); |
144 } | 150 } |
145 | 151 |
146 void FirefoxImporter::ImportHistory() { | 152 void FirefoxImporter::ImportHistory() { |
147 base::FilePath file = source_path_.AppendASCII("places.sqlite"); | 153 base::FilePath file = source_path_.AppendASCII("places.sqlite"); |
148 if (!base::PathExists(file)) | 154 if (!base::PathExists(file)) |
149 return; | 155 return; |
150 | 156 |
151 sql::Connection db; | 157 sql::Connection db; |
152 if (!db.Open(file)) | 158 if (!db.Open(file)) |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
375 bridge_->SetFirefoxSearchEnginesXMLData(search_engine_data); | 381 bridge_->SetFirefoxSearchEnginesXMLData(search_engine_data); |
376 } | 382 } |
377 | 383 |
378 void FirefoxImporter::ImportHomepage() { | 384 void FirefoxImporter::ImportHomepage() { |
379 GURL home_page = GetHomepage(source_path_); | 385 GURL home_page = GetHomepage(source_path_); |
380 if (home_page.is_valid() && !IsDefaultHomepage(home_page, app_path_)) { | 386 if (home_page.is_valid() && !IsDefaultHomepage(home_page, app_path_)) { |
381 bridge_->AddHomePage(home_page); | 387 bridge_->AddHomePage(home_page); |
382 } | 388 } |
383 } | 389 } |
384 | 390 |
391 void FirefoxImporter::ImportAutofillFormData() { | |
392 base::FilePath file = source_path_.AppendASCII("formhistory.sqlite"); | |
393 if (!base::PathExists(file)) | |
394 return; | |
395 | |
396 sql::Connection db; | |
397 if (!db.Open(file)) | |
398 return; | |
399 | |
400 const char* query = | |
Ilya Sherman
2014/08/20 05:47:42
nit: "const char query[] =" is more const (both th
Nikhil
2014/08/20 11:29:18
Changes done for this. But there are other queries
Ilya Sherman
2014/08/20 20:47:22
Yes, this would be great to fix in a follow-up pat
Nikhil
2014/08/21 07:35:36
Acknowledged.
| |
401 "SELECT fieldname, value, timesUsed, firstUsed, lastUsed FROM " | |
402 "moz_formhistory"; | |
403 | |
404 sql::Statement s(db.GetUniqueStatement(query)); | |
405 | |
406 std::vector<ImporterAutofillFormDataEntry> form_entries; | |
407 while (s.Step() && !cancelled()) { | |
408 ImporterAutofillFormDataEntry form_entry; | |
409 form_entry.name = s.ColumnString16(0); | |
410 form_entry.value = s.ColumnString16(1); | |
411 form_entry.times_used = s.ColumnInt(2); | |
412 form_entry.first_used = base::Time::FromTimeT(s.ColumnInt64(3) / 1000000); | |
413 form_entry.last_used = base::Time::FromTimeT(s.ColumnInt64(4) / 1000000); | |
414 | |
415 // Don't import search bar history. | |
416 if (base::UTF16ToUTF8(form_entry.name) == "searchbar-history") | |
417 continue; | |
418 | |
419 form_entries.push_back(form_entry); | |
420 } | |
421 | |
422 if (!form_entries.empty() && !cancelled()) | |
423 bridge_->SetAutofillFormData(form_entries); | |
424 } | |
425 | |
385 void FirefoxImporter::GetSearchEnginesXMLData( | 426 void FirefoxImporter::GetSearchEnginesXMLData( |
386 std::vector<std::string>* search_engine_data) { | 427 std::vector<std::string>* search_engine_data) { |
387 base::FilePath file = source_path_.AppendASCII("search.sqlite"); | 428 base::FilePath file = source_path_.AppendASCII("search.sqlite"); |
388 if (!base::PathExists(file)) { | 429 if (!base::PathExists(file)) { |
389 // Since Firefox 3.5, search engines are no longer stored in search.sqlite. | 430 // Since Firefox 3.5, search engines are no longer stored in search.sqlite. |
390 // Instead, search.json is used for storing search engines. | 431 // Instead, search.json is used for storing search engines. |
391 GetSearchEnginesXMLDataFromJSON(search_engine_data); | 432 GetSearchEnginesXMLDataFromJSON(search_engine_data); |
392 return; | 433 return; |
393 } | 434 } |
394 | 435 |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
725 | 766 |
726 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) | 767 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) |
727 continue; // Unable to decode. | 768 continue; // Unable to decode. |
728 | 769 |
729 usage.urls = i->second; | 770 usage.urls = i->second; |
730 favicons->push_back(usage); | 771 favicons->push_back(usage); |
731 } | 772 } |
732 s.Reset(true); | 773 s.Reset(true); |
733 } | 774 } |
734 } | 775 } |
OLD | NEW |