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

Side by Side Diff: chrome/browser/importer/importer.cc

Issue 4281: Fixes bug in importer where we could set the default search provider... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/importer/firefox_importer_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/importer/importer.h" 5 #include "chrome/browser/importer/importer.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/gfx/image_operations.h" 10 #include "base/gfx/image_operations.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 132 }
133 133
134 void ProfileWriter::AddFavicons( 134 void ProfileWriter::AddFavicons(
135 const std::vector<history::ImportedFavIconUsage>& favicons) { 135 const std::vector<history::ImportedFavIconUsage>& favicons) {
136 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS)-> 136 profile_->GetHistoryService(Profile::EXPLICIT_ACCESS)->
137 SetImportedFavicons(favicons); 137 SetImportedFavicons(favicons);
138 } 138 }
139 139
140 typedef std::map<std::string, const TemplateURL*> HostPathMap; 140 typedef std::map<std::string, const TemplateURL*> HostPathMap;
141 141
142 // Returns the key for the map built by BuildHostPathMap. If url_string is not
143 // a valid URL, an empty string is returned, otherwise host+path is returned.
144 static std::string HostPathKeyForURL(const std::wstring& url_string) {
145 GURL url(url_string);
146 return url.is_valid() ? url.host() + url.path() : std::string();
147 }
148
142 // Builds the key to use in HostPathMap for the specified TemplateURL. Returns 149 // Builds the key to use in HostPathMap for the specified TemplateURL. Returns
143 // an empty string if a host+path can't be generated for the TemplateURL. 150 // an empty string if a host+path can't be generated for the TemplateURL.
144 // If an empty string is returned, it should not be added to HostPathMap. 151 // If an empty string is returned, the TemplateURL should not be added to
145 static std::string BuildHostPathKey(const TemplateURL* t_url) { 152 // HostPathMap.
146 if (t_url->url() && t_url->url()->SupportsReplacement()) { 153 //
147 GURL search_url(t_url->url()->ReplaceSearchTerms( 154 // If |try_url_if_invalid| is true, and |t_url| isn't valid, a string is built
148 *t_url, L"random string", TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, 155 // from the raw TemplateURL string. Use a value of true for |try_url_if_invalid|
149 std::wstring())); 156 // when checking imported URLs as the imported URL may not be valid yet may
150 if (search_url.is_valid()) 157 // match the host+path of one of the default URLs. This is used to catch the
151 return search_url.host() + search_url.path(); 158 // case of IE using an invalid OSDD URL for Live Search, yet the host+path
159 // matches our prepopulate data. IE's URL for Live Search is something like
160 // 'http://...{Language}...'. As {Language} is not a valid OSDD parameter value
161 // the TemplateURL is invalid.
Peter Kasting 2008/09/25 23:44:19 Thanks for this comment, it helps. It might be ev
162 static std::string BuildHostPathKey(const TemplateURL* t_url,
163 bool try_url_if_invalid) {
164 if (t_url->url()) {
165 if (try_url_if_invalid && !t_url->url()->IsValid())
166 return HostPathKeyForURL(t_url->url()->url());
167
168 if (t_url->url()->SupportsReplacement()) {
169 return HostPathKeyForURL(
170 t_url->url()->ReplaceSearchTerms(
171 *t_url, L"random string",
172 TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()));
173 }
152 } 174 }
153 return std::string(); 175 return std::string();
154 } 176 }
155 177
156 // Builds a set that contains an entry of the host+path for each TemplateURL in 178 // Builds a set that contains an entry of the host+path for each TemplateURL in
157 // the TemplateURLModel that has a valid search url. 179 // the TemplateURLModel that has a valid search url.
158 static void BuildHostPathMap(const TemplateURLModel& model, 180 static void BuildHostPathMap(const TemplateURLModel& model,
159 HostPathMap* host_path_map) { 181 HostPathMap* host_path_map) {
160 std::vector<const TemplateURL*> template_urls = model.GetTemplateURLs(); 182 std::vector<const TemplateURL*> template_urls = model.GetTemplateURLs();
161 for (size_t i = 0; i < template_urls.size(); ++i) { 183 for (size_t i = 0; i < template_urls.size(); ++i) {
162 const std::string host_path = BuildHostPathKey(template_urls[i]); 184 const std::string host_path = BuildHostPathKey(template_urls[i], false);
163 if (!host_path.empty()) { 185 if (!host_path.empty()) {
164 const TemplateURL* existing_turl = (*host_path_map)[host_path]; 186 const TemplateURL* existing_turl = (*host_path_map)[host_path];
165 if (!existing_turl || 187 if (!existing_turl ||
166 (template_urls[i]->show_in_default_list() && 188 (template_urls[i]->show_in_default_list() &&
167 !existing_turl->show_in_default_list())) { 189 !existing_turl->show_in_default_list())) {
168 // If there are multiple TemplateURLs with the same host+path, favor 190 // If there are multiple TemplateURLs with the same host+path, favor
169 // those shown in the default list. If there are multiple potential 191 // those shown in the default list. If there are multiple potential
170 // defaults, favor the first one, which should be the more commonly used 192 // defaults, favor the first one, which should be the more commonly used
171 // one. 193 // one.
172 (*host_path_map)[host_path] = template_urls[i]; 194 (*host_path_map)[host_path] = template_urls[i];
(...skipping 28 matching lines...) Expand all
201 delete t_url; 223 delete t_url;
202 continue; 224 continue;
203 } 225 }
204 226
205 // For search engines if there is already a keyword with the same 227 // For search engines if there is already a keyword with the same
206 // host+path, we don't import it. This is done to avoid both duplicate 228 // host+path, we don't import it. This is done to avoid both duplicate
207 // search providers (such as two Googles, or two Yahoos) as well as making 229 // search providers (such as two Googles, or two Yahoos) as well as making
208 // sure the search engines we provide aren't replaced by those from the 230 // sure the search engines we provide aren't replaced by those from the
209 // imported browser. 231 // imported browser.
210 if (unique_on_host_and_path && 232 if (unique_on_host_and_path &&
211 host_path_map.find(BuildHostPathKey(t_url)) != host_path_map.end()) { 233 host_path_map.find(
234 BuildHostPathKey(t_url, true)) != host_path_map.end()) {
212 if (default_keyword) { 235 if (default_keyword) {
213 const TemplateURL* turl_with_host_path = 236 const TemplateURL* turl_with_host_path =
214 host_path_map[BuildHostPathKey(t_url)]; 237 host_path_map[BuildHostPathKey(t_url, true)];
215 if (turl_with_host_path) 238 if (turl_with_host_path)
216 model->SetDefaultSearchProvider(turl_with_host_path); 239 model->SetDefaultSearchProvider(turl_with_host_path);
217 else 240 else
218 NOTREACHED(); // BuildHostPathMap should only insert non-null values. 241 NOTREACHED(); // BuildHostPathMap should only insert non-null values.
219 } 242 }
220 delete t_url; 243 delete t_url;
221 continue; 244 continue;
222 } 245 }
223 model->Add(t_url); 246 if (t_url->url() && t_url->url()->IsValid()) {
224 if (default_keyword) 247 model->Add(t_url);
225 model->SetDefaultSearchProvider(t_url); 248 if (default_keyword && t_url->url() && t_url->url()->SupportsReplacement() )
249 model->SetDefaultSearchProvider(t_url);
250 } else {
251 // Don't add invalid TemplateURLs to the model.
252 delete t_url;
253 }
226 } 254 }
227 } 255 }
228 256
229 void ProfileWriter::ShowBookmarkBar() { 257 void ProfileWriter::ShowBookmarkBar() {
230 DCHECK(profile_); 258 DCHECK(profile_);
231 259
232 PrefService* prefs = profile_->GetPrefs(); 260 PrefService* prefs = profile_->GetPrefs();
233 // Check whether the bookmark bar is shown in current pref. 261 // Check whether the bookmark bar is shown in current pref.
234 if (!prefs->GetBoolean(prefs::kShowBookmarkBar)) { 262 if (!prefs->GetBoolean(prefs::kShowBookmarkBar)) {
235 // Set the pref and notify the notification service. 263 // Set the pref and notify the notification service.
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
532 if (!source_path.empty()) { 560 if (!source_path.empty()) {
533 ProfileInfo* firefox = new ProfileInfo(); 561 ProfileInfo* firefox = new ProfileInfo();
534 firefox->description = l10n_util::GetString(IDS_IMPORT_FROM_FIREFOX); 562 firefox->description = l10n_util::GetString(IDS_IMPORT_FROM_FIREFOX);
535 firefox->browser_type = firefox_type; 563 firefox->browser_type = firefox_type;
536 firefox->source_path = source_path; 564 firefox->source_path = source_path;
537 firefox->app_path = GetFirefoxInstallPath(); 565 firefox->app_path = GetFirefoxInstallPath();
538 source_profiles_.push_back(firefox); 566 source_profiles_.push_back(firefox);
539 } 567 }
540 } 568 }
541 569
OLDNEW
« no previous file with comments | « chrome/browser/importer/firefox_importer_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698