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

Side by Side Diff: chrome/browser/protector/default_search_provider_change.cc

Issue 8954014: Protector: separate handling for several cases. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/compiler_specific.h" 6 #include "base/compiler_specific.h"
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "chrome/browser/protector/base_setting_change.h" 10 #include "chrome/browser/protector/base_setting_change.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 AreKeywordsSame(url, other_) && 61 AreKeywordsSame(url, other_) &&
62 TemplateURLRef::SameUrlRefs(url->url(), other_->url()) && 62 TemplateURLRef::SameUrlRefs(url->url(), other_->url()) &&
63 TemplateURLRef::SameUrlRefs(url->suggestions_url(), 63 TemplateURLRef::SameUrlRefs(url->suggestions_url(),
64 other_->suggestions_url()) && 64 other_->suggestions_url()) &&
65 TemplateURLRef::SameUrlRefs(url->instant_url(), 65 TemplateURLRef::SameUrlRefs(url->instant_url(),
66 other_->instant_url()) && 66 other_->instant_url()) &&
67 url->GetFaviconURL() == other_->GetFaviconURL() && 67 url->GetFaviconURL() == other_->GetFaviconURL() &&
68 url->safe_for_autoreplace() == other_->safe_for_autoreplace() && 68 url->safe_for_autoreplace() == other_->safe_for_autoreplace() &&
69 url->show_in_default_list() == other_->show_in_default_list() && 69 url->show_in_default_list() == other_->show_in_default_list() &&
70 url->input_encodings() == other_->input_encodings() && 70 url->input_encodings() == other_->input_encodings() &&
71 url->logo_id() == other_->logo_id() &&
72 url->prepopulate_id() == other_->prepopulate_id(); 71 url->prepopulate_id() == other_->prepopulate_id();
73 } 72 }
74 73
75 private: 74 private:
76 // Returns true if both |url1| and |url2| have autogenerated keywords 75 // Returns true if both |url1| and |url2| have autogenerated keywords
77 // or if their keywords are identical. 76 // or if their keywords are identical.
78 bool AreKeywordsSame(const TemplateURL* url1, const TemplateURL* url2) { 77 bool AreKeywordsSame(const TemplateURL* url1, const TemplateURL* url2) {
79 return (url1->autogenerate_keyword() && url2->autogenerate_keyword()) || 78 return (url1->autogenerate_keyword() && url2->autogenerate_keyword()) ||
80 url1->keyword() == url2->keyword(); 79 url1->keyword() == url2->keyword();
81 } 80 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 new_histogram_id_(GetSearchProviderHistogramID(new_url)), 149 new_histogram_id_(GetSearchProviderHistogramID(new_url)),
151 default_search_provider_(NULL) { 150 default_search_provider_(NULL) {
152 if (new_url) { 151 if (new_url) {
153 new_id_ = new_url->id(); 152 new_id_ = new_url->id();
154 new_name_ = new_url->short_name(); 153 new_name_ = new_url->short_name();
155 } 154 }
156 if (old_url) { 155 if (old_url) {
157 old_id_ = old_url->id(); 156 old_id_ = old_url->id();
158 old_name_ = old_url->short_name(); 157 old_name_ = old_url->short_name();
159 } 158 }
159 if (old_id_ == new_id_) {
160 // This means someone has tampered with the search providers list but not
161 // with the ID. Old ID is useless in this case so the prepopulated default
162 // search provider will be used.
163 old_id_ = 0;
164 // TODO(ivankr): restore the default search provider from the backup table.
165 }
160 } 166 }
161 167
162 DefaultSearchProviderChange::~DefaultSearchProviderChange() { 168 DefaultSearchProviderChange::~DefaultSearchProviderChange() {
163 } 169 }
164 170
165 bool DefaultSearchProviderChange::Init(Protector* protector) { 171 bool DefaultSearchProviderChange::Init(Protector* protector) {
166 BaseSettingChange::Init(protector); 172 BaseSettingChange::Init(protector);
167 173
168 UMA_HISTOGRAM_ENUMERATION( 174 UMA_HISTOGRAM_ENUMERATION(
169 kProtectorHistogramNewSearchProvider, 175 kProtectorHistogramNewSearchProvider,
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 IDS_SEARCH_ENGINE_CHANGE_NO_BACKUP_MESSAGE, fallback_name_); 271 IDS_SEARCH_ENGINE_CHANGE_NO_BACKUP_MESSAGE, fallback_name_);
266 } 272 }
267 273
268 string16 DefaultSearchProviderChange::GetApplyButtonText() const { 274 string16 DefaultSearchProviderChange::GetApplyButtonText() const {
269 if (new_id_) { 275 if (new_id_) {
270 if (new_id_ == fallback_id_) { 276 if (new_id_ == fallback_id_) {
271 // Old search engine is lost, the fallback search engine is the same as 277 // Old search engine is lost, the fallback search engine is the same as
272 // the new one so no need to show this button. 278 // the new one so no need to show this button.
273 return string16(); 279 return string16();
274 } 280 }
281 if (!new_name_.empty() &&
282 new_name_ == fallback_name_) {
283 // The fallback and new search engines have the same name but different
284 // IDs, which most likely is some fraud attempt, so don't suggest to
285 // apply the new setting.
286 return string16();
287 }
275 if (new_name_.length() > kMaxDisplayedNameLength) 288 if (new_name_.length() > kMaxDisplayedNameLength)
276 return l10n_util::GetStringUTF16(IDS_CHANGE_SEARCH_ENGINE_NO_NAME); 289 return l10n_util::GetStringUTF16(IDS_CHANGE_SEARCH_ENGINE_NO_NAME);
277 else 290 else
278 return l10n_util::GetStringFUTF16(IDS_CHANGE_SEARCH_ENGINE, new_name_); 291 return l10n_util::GetStringFUTF16(IDS_CHANGE_SEARCH_ENGINE, new_name_);
279 } else if (old_id_) { 292 } else if (old_id_) {
280 // New setting is lost, offer to go to settings. 293 // New setting is lost, offer to go to settings.
281 return l10n_util::GetStringUTF16(IDS_SELECT_SEARCH_ENGINE); 294 return l10n_util::GetStringUTF16(IDS_SELECT_SEARCH_ENGINE);
282 } else { 295 } else {
283 // Both settings are lost: don't show this button. 296 // Both settings are lost: don't show this button.
284 return string16(); 297 return string16();
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 chrome::kSearchEnginesSubPage)); 378 chrome::kSearchEnginesSubPage));
366 } 379 }
367 380
368 BaseSettingChange* CreateDefaultSearchProviderChange( 381 BaseSettingChange* CreateDefaultSearchProviderChange(
369 const TemplateURL* actual, 382 const TemplateURL* actual,
370 const TemplateURL* backup) { 383 const TemplateURL* backup) {
371 return new DefaultSearchProviderChange(backup, actual); 384 return new DefaultSearchProviderChange(backup, actual);
372 } 385 }
373 386
374 } // namespace protector 387 } // namespace protector
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698