Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1066)

Unified Diff: chrome/browser/importer/firefox3_importer.cc

Issue 14575004: Extract BookmarksFileImporter from Firefox2Importer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: extraneous include Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/importer/firefox3_importer.cc
diff --git a/chrome/browser/importer/firefox3_importer.cc b/chrome/browser/importer/firefox3_importer.cc
index 2cab2caee68c69bc92f1a311925e57e945ab2ea2..7aee612a35ad72ee5271200f3c612c85aaacaa22 100644
--- a/chrome/browser/importer/firefox3_importer.cc
+++ b/chrome/browser/importer/firefox3_importer.cc
@@ -41,6 +41,24 @@ enum BookmarkItemType {
TYPE_DYNAMIC_CONTAINER = 4
};
+// Creates a TemplateURL with the |keyword| and |url|. |title| may be empty.
+// This function transfers ownership of the created TemplateURL to the caller.
+TemplateURL* CreateTemplateURL(const string16& title,
+ const string16& keyword,
+ const GURL& url) {
+ // Skip if the keyword or url is invalid.
+ if (keyword.empty() || !url.is_valid())
+ return NULL;
+
+ TemplateURLData data;
+ // We set short name by using the title if it exists.
+ // Otherwise, we use the shortcut.
+ data.short_name = title.empty() ? keyword : title;
+ data.SetKeyword(keyword);
+ data.SetURL(TemplateURLRef::DisplayURLToURLRef(UTF8ToUTF16(url.spec())));
+ return new TemplateURL(NULL, data);
+}
+
} // namespace
struct Firefox3Importer::BookmarkItem {
@@ -273,7 +291,7 @@ void Firefox3Importer::ImportBookmarks() {
favicon_map[item->favicon].insert(item->url);
// This bookmark has a keyword, we import it to our TemplateURL model.
- TemplateURL* t_url = Firefox2Importer::CreateTemplateURL(
+ TemplateURL* t_url = CreateTemplateURL(
item->title, UTF8ToUTF16(item->keyword), item->url);
if (t_url)
template_urls.push_back(t_url);

Powered by Google App Engine
This is Rietveld 408576698