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

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

Issue 616763002: Importing certain bookmarks from firefox and HTML file as search engines. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Handled potential NULL pointer exception that could have resulted from CreateTemplateURL. Created 6 years 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/in_process_importer_bridge.cc
diff --git a/chrome/browser/importer/in_process_importer_bridge.cc b/chrome/browser/importer/in_process_importer_bridge.cc
index 3bd1fde5be8c905e1ea3b3014adf69bb691b80f0..178fd63b3cab9d7a1db588d59c0f39fcb4fc35c5 100644
--- a/chrome/browser/importer/in_process_importer_bridge.cc
+++ b/chrome/browser/importer/in_process_importer_bridge.cc
@@ -91,25 +91,30 @@ class FirefoxURLParameterFilter : public TemplateURLParser::ParameterFilter {
DISALLOW_COPY_AND_ASSIGN(FirefoxURLParameterFilter);
};
-// Creates a TemplateURL with the |keyword| and |url|. |title| may be empty.
+// Attempts to create a TemplateURL from the provided data. |title| is optional.
+// If |keyword| is not specified, the function will attempt to generate the
+// keyword from |url|, which in that case must be a valid GURL. This can fail if
+// e.g. the replacement term is in the host. If TemplateURL creation fails,
+// returns NULL.
// This function transfers ownership of the created TemplateURL to the caller.
TemplateURL* CreateTemplateURL(const base::string16& title,
const base::string16& keyword,
- const GURL& url) {
- // Skip if the url is invalid.
- if (!url.is_valid())
+ const base::string16& url) {
+ if (url.empty())
return NULL;
-
TemplateURLData data;
- if (keyword.empty())
- data.SetKeyword(TemplateURL::GenerateKeyword(url));
- else
+ if (keyword.empty()) {
+ GURL gurl(url);
+ if (!gurl.is_valid())
+ return NULL;
+ data.SetKeyword(TemplateURL::GenerateKeyword(gurl));
+ } else {
data.SetKeyword(keyword);
+ }
// We set short name by using the title if it exists.
// Otherwise, we use the shortcut.
data.short_name = title.empty() ? keyword : title;
Peter Kasting 2014/12/09 23:10:19 I think this should be "keyword()" instead of "key
Tapu Ghose 2014/12/10 04:41:55 Made use of "data.keyword()" instead of "keyword".
Peter Kasting 2014/12/10 17:41:16 Well, where else is this called from? You should
Tapu Ghose 2014/12/11 03:12:21 Looks like this is called while importing bookmark
- data.SetURL(
- TemplateURLRef::DisplayURLToURLRef(base::UTF8ToUTF16(url.spec())));
+ data.SetURL(TemplateURLRef::DisplayURLToURLRef(url));
return new TemplateURL(data);
}
@@ -221,14 +226,16 @@ void InProcessImporterBridge::SetHistoryItems(
}
void InProcessImporterBridge::SetKeywords(
- const std::vector<importer::URLKeywordInfo>& url_keywords,
+ const std::vector<importer::SearchEngineInfo>& search_engines,
bool unique_on_host_and_path) {
ScopedVector<TemplateURL> owned_template_urls;
- for (size_t i = 0; i < url_keywords.size(); ++i) {
- owned_template_urls.push_back(
- CreateTemplateURL(url_keywords[i].display_name,
- url_keywords[i].keyword,
- url_keywords[i].url));
+ TemplateURL* owned_template_url;
Peter Kasting 2014/12/09 23:10:19 Nit: Declare this where it's defined, in the loop
Tapu Ghose 2014/12/10 04:41:55 Agreed.
+ for (const auto& search_engine : search_engines) {
+ owned_template_url = CreateTemplateURL(search_engine.display_name,
+ search_engine.keyword,
+ search_engine.url);
+ if (owned_template_url)
+ owned_template_urls.push_back(owned_template_url);
}
BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
base::Bind(&ProfileWriter::AddKeywords, writer_,

Powered by Google App Engine
This is Rietveld 408576698