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/importer/bookmark_html_reader.h" | |
9 #include "chrome/browser/importer/firefox_importer_utils.h" | |
10 #include "chrome/browser/importer/importer_bridge.h" | |
11 #include "chrome/common/importer/imported_bookmark_entry.h" | |
12 #include "chrome/common/importer/imported_favicon_usage.h" | |
13 #include "chrome/common/importer/importer_data_types.h" | |
14 #include "grit/generated_resources.h" | |
15 | |
16 namespace { | |
17 | |
18 bool IsImporterCancelled(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<ImportedFaviconUsage> favicons; | |
41 | |
42 bookmark_html_reader::ImportBookmarksFile( | |
43 base::Bind(IsImporterCancelled, base::Unretained(this)), | |
44 base::Bind(CanImportURL), | |
45 source_profile.source_path, | |
46 &bookmarks, | |
47 &favicons); | |
48 | |
49 if (!bookmarks.empty() && !cancelled()) { | |
50 base::string16 first_folder_name = | |
51 bridge->GetLocalizedString(IDS_BOOKMARK_GROUP); | |
52 bridge->AddBookmarks(bookmarks, first_folder_name); | |
53 } | |
54 if (!favicons.empty()) | |
55 bridge->SetFavicons(favicons); | |
56 | |
57 bridge->NotifyItemEnded(importer::FAVORITES); | |
58 bridge->NotifyEnded(); | |
59 } | |
OLD | NEW |