diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-05 22:08:16 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-05 22:08:16 +0000 |
commit | c808593aa9b58d8c647713214477bd237eb5e0fc (patch) | |
tree | 8c91bc6e34424df600ab7ddc33286feacfed6d7f /chrome/browser/importer | |
parent | add68c87534edb4b6b50f35e75213f422083d5b9 (diff) | |
download | chromium_src-c808593aa9b58d8c647713214477bd237eb5e0fc.zip chromium_src-c808593aa9b58d8c647713214477bd237eb5e0fc.tar.gz chromium_src-c808593aa9b58d8c647713214477bd237eb5e0fc.tar.bz2 |
Move most TemplateURL data members to a new struct, TemplateURLData. This allows us to eliminate the TemplateURL NULL constructor, most public non-const TemplateURL functions, and most TemplateURL friend declarations.
This is also a necessary precursor to changing TemplateURLService's APIs to convert most "const TemplateURL*" cases to "TemplateURL*", which I'll explain once I actually make the change.
There is some awkwardness here around keywords, as keyword autogeneration requires a TemplateURL but the state bits are kept on TemplateURLData. This will go away in the future when I remove keyword autogeneration from TemplateURL entirely.
BUG=none
TEST=none
Review URL: https://chromiumcodereview.appspot.com/9982018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131019 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/importer')
-rw-r--r-- | chrome/browser/importer/firefox2_importer.cc | 10 | ||||
-rw-r--r-- | chrome/browser/importer/firefox_importer_utils.cc | 5 | ||||
-rw-r--r-- | chrome/browser/importer/ie_importer.cc | 15 | ||||
-rw-r--r-- | chrome/browser/importer/profile_import_process_messages.h | 119 |
4 files changed, 75 insertions, 74 deletions
diff --git a/chrome/browser/importer/firefox2_importer.cc b/chrome/browser/importer/firefox2_importer.cc index fe6cbb1..91bb725 100644 --- a/chrome/browser/importer/firefox2_importer.cc +++ b/chrome/browser/importer/firefox2_importer.cc @@ -134,13 +134,13 @@ TemplateURL* Firefox2Importer::CreateTemplateURL(const string16& title, if (keyword.empty() || !url.is_valid()) return NULL; - TemplateURL* t_url = new TemplateURL(); + TemplateURLData data; // We set short name by using the title if it exists. // Otherwise, we use the shortcut. - t_url->set_short_name(title.empty() ? keyword : title); - t_url->set_keyword(keyword); - t_url->SetURL(TemplateURLRef::DisplayURLToURLRef(UTF8ToUTF16(url.spec()))); - return t_url; + data.short_name = title.empty() ? keyword : title; + data.SetKeyword(keyword); + data.SetURL(TemplateURLRef::DisplayURLToURLRef(UTF8ToUTF16(url.spec()))); + return new TemplateURL(data); } // static diff --git a/chrome/browser/importer/firefox_importer_utils.cc b/chrome/browser/importer/firefox_importer_utils.cc index 5904940..5cceeb2 100644 --- a/chrome/browser/importer/firefox_importer_utils.cc +++ b/chrome/browser/importer/firefox_importer_utils.cc @@ -200,8 +200,8 @@ void ParseSearchEnginesFromXMLFiles(const std::vector<FilePath>& xml_files, file_iter != xml_files.end(); ++file_iter) { file_util::ReadFileToString(*file_iter, &content); FirefoxURLParameterFilter param_filter; - TemplateURL* template_url = TemplateURLParser::Parse(NULL, content.data(), - content.length(), ¶m_filter); + TemplateURL* template_url = TemplateURLParser::Parse(NULL, true, + content.data(), content.length(), ¶m_filter); if (template_url) { SearchEnginesMap::iterator iter = search_engine_for_url.find(template_url->url()); @@ -216,7 +216,6 @@ void ParseSearchEnginesFromXMLFiles(const std::vector<FilePath>& xml_files, delete iter->second; iter->second = template_url; } - iter->second->set_show_in_default_list(true); if (default_turl == search_engine_for_url.end()) default_turl = iter; } diff --git a/chrome/browser/importer/ie_importer.cc b/chrome/browser/importer/ie_importer.cc index 63823dd..0730fb8 100644 --- a/chrome/browser/importer/ie_importer.cc +++ b/chrome/browser/importer/ie_importer.cc @@ -584,14 +584,13 @@ void IEImporter::ImportSearchEngines() { // First time we see that URL. GURL gurl(url); if (gurl.is_valid()) { - TemplateURL* template_url = new TemplateURL(); - template_url->set_short_name(name); - template_url->SetURL(url); - // 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)); + TemplateURLData data; + data.short_name = name; + data.SetKeyword(TemplateURLService::GenerateKeyword(gurl, false)); + data.SetURL(url); + data.show_in_default_list = true; + t_iter = search_engines_map.insert(std::make_pair(url, + new TemplateURL(data))).first; } } } diff --git a/chrome/browser/importer/profile_import_process_messages.h b/chrome/browser/importer/profile_import_process_messages.h index ff9407a..ceaf9e0 100644 --- a/chrome/browser/importer/profile_import_process_messages.h +++ b/chrome/browser/importer/profile_import_process_messages.h @@ -189,6 +189,63 @@ struct ParamTraits<history::ImportedFaviconUsage> { } }; // ParamTraits<history::ImportedFaviconUsage +// Traits for TemplateURLData +template <> +struct ParamTraits<TemplateURLData> { + typedef TemplateURLData param_type; + static void Write(Message* m, const param_type& p) { + WriteParam(m, p.short_name); + WriteParam(m, p.raw_keyword()); + WriteParam(m, p.autogenerate_keyword()); + WriteParam(m, p.url()); + WriteParam(m, p.suggestions_url); + WriteParam(m, p.instant_url); + WriteParam(m, p.favicon_url); + WriteParam(m, p.originating_url); + WriteParam(m, p.show_in_default_list); + WriteParam(m, p.safe_for_autoreplace); + WriteParam(m, p.input_encodings); + WriteParam(m, p.id); + WriteParam(m, p.date_created); + WriteParam(m, p.last_modified); + WriteParam(m, p.created_by_policy); + WriteParam(m, p.usage_count); + WriteParam(m, p.prepopulate_id); + WriteParam(m, p.sync_guid); + } + static bool Read(const Message* m, PickleIterator* iter, param_type* p) { + string16 keyword; + bool autogenerate_keyword; + std::string url; + if (!ReadParam(m, iter, &p->short_name) || + !ReadParam(m, iter, &keyword) || + !ReadParam(m, iter, &autogenerate_keyword) || + !ReadParam(m, iter, &url) || + !ReadParam(m, iter, &p->suggestions_url) || + !ReadParam(m, iter, &p->instant_url) || + !ReadParam(m, iter, &p->favicon_url) || + !ReadParam(m, iter, &p->originating_url) || + !ReadParam(m, iter, &p->show_in_default_list) || + !ReadParam(m, iter, &p->safe_for_autoreplace) || + !ReadParam(m, iter, &p->input_encodings) || + !ReadParam(m, iter, &p->id) || + !ReadParam(m, iter, &p->date_created) || + !ReadParam(m, iter, &p->last_modified) || + !ReadParam(m, iter, &p->created_by_policy) || + !ReadParam(m, iter, &p->usage_count) || + !ReadParam(m, iter, &p->prepopulate_id) || + !ReadParam(m, iter, &p->sync_guid)) + return false; + p->SetKeyword(keyword); + p->SetAutogenerateKeyword(autogenerate_keyword); + p->SetURL(url); + return true; + } + static void Log(const param_type& p, std::string* l) { + l->append("<TemplateURLData>"); + } +}; + // Traits for TemplateURL*. // WARNING: These will cause us to allocate a new TemplateURL on the heap on the // receiver side. Any messages using this type must have handlers that are @@ -198,67 +255,13 @@ template <> struct ParamTraits<TemplateURL*> { typedef TemplateURL* param_type; static void Write(Message* m, const param_type& p) { - WriteParam(m, p->short_name()); - WriteParam(m, p->url()); - WriteParam(m, p->suggestions_url()); - WriteParam(m, p->instant_url()); - WriteParam(m, p->originating_url()); - WriteParam(m, p->keyword()); - WriteParam(m, p->autogenerate_keyword()); - WriteParam(m, p->show_in_default_list()); - WriteParam(m, p->safe_for_autoreplace()); - WriteParam(m, p->favicon_url()); - WriteParam(m, p->input_encodings()); - WriteParam(m, p->date_created()); - WriteParam(m, p->last_modified()); - WriteParam(m, p->usage_count()); - WriteParam(m, p->prepopulate_id()); + WriteParam(m, p->data()); } static bool Read(const Message* m, PickleIterator* iter, param_type* p) { - string16 short_name; - std::string url; - std::string suggestions_url; - std::string instant_url; - GURL originating_url; - string16 keyword; - bool autogenerate_keyword; - bool show_in_default_list; - bool safe_for_autoreplace; - GURL favicon_url; - base::Time date_created; - base::Time last_modified; - int usage_count; - int prepopulate_id; - if (!ReadParam(m, iter, &short_name) || - !ReadParam(m, iter, &url) || - !ReadParam(m, iter, &suggestions_url) || - !ReadParam(m, iter, &instant_url) || - !ReadParam(m, iter, &originating_url) || - !ReadParam(m, iter, &keyword) || - !ReadParam(m, iter, &autogenerate_keyword) || - !ReadParam(m, iter, &show_in_default_list) || - !ReadParam(m, iter, &safe_for_autoreplace) || - !ReadParam(m, iter, &favicon_url) || - !ReadParam(m, iter, &date_created) || - !ReadParam(m, iter, &last_modified) || - !ReadParam(m, iter, &usage_count) || - !ReadParam(m, iter, &prepopulate_id)) + TemplateURLData data; + if (!ReadParam(m, iter, &data)) return false; - *p = new TemplateURL(); - (*p)->set_short_name(short_name); - (*p)->SetURL(url); - (*p)->SetSuggestionsURL(suggestions_url); - (*p)->SetInstantURL(suggestions_url); - (*p)->set_originating_url(originating_url); - (*p)->set_keyword(keyword); - (*p)->set_autogenerate_keyword(autogenerate_keyword); - (*p)->set_show_in_default_list(show_in_default_list); - (*p)->set_safe_for_autoreplace(safe_for_autoreplace); - (*p)->set_favicon_url(favicon_url); - (*p)->set_date_created(date_created); - (*p)->set_last_modified(last_modified); - (*p)->set_usage_count(usage_count); - (*p)->SetPrepopulateId(prepopulate_id); + *p = new TemplateURL(data); return true; } static void Log(const param_type& p, std::string* l) { |