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

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

Issue 9701037: Misc. protector cleanup: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 <algorithm> 5 #include <algorithm>
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 279
280 int DefaultSearchProviderChange::GetBubbleIconID() const { 280 int DefaultSearchProviderChange::GetBubbleIconID() const {
281 return IDR_SEARCH_ENGINE_CHANGE_ALERT; 281 return IDR_SEARCH_ENGINE_CHANGE_ALERT;
282 } 282 }
283 283
284 string16 DefaultSearchProviderChange::GetBubbleTitle() const { 284 string16 DefaultSearchProviderChange::GetBubbleTitle() const {
285 return l10n_util::GetStringUTF16(IDS_SEARCH_ENGINE_CHANGE_TITLE); 285 return l10n_util::GetStringUTF16(IDS_SEARCH_ENGINE_CHANGE_TITLE);
286 } 286 }
287 287
288 string16 DefaultSearchProviderChange::GetBubbleMessage() const { 288 string16 DefaultSearchProviderChange::GetBubbleMessage() const {
289 if (!is_fallback_) { 289 if (is_fallback_) {
290 return l10n_util::GetStringUTF16(IDS_SEARCH_ENGINE_CHANGE_MESSAGE);
291 } else {
292 return l10n_util::GetStringFUTF16( 290 return l10n_util::GetStringFUTF16(
293 IDS_SEARCH_ENGINE_CHANGE_NO_BACKUP_MESSAGE, 291 IDS_SEARCH_ENGINE_CHANGE_NO_BACKUP_MESSAGE,
294 default_search_provider_->short_name()); 292 default_search_provider_->short_name());
295 } 293 }
294 return l10n_util::GetStringUTF16(IDS_SEARCH_ENGINE_CHANGE_MESSAGE);
296 } 295 }
297 296
298 string16 DefaultSearchProviderChange::GetApplyButtonText() const { 297 string16 DefaultSearchProviderChange::GetApplyButtonText() const {
299 if (new_search_provider_) { 298 if (new_search_provider_) {
300 // If backup search engine is lost and fallback was made to the current 299 // If backup search engine is lost and fallback was made to the current
301 // search provider then there is no need to show this button. 300 // search provider then there is no need to show this button.
302 if (fallback_is_new_) 301 if (fallback_is_new_)
303 return string16(); 302 return string16();
304 string16 name = new_search_provider_->short_name(); 303 string16 name = new_search_provider_->short_name();
305 if (name.length() > kMaxDisplayedNameLength) 304 return (name.length() > kMaxDisplayedNameLength) ?
306 return l10n_util::GetStringUTF16(IDS_CHANGE_SEARCH_ENGINE_NO_NAME); 305 l10n_util::GetStringUTF16(IDS_CHANGE_SEARCH_ENGINE_NO_NAME) :
307 else 306 l10n_util::GetStringFUTF16(IDS_CHANGE_SEARCH_ENGINE, name);
308 return l10n_util::GetStringFUTF16(IDS_CHANGE_SEARCH_ENGINE, name); 307 }
309 } else if (!is_fallback_) { 308 if (is_fallback_) {
310 // New setting is lost, offer to go to settings.
311 return l10n_util::GetStringUTF16(IDS_SELECT_SEARCH_ENGINE);
312 } else {
313 // Both settings are lost: don't show this button. 309 // Both settings are lost: don't show this button.
314 return string16(); 310 return string16();
315 } 311 }
312 // New setting is lost, offer to go to settings.
313 return l10n_util::GetStringUTF16(IDS_SELECT_SEARCH_ENGINE);
316 } 314 }
317 315
318 string16 DefaultSearchProviderChange::GetDiscardButtonText() const { 316 string16 DefaultSearchProviderChange::GetDiscardButtonText() const {
319 if (!is_fallback_) { 317 if (!is_fallback_) {
320 string16 name = default_search_provider_->short_name(); 318 string16 name = default_search_provider_->short_name();
321 if (name.length() > kMaxDisplayedNameLength) 319 return (name.length() > kMaxDisplayedNameLength) ?
322 return l10n_util::GetStringUTF16(IDS_KEEP_SETTING); 320 l10n_util::GetStringUTF16(IDS_KEEP_SETTING) :
323 else 321 l10n_util::GetStringFUTF16(IDS_KEEP_SEARCH_ENGINE, name);
324 return l10n_util::GetStringFUTF16(IDS_KEEP_SEARCH_ENGINE, name);
325 } else {
326 // Old setting is lost, offer to go to settings.
327 return l10n_util::GetStringUTF16(IDS_SELECT_SEARCH_ENGINE);
328 } 322 }
323 // Old setting is lost, offer to go to settings.
324 return l10n_util::GetStringUTF16(IDS_SELECT_SEARCH_ENGINE);
329 } 325 }
330 326
331 void DefaultSearchProviderChange::OnTemplateURLServiceChanged() { 327 void DefaultSearchProviderChange::OnTemplateURLServiceChanged() {
332 TemplateURLService* url_service = GetTemplateURLService(); 328 TemplateURLService* url_service = GetTemplateURLService();
333 if (url_service->GetDefaultSearchProvider() != default_search_provider_) { 329 if (url_service->GetDefaultSearchProvider() != default_search_provider_) {
334 VLOG(1) << "Default search provider has been changed by user"; 330 VLOG(1) << "Default search provider has been changed by user";
335 default_search_provider_ = NULL; 331 default_search_provider_ = NULL;
336 url_service->RemoveObserver(this); 332 url_service->RemoveObserver(this);
337 // Will delete this DefaultSearchProviderChange instance. 333 // Will delete this DefaultSearchProviderChange instance.
338 ProtectorServiceFactory::GetForProfile(profile())->DismissChange(this); 334 ProtectorServiceFactory::GetForProfile(profile())->DismissChange(this);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 chrome::kSearchEnginesSubPage), browser); 387 chrome::kSearchEnginesSubPage), browser);
392 } 388 }
393 389
394 TemplateURLService* DefaultSearchProviderChange::GetTemplateURLService() { 390 TemplateURLService* DefaultSearchProviderChange::GetTemplateURLService() {
395 TemplateURLService* url_service = 391 TemplateURLService* url_service =
396 TemplateURLServiceFactory::GetForProfile(profile()); 392 TemplateURLServiceFactory::GetForProfile(profile());
397 DCHECK(url_service); 393 DCHECK(url_service);
398 return url_service; 394 return url_service;
399 } 395 }
400 396
401 BaseSettingChange* CreateDefaultSearchProviderChange( 397 BaseSettingChange* CreateDefaultSearchProviderChange(const TemplateURL* actual,
402 const TemplateURL* actual, 398 TemplateURL* backup) {
403 TemplateURL* backup) {
404 return new DefaultSearchProviderChange(actual, backup); 399 return new DefaultSearchProviderChange(actual, backup);
405 } 400 }
406 401
407 } // namespace protector 402 } // namespace protector
OLDNEW
« no previous file with comments | « chrome/browser/protector/base_setting_change.h ('k') | chrome/browser/protector/default_search_provider_change_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698