| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/importer/bookmarks_file_importer.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "chrome/browser/bookmarks/bookmark_html_reader.h" |
| 9 #include "chrome/browser/bookmarks/imported_bookmark_entry.h" |
| 10 #include "chrome/browser/importer/firefox_importer_utils.h" |
| 11 #include "chrome/browser/importer/importer_bridge.h" |
| 12 #include "chrome/browser/importer/importer_data_types.h" |
| 13 #include "chrome/browser/importer/importer_util.h" |
| 14 #include "grit/generated_resources.h" |
| 15 |
| 16 namespace { |
| 17 |
| 18 bool ImporterCancelBridge(BookmarksFileImporter* importer) { |
| 19 return importer->cancelled(); |
| 20 } |
| 21 |
| 22 } // namespace |
| 23 |
| 24 BookmarksFileImporter::BookmarksFileImporter() {} |
| 25 |
| 26 BookmarksFileImporter::~BookmarksFileImporter() {} |
| 27 |
| 28 void BookmarksFileImporter::StartImport( |
| 29 const importer::SourceProfile& source_profile, |
| 30 uint16 items, |
| 31 ImporterBridge* bridge) { |
| 32 // The only thing this importer can import is a bookmarks file, aka |
| 33 // "favorites". |
| 34 DCHECK_EQ(importer::FAVORITES, items); |
| 35 |
| 36 bridge->NotifyStarted(); |
| 37 bridge->NotifyItemStarted(importer::FAVORITES); |
| 38 |
| 39 std::vector<ImportedBookmarkEntry> bookmarks; |
| 40 std::vector<history::ImportedFaviconUsage> dirty_favicons; |
| 41 base::Callback<bool(void)> cancellation_callback = |
| 42 base::Bind(ImporterCancelBridge, base::Unretained(this)); |
| 43 base::Callback<bool(const GURL&)> valid_url_callback = |
| 44 base::Bind(CanImportURL); |
| 45 |
| 46 bookmark_html_reader::ImportBookmarksFile(&cancellation_callback, |
| 47 &valid_url_callback, |
| 48 source_profile.source_path, |
| 49 &bookmarks, |
| 50 &dirty_favicons); |
| 51 |
| 52 std::vector<history::ImportedFaviconUsage> clean_favicons; |
| 53 for (size_t i = 0; i < dirty_favicons.size(); ++i) { |
| 54 history::ImportedFaviconUsage& favicon = dirty_favicons[i]; |
| 55 std::vector<unsigned char> clean_data; |
| 56 if (importer::ReencodeFavicon(&favicon.png_data[0], |
| 57 favicon.png_data.size(), |
| 58 &clean_data)) { |
| 59 favicon.png_data.swap(clean_data); |
| 60 } |
| 61 clean_favicons.push_back(favicon); |
| 62 } |
| 63 |
| 64 if (!bookmarks.empty() && !cancelled()) { |
| 65 base::string16 first_folder_name = |
| 66 bridge->GetLocalizedString(IDS_BOOKMARK_GROUP); |
| 67 bridge->AddBookmarks(bookmarks, first_folder_name); |
| 68 } |
| 69 if (!clean_favicons.empty()) |
| 70 bridge->SetFavicons(clean_favicons); |
| 71 |
| 72 bridge->NotifyItemEnded(importer::FAVORITES); |
| 73 bridge->NotifyEnded(); |
| 74 } |
| OLD | NEW |