This source file includes following definitions.
- IsImporterCancelled
- CanImportURL
- StartImport
#include "chrome/utility/importer/bookmarks_file_importer.h"
#include "base/bind.h"
#include "chrome/common/importer/imported_bookmark_entry.h"
#include "chrome/common/importer/imported_favicon_usage.h"
#include "chrome/common/importer/importer_bridge.h"
#include "chrome/common/importer/importer_data_types.h"
#include "chrome/common/net/url_fixer_upper.h"
#include "chrome/common/url_constants.h"
#include "chrome/utility/importer/bookmark_html_reader.h"
#include "content/public/common/url_constants.h"
#include "grit/generated_resources.h"
namespace {
bool IsImporterCancelled(BookmarksFileImporter* importer) {
return importer->cancelled();
}
}
namespace internal {
bool CanImportURL(const GURL& url) {
if (!url.is_valid())
return false;
const char* const kInvalidSchemes[] = {"wyciwyg", "place"};
for (size_t i = 0; i < arraysize(kInvalidSchemes); ++i) {
if (url.SchemeIs(kInvalidSchemes[i]))
return false;
}
if (url == GURL(content::kAboutBlankURL))
return true;
if (url.SchemeIs(content::kChromeUIScheme) ||
url.SchemeIs(content::kAboutScheme)) {
if (url.host() == chrome::kChromeUIUberHost ||
url.host() == chrome::kChromeUIAboutHost)
return true;
GURL fixed_url(URLFixerUpper::FixupURL(url.spec(), std::string()));
for (size_t i = 0; i < chrome::kNumberOfChromeHostURLs; ++i) {
if (fixed_url.DomainIs(chrome::kChromeHostURLs[i]))
return true;
}
for (int i = 0; i < chrome::kNumberOfChromeDebugURLs; ++i) {
if (fixed_url == GURL(chrome::kChromeDebugURLs[i]))
return true;
}
return false;
}
return true;
}
}
BookmarksFileImporter::BookmarksFileImporter() {}
BookmarksFileImporter::~BookmarksFileImporter() {}
void BookmarksFileImporter::StartImport(
const importer::SourceProfile& source_profile,
uint16 items,
ImporterBridge* bridge) {
DCHECK_EQ(importer::FAVORITES, items);
bridge->NotifyStarted();
bridge->NotifyItemStarted(importer::FAVORITES);
std::vector<ImportedBookmarkEntry> bookmarks;
std::vector<ImportedFaviconUsage> favicons;
bookmark_html_reader::ImportBookmarksFile(
base::Bind(IsImporterCancelled, base::Unretained(this)),
base::Bind(internal::CanImportURL),
source_profile.source_path,
&bookmarks,
&favicons);
if (!bookmarks.empty() && !cancelled()) {
base::string16 first_folder_name =
bridge->GetLocalizedString(IDS_BOOKMARK_GROUP);
bridge->AddBookmarks(bookmarks, first_folder_name);
}
if (!favicons.empty())
bridge->SetFavicons(favicons);
bridge->NotifyItemEnded(importer::FAVORITES);
bridge->NotifyEnded();
}