summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-16 23:09:32 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-16 23:09:32 +0000
commit5ed6961afa5307f1c81b87f04cb3f5d45853db90 (patch)
treea450c6af3cdee324e62a6150b4e6b720566a04ad /chrome/browser
parenta5aae12d00dd5efc48921d180e94208841a49f35 (diff)
downloadchromium_src-5ed6961afa5307f1c81b87f04cb3f5d45853db90.zip
chromium_src-5ed6961afa5307f1c81b87f04cb3f5d45853db90.tar.gz
chromium_src-5ed6961afa5307f1c81b87f04cb3f5d45853db90.tar.bz2
Misc. cleanup for chrome/browser/importer/:
BUG=none TEST=none Review URL: https://chromiumcodereview.appspot.com/9692073 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127289 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/importer/external_process_importer_bridge.cc3
-rw-r--r--chrome/browser/importer/external_process_importer_bridge.h1
-rw-r--r--chrome/browser/importer/external_process_importer_client.cc5
-rw-r--r--chrome/browser/importer/external_process_importer_client.h8
-rw-r--r--chrome/browser/importer/firefox2_importer.cc12
-rw-r--r--chrome/browser/importer/firefox3_importer.cc10
-rw-r--r--chrome/browser/importer/firefox_importer_unittest.cc8
-rw-r--r--chrome/browser/importer/firefox_importer_utils.cc34
-rw-r--r--chrome/browser/importer/ie_importer.cc51
-rw-r--r--chrome/browser/importer/importer_bridge.h1
-rw-r--r--chrome/browser/importer/in_process_importer_bridge.cc9
-rw-r--r--chrome/browser/importer/in_process_importer_bridge.h1
-rw-r--r--chrome/browser/importer/profile_import_process_messages.h3
-rw-r--r--chrome/browser/importer/profile_writer.cc52
-rw-r--r--chrome/browser/importer/profile_writer.h19
15 files changed, 83 insertions, 134 deletions
diff --git a/chrome/browser/importer/external_process_importer_bridge.cc b/chrome/browser/importer/external_process_importer_bridge.cc
index 0c3312e..c6a3903 100644
--- a/chrome/browser/importer/external_process_importer_bridge.cc
+++ b/chrome/browser/importer/external_process_importer_bridge.cc
@@ -104,14 +104,13 @@ void ExternalProcessImporterBridge::SetHistoryItems(
void ExternalProcessImporterBridge::SetKeywords(
const std::vector<TemplateURL*>& template_urls,
- int default_keyword_index,
bool unique_on_host_and_path) {
std::vector<TemplateURL> urls;
for (size_t i = 0; i < template_urls.size(); ++i) {
urls.push_back(*template_urls[i]);
}
Send(new ProfileImportProcessHostMsg_NotifyKeywordsReady(urls,
- default_keyword_index, unique_on_host_and_path));
+ unique_on_host_and_path));
}
void ExternalProcessImporterBridge::SetPasswordForm(
diff --git a/chrome/browser/importer/external_process_importer_bridge.h b/chrome/browser/importer/external_process_importer_bridge.h
index a9f884d..4640f0bb 100644
--- a/chrome/browser/importer/external_process_importer_bridge.h
+++ b/chrome/browser/importer/external_process_importer_bridge.h
@@ -51,7 +51,6 @@ class ExternalProcessImporterBridge : public ImporterBridge {
history::VisitSource visit_source) OVERRIDE;
virtual void SetKeywords(const std::vector<TemplateURL*>& template_urls,
- int default_keyword_index,
bool unique_on_host_and_path) OVERRIDE;
virtual void SetPasswordForm(
diff --git a/chrome/browser/importer/external_process_importer_client.cc b/chrome/browser/importer/external_process_importer_client.cc
index c2de9a8..77332e7 100644
--- a/chrome/browser/importer/external_process_importer_client.cc
+++ b/chrome/browser/importer/external_process_importer_client.cc
@@ -291,7 +291,7 @@ void ExternalProcessImporterClient::OnPasswordFormImportReady(
void ExternalProcessImporterClient::OnKeywordsImportReady(
const std::vector<TemplateURL>& template_urls,
- int default_keyword_index, bool unique_on_host_and_path) {
+ bool unique_on_host_and_path) {
if (cancelled_)
return;
@@ -303,6 +303,5 @@ void ExternalProcessImporterClient::OnKeywordsImportReady(
++iter) {
template_url_vec.push_back(new TemplateURL(*iter));
}
- bridge_->SetKeywords(template_url_vec, default_keyword_index,
- unique_on_host_and_path);
+ bridge_->SetKeywords(template_url_vec, unique_on_host_and_path);
}
diff --git a/chrome/browser/importer/external_process_importer_client.h b/chrome/browser/importer/external_process_importer_client.h
index 81b274b..e9b036f 100644
--- a/chrome/browser/importer/external_process_importer_client.h
+++ b/chrome/browser/importer/external_process_importer_client.h
@@ -61,17 +61,15 @@ class ExternalProcessImporterClient : public content::UtilityProcessHostClient {
int visit_source);
void OnHomePageImportReady(const GURL& home_page);
void OnBookmarksImportStart(const string16& first_folder_name,
- size_t total_bookmarks_count);
+ size_t total_bookmarks_count);
void OnBookmarksImportGroup(
const std::vector<ProfileWriter::BookmarkEntry>& bookmarks_group);
void OnFaviconsImportStart(size_t total_favicons_count);
void OnFaviconsImportGroup(
const std::vector<history::ImportedFaviconUsage>& favicons_group);
void OnPasswordFormImportReady(const webkit::forms::PasswordForm& form);
- void OnKeywordsImportReady(
- const std::vector<TemplateURL>& template_urls,
- int default_keyword_index,
- bool unique_on_host_and_path);
+ void OnKeywordsImportReady(const std::vector<TemplateURL>& template_urls,
+ bool unique_on_host_and_path);
private:
// Notifies the importerhost that import has finished, and calls Release().
diff --git a/chrome/browser/importer/firefox2_importer.cc b/chrome/browser/importer/firefox2_importer.cc
index 651cf45..6bcdb7d 100644
--- a/chrome/browser/importer/firefox2_importer.cc
+++ b/chrome/browser/importer/firefox2_importer.cc
@@ -132,13 +132,13 @@ TemplateURL* Firefox2Importer::CreateTemplateURL(const string16& title,
const string16& keyword,
const GURL& url) {
// Skip if the keyword or url is invalid.
- if (keyword.empty() && url.is_valid())
+ if (keyword.empty() || !url.is_valid())
return NULL;
TemplateURL* t_url = new TemplateURL();
// We set short name by using the title if it exists.
// Otherwise, we use the shortcut.
- t_url->set_short_name(!title.empty() ? title : keyword);
+ t_url->set_short_name(title.empty() ? keyword : title);
t_url->set_keyword(keyword);
t_url->SetURL(TemplateURLRef::DisplayURLToURLRef(UTF8ToUTF16(url.spec())),
0, 0);
@@ -315,9 +315,8 @@ void Firefox2Importer::ImportBookmarks() {
IDS_BOOKMARK_GROUP_FROM_FIREFOX);
bridge_->AddBookmarks(bookmarks, first_folder_name);
}
- if (!parsing_bookmarks_html_file_ && !template_urls.empty() &&
- !cancelled()) {
- bridge_->SetKeywords(template_urls, -1, false);
+ if (!parsing_bookmarks_html_file_ && !template_urls.empty() && !cancelled()) {
+ bridge_->SetKeywords(template_urls, false);
} else {
STLDeleteContainerPointers(template_urls.begin(), template_urls.end());
}
@@ -364,8 +363,7 @@ void Firefox2Importer::ImportSearchEngines() {
std::vector<TemplateURL*> search_engines;
ParseSearchEnginesFromXMLFiles(files, &search_engines);
- // Import the list of search engines, but do not override the default.
- bridge_->SetKeywords(search_engines, -1 /*default_keyword_index*/, true);
+ bridge_->SetKeywords(search_engines, true);
}
void Firefox2Importer::ImportHomepage() {
diff --git a/chrome/browser/importer/firefox3_importer.cc b/chrome/browser/importer/firefox3_importer.cc
index faca03b..3af1b4d 100644
--- a/chrome/browser/importer/firefox3_importer.cc
+++ b/chrome/browser/importer/firefox3_importer.cc
@@ -288,11 +288,10 @@ void Firefox3Importer::ImportBookmarks() {
bridge_->GetLocalizedString(IDS_BOOKMARK_GROUP_FROM_FIREFOX);
bridge_->AddBookmarks(bookmarks, first_folder_name);
}
- if (!template_urls.empty() && !cancelled()) {
- bridge_->SetKeywords(template_urls, -1, false);
- } else {
+ if (!template_urls.empty() && !cancelled())
+ bridge_->SetKeywords(template_urls, false);
+ else
STLDeleteContainerPointers(template_urls.begin(), template_urls.end());
- }
if (!favicon_map.empty() && !cancelled()) {
std::vector<history::ImportedFaviconUsage> favicons;
LoadFavicons(&db, favicon_map, &favicons);
@@ -339,8 +338,7 @@ void Firefox3Importer::ImportSearchEngines() {
std::vector<TemplateURL*> search_engines;
ParseSearchEnginesFromXMLFiles(files, &search_engines);
- // Import the list of search engines, but do not override the default.
- bridge_->SetKeywords(search_engines, -1 /*default_keyword_index*/, true);
+ bridge_->SetKeywords(search_engines, true);
}
void Firefox3Importer::ImportHomepage() {
diff --git a/chrome/browser/importer/firefox_importer_unittest.cc b/chrome/browser/importer/firefox_importer_unittest.cc
index cb7e5f5..b6d36f7 100644
--- a/chrome/browser/importer/firefox_importer_unittest.cc
+++ b/chrome/browser/importer/firefox_importer_unittest.cc
@@ -182,7 +182,6 @@ class FirefoxObserver : public ProfileWriter,
}
virtual void AddKeywords(const std::vector<TemplateURL*>& template_urls,
- int default_keyword_index,
bool unique_on_host_and_path) {
for (size_t i = 0; i < template_urls.size(); ++i) {
// The order might not be deterministic, look in the expected list for
@@ -201,7 +200,6 @@ class FirefoxObserver : public ProfileWriter,
++keyword_count_;
}
- EXPECT_EQ(-1, default_keyword_index);
STLDeleteContainerPointers(template_urls.begin(), template_urls.end());
}
@@ -336,7 +334,6 @@ class Firefox3Observer : public ProfileWriter,
}
void AddKeywords(const std::vector<TemplateURL*>& template_urls,
- int default_keyword_index,
bool unique_on_host_and_path) {
for (size_t i = 0; i < template_urls.size(); ++i) {
// The order might not be deterministic, look in the expected list for
@@ -355,7 +352,6 @@ class Firefox3Observer : public ProfileWriter,
++keyword_count_;
}
- EXPECT_EQ(-1, default_keyword_index);
STLDeleteContainerPointers(template_urls.begin(), template_urls.end());
}
@@ -508,7 +504,7 @@ TEST(FirefoxImporterTest, Firefox2NSS3Decryptor) {
FFUnitTestDecryptorProxy decryptor_proxy;
ASSERT_TRUE(decryptor_proxy.Setup(nss_path));
- EXPECT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path));
+ ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path));
EXPECT_EQ(ASCIIToUTF16("hello"),
decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECBJ"
"M63MpT9rtBAjMCm7qo/EhlA=="));
@@ -533,7 +529,7 @@ TEST(FirefoxImporterTest, Firefox3NSS3Decryptor) {
FFUnitTestDecryptorProxy decryptor_proxy;
ASSERT_TRUE(decryptor_proxy.Setup(nss_path));
- EXPECT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path));
+ ASSERT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path));
EXPECT_EQ(ASCIIToUTF16("hello"),
decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECKa"
"jtRg4qFSHBAhv9luFkXgDJA=="));
diff --git a/chrome/browser/importer/firefox_importer_utils.cc b/chrome/browser/importer/firefox_importer_utils.cc
index de4350e..4755e49 100644
--- a/chrome/browser/importer/firefox_importer_utils.cc
+++ b/chrome/browser/importer/firefox_importer_utils.cc
@@ -190,39 +190,40 @@ void ParseSearchEnginesFromXMLFiles(const std::vector<FilePath>& xml_files,
std::vector<TemplateURL*>* search_engines) {
DCHECK(search_engines);
- std::map<std::string, TemplateURL*> search_engine_for_url;
+ typedef std::map<std::string, TemplateURL*> SearchEnginesMap;
+ SearchEnginesMap search_engine_for_url;
std::string content;
// The first XML file represents the default search engine in Firefox 3, so we
// need to keep it on top of the list.
- TemplateURL* default_turl = NULL;
+ SearchEnginesMap::const_iterator default_turl = search_engine_for_url.end();
for (std::vector<FilePath>::const_iterator file_iter = xml_files.begin();
file_iter != xml_files.end(); ++file_iter) {
file_util::ReadFileToString(*file_iter, &content);
- TemplateURL* template_url = new TemplateURL();
FirefoxURLParameterFilter param_filter;
+ TemplateURL* template_url = new TemplateURL();
if (TemplateURLParser::Parse(
reinterpret_cast<const unsigned char*>(content.data()),
content.length(), &param_filter, template_url) &&
template_url->url()) {
std::string url = template_url->url()->url();
- std::map<std::string, TemplateURL*>::iterator iter =
- search_engine_for_url.find(url);
- if (iter != search_engine_for_url.end()) {
+ SearchEnginesMap::iterator iter = search_engine_for_url.find(url);
+ if (iter == search_engine_for_url.end()) {
+ iter = search_engine_for_url.insert(
+ std::make_pair(url, template_url)).first;
+ } else {
// We have already found a search engine with the same URL. We give
// priority to the latest one found, as GetSearchEnginesXMLFiles()
// returns a vector with first Firefox default search engines and then
// the user's ones. We want to give priority to the user ones.
delete iter->second;
- search_engine_for_url.erase(iter);
+ iter->second = template_url;
}
// Give this a keyword to facilitate tab-to-search, if possible.
- GURL gurl = GURL(url);
template_url->set_keyword(
- TemplateURLService::GenerateKeyword(gurl, false));
- template_url->set_show_in_default_list(true);
- search_engine_for_url[url] = template_url;
- if (!default_turl)
- default_turl = template_url;
+ TemplateURLService::GenerateKeyword(GURL(url), false));
+ iter->second->set_show_in_default_list(true);
+ if (default_turl == search_engine_for_url.end())
+ default_turl = iter;
} else {
delete template_url;
}
@@ -230,11 +231,10 @@ void ParseSearchEnginesFromXMLFiles(const std::vector<FilePath>& xml_files,
}
// Put the results in the |search_engines| vector.
- std::map<std::string, TemplateURL*>::iterator t_iter;
- for (t_iter = search_engine_for_url.begin();
+ for (SearchEnginesMap::iterator t_iter = search_engine_for_url.begin();
t_iter != search_engine_for_url.end(); ++t_iter) {
- if (t_iter->second == default_turl)
- search_engines->insert(search_engines->begin(), default_turl);
+ if (t_iter == default_turl)
+ search_engines->insert(search_engines->begin(), default_turl->second);
else
search_engines->push_back(t_iter->second);
}
diff --git a/chrome/browser/importer/ie_importer.cc b/chrome/browser/importer/ie_importer.cc
index d35d09d..08a577c 100644
--- a/chrome/browser/importer/ie_importer.cc
+++ b/chrome/browser/importer/ie_importer.cc
@@ -551,19 +551,18 @@ void IEImporter::ImportSearchEngines() {
// Software\Microsoft\Internet Explorer\SearchScopes
// Each key represents a search engine. The URL value contains the URL and
// the DisplayName the name.
- std::map<std::string, TemplateURL*> search_engines_map;
- base::win::RegistryKeyIterator key_iterator(HKEY_CURRENT_USER,
- kSearchScopePath);
- while (key_iterator.Valid()) {
+ typedef std::map<std::string, TemplateURL*> SearchEnginesMap;
+ SearchEnginesMap search_engines_map;
+ for (base::win::RegistryKeyIterator key_iter(HKEY_CURRENT_USER,
+ kSearchScopePath); key_iter.Valid(); ++key_iter) {
string16 sub_key_name = kSearchScopePath;
- sub_key_name.append(L"\\").append(key_iterator.Name());
+ sub_key_name.append(L"\\").append(key_iter.Name());
base::win::RegKey sub_key(HKEY_CURRENT_USER, sub_key_name.c_str(),
KEY_READ);
string16 wide_url;
if ((sub_key.ReadValue(L"URL", &wide_url) != ERROR_SUCCESS) ||
wide_url.empty()) {
- VLOG(1) << "No URL for IE search engine at " << key_iterator.Name();
- ++key_iterator;
+ VLOG(1) << "No URL for IE search engine at " << key_iter.Name();
continue;
}
// For the name, we try the default value first (as Live Search uses a
@@ -574,40 +573,36 @@ void IEImporter::ImportSearchEngines() {
// Try the displayable name.
if ((sub_key.ReadValue(L"DisplayName", &name) != ERROR_SUCCESS) ||
name.empty()) {
- VLOG(1) << "No name for IE search engine at " << key_iterator.Name();
- ++key_iterator;
+ VLOG(1) << "No name for IE search engine at " << key_iter.Name();
continue;
}
}
std::string url(WideToUTF8(wide_url));
- std::map<std::string, TemplateURL*>::iterator t_iter =
- search_engines_map.find(url);
- TemplateURL* template_url =
- (t_iter != search_engines_map.end()) ? t_iter->second : NULL;
- if (!template_url) {
+ SearchEnginesMap::iterator t_iter = search_engines_map.find(url);
+ if (t_iter == search_engines_map.end()) {
// First time we see that URL.
- template_url = new TemplateURL();
- template_url->set_short_name(name);
- template_url->SetURL(url, 0, 0);
- // Give this a keyword to facilitate tab-to-search, if possible.
- GURL gurl = GURL(url);
- template_url->set_keyword(TemplateURLService::GenerateKeyword(gurl,
- false));
- template_url->set_show_in_default_list(true);
- search_engines_map[url] = template_url;
+ GURL gurl(url);
+ if (gurl.is_valid()) {
+ TemplateURL* template_url = new TemplateURL();
+ template_url->set_short_name(name);
+ template_url->SetURL(url, 0, 0);
+ // Give this a keyword to facilitate tab-to-search, if possible.
+ template_url->set_keyword(TemplateURLService::GenerateKeyword(gurl,
+ false));
+ template_url->set_show_in_default_list(true);
+ search_engines_map.insert(std::make_pair(url, template_url));
+ }
}
- ++key_iterator;
}
// ProfileWriter::AddKeywords() requires a vector and we have a map.
- std::map<std::string, TemplateURL*>::iterator i;
std::vector<TemplateURL*> search_engines;
- for (i = search_engines_map.begin(); i != search_engines_map.end(); ++i)
+ for (SearchEnginesMap::iterator i = search_engines_map.begin();
+ i != search_engines_map.end(); ++i)
search_engines.push_back(i->second);
- // Import the list of search engines, but do not override the default.
- bridge_->SetKeywords(search_engines, -1 /*default_keyword_index*/, true);
+ bridge_->SetKeywords(search_engines, true);
}
void IEImporter::ImportHomepage() {
diff --git a/chrome/browser/importer/importer_bridge.h b/chrome/browser/importer/importer_bridge.h
index 2085f3d..b99afab 100644
--- a/chrome/browser/importer/importer_bridge.h
+++ b/chrome/browser/importer/importer_bridge.h
@@ -39,7 +39,6 @@ class ImporterBridge : public base::RefCountedThreadSafe<ImporterBridge> {
history::VisitSource visit_source) = 0;
virtual void SetKeywords(const std::vector<TemplateURL*>& template_urls,
- int default_keyword_index,
bool unique_on_host_and_path) = 0;
virtual void SetPasswordForm(const webkit::forms::PasswordForm& form) = 0;
diff --git a/chrome/browser/importer/in_process_importer_bridge.cc b/chrome/browser/importer/in_process_importer_bridge.cc
index 14ba8f2..d599902 100644
--- a/chrome/browser/importer/in_process_importer_bridge.cc
+++ b/chrome/browser/importer/in_process_importer_bridge.cc
@@ -64,13 +64,10 @@ void InProcessImporterBridge::SetHistoryItems(
void InProcessImporterBridge::SetKeywords(
const std::vector<TemplateURL*>& template_urls,
- int default_keyword_index,
bool unique_on_host_and_path) {
- BrowserThread::PostTask(
- BrowserThread::UI, FROM_HERE,
- base::Bind(
- &ProfileWriter::AddKeywords, writer_, template_urls,
- default_keyword_index, unique_on_host_and_path));
+ BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
+ base::Bind(&ProfileWriter::AddKeywords, writer_, template_urls,
+ unique_on_host_and_path));
}
void InProcessImporterBridge::SetPasswordForm(
diff --git a/chrome/browser/importer/in_process_importer_bridge.h b/chrome/browser/importer/in_process_importer_bridge.h
index f6a0126..e70143d 100644
--- a/chrome/browser/importer/in_process_importer_bridge.h
+++ b/chrome/browser/importer/in_process_importer_bridge.h
@@ -41,7 +41,6 @@ class InProcessImporterBridge : public ImporterBridge {
history::VisitSource visit_source) OVERRIDE;
virtual void SetKeywords(const std::vector<TemplateURL*>& template_urls,
- int default_keyword_index,
bool unique_on_host_and_path) OVERRIDE;
virtual void SetPasswordForm(
diff --git a/chrome/browser/importer/profile_import_process_messages.h b/chrome/browser/importer/profile_import_process_messages.h
index 442cc01..a11cb35 100644
--- a/chrome/browser/importer/profile_import_process_messages.h
+++ b/chrome/browser/importer/profile_import_process_messages.h
@@ -397,7 +397,6 @@ IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyFaviconsImportGroup,
IPC_MESSAGE_CONTROL1(ProfileImportProcessHostMsg_NotifyPasswordFormReady,
webkit::forms::PasswordForm)
-IPC_MESSAGE_CONTROL3(ProfileImportProcessHostMsg_NotifyKeywordsReady,
+IPC_MESSAGE_CONTROL2(ProfileImportProcessHostMsg_NotifyKeywordsReady,
std::vector<TemplateURL>,
- int, /* default keyword index */
bool /* unique on host and path */)
diff --git a/chrome/browser/importer/profile_writer.cc b/chrome/browser/importer/profile_writer.cc
index 3be6d7b..da4da0c 100644
--- a/chrome/browser/importer/profile_writer.cc
+++ b/chrome/browser/importer/profile_writer.cc
@@ -261,9 +261,8 @@ static std::string BuildHostPathKey(const TemplateURL* t_url,
if (t_url->url()->SupportsReplacement()) {
return HostPathKeyForURL(GURL(
- t_url->url()->ReplaceSearchTerms(
- *t_url, ASCIIToUTF16("random string"),
- TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())));
+ t_url->url()->ReplaceSearchTerms(*t_url, ASCIIToUTF16("x"),
+ TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16())));
}
}
return std::string();
@@ -271,9 +270,10 @@ static std::string BuildHostPathKey(const TemplateURL* t_url,
// Builds a set that contains an entry of the host+path for each TemplateURL in
// the TemplateURLService that has a valid search url.
-static void BuildHostPathMap(const TemplateURLService& model,
+static void BuildHostPathMap(TemplateURLService* model,
HostPathMap* host_path_map) {
- std::vector<const TemplateURL*> template_urls = model.GetTemplateURLs();
+ TemplateURLService::TemplateURLVector template_urls =
+ model->GetTemplateURLs();
for (size_t i = 0; i < template_urls.size(); ++i) {
const std::string host_path = BuildHostPathKey(template_urls[i], false);
if (!host_path.empty()) {
@@ -293,31 +293,21 @@ static void BuildHostPathMap(const TemplateURLService& model,
}
void ProfileWriter::AddKeywords(const std::vector<TemplateURL*>& template_urls,
- int default_keyword_index,
bool unique_on_host_and_path) {
TemplateURLService* model =
TemplateURLServiceFactory::GetForProfile(profile_);
HostPathMap host_path_map;
if (unique_on_host_and_path)
- BuildHostPathMap(*model, &host_path_map);
+ BuildHostPathMap(model, &host_path_map);
for (std::vector<TemplateURL*>::const_iterator i = template_urls.begin();
i != template_urls.end(); ++i) {
- TemplateURL* t_url = *i;
- bool default_keyword =
- default_keyword_index >= 0 &&
- (i - template_urls.begin() == default_keyword_index);
+ scoped_ptr<TemplateURL> t_url(*i);
// TemplateURLService requires keywords to be unique. If there is already a
// TemplateURL with this keyword, don't import it again.
- const TemplateURL* turl_with_keyword =
- model->GetTemplateURLForKeyword(t_url->keyword());
- if (turl_with_keyword != NULL) {
- if (default_keyword)
- model->SetDefaultSearchProvider(turl_with_keyword);
- delete t_url;
+ if (model->GetTemplateURLForKeyword(t_url->keyword()) != NULL)
continue;
- }
// For search engines if there is already a keyword with the same
// host+path, we don't import it. This is done to avoid both duplicate
@@ -325,27 +315,13 @@ void ProfileWriter::AddKeywords(const std::vector<TemplateURL*>& template_urls,
// sure the search engines we provide aren't replaced by those from the
// imported browser.
if (unique_on_host_and_path &&
- host_path_map.find(
- BuildHostPathKey(t_url, true)) != host_path_map.end()) {
- if (default_keyword) {
- const TemplateURL* turl_with_host_path =
- host_path_map[BuildHostPathKey(t_url, true)];
- if (turl_with_host_path)
- model->SetDefaultSearchProvider(turl_with_host_path);
- else
- NOTREACHED(); // BuildHostPathMap should only insert non-null values.
- }
- delete t_url;
+ (host_path_map.find(BuildHostPathKey(t_url.get(), true)) !=
+ host_path_map.end()))
continue;
- }
- if (t_url->url() && t_url->url()->IsValid()) {
- model->Add(t_url);
- if (default_keyword && TemplateURL::SupportsReplacement(t_url))
- model->SetDefaultSearchProvider(t_url);
- } else {
- // Don't add invalid TemplateURLs to the model.
- delete t_url;
- }
+
+ // Only add valid TemplateURLs to the model.
+ if (t_url->url() && t_url->url()->IsValid())
+ model->Add(t_url.release());
}
}
diff --git a/chrome/browser/importer/profile_writer.h b/chrome/browser/importer/profile_writer.h
index 69c58e6..ac315f3 100644
--- a/chrome/browser/importer/profile_writer.h
+++ b/chrome/browser/importer/profile_writer.h
@@ -90,18 +90,15 @@ class ProfileWriter : public base::RefCountedThreadSafe<ProfileWriter> {
virtual void AddFavicons(
const std::vector<history::ImportedFaviconUsage>& favicons);
- // Add the TemplateURLs in |template_urls| to the local store and make the
- // TemplateURL at |default_keyword_index| the default keyword (does not set
- // a default keyword if it is -1). The local store becomes the owner of the
- // TemplateURLs. Some TemplateURLs in |template_urls| may conflict (same
- // keyword or same host name in the URL) with existing TemplateURLs in the
- // local store, in which case the existing ones takes precedence and the
- // duplicate in |template_urls| are deleted.
- // If unique_on_host_and_path a TemplateURL is only added if there is not an
- // existing TemplateURL that has a replaceable search url with the same
- // host+path combination.
+ // Adds the TemplateURLs in |template_urls| to the local store. The local
+ // store becomes the owner of the TemplateURLs. Some TemplateURLs in
+ // |template_urls| may conflict (same keyword or same host name in the URL)
+ // with existing TemplateURLs in the local store, in which case the existing
+ // ones take precedence and the duplicates in |template_urls| are deleted.
+ // If |unique_on_host_and_path| is true, a TemplateURL is only added if there
+ // is not an existing TemplateURL that has a replaceable search url with the
+ // same host+path combination.
virtual void AddKeywords(const std::vector<TemplateURL*>& template_urls,
- int default_keyword_index,
bool unique_on_host_and_path);
protected: