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

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

Issue 9968007: [protector] Support for collapsing multiple changes into a single one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge Created 8 years, 8 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 virtual void Apply(Browser* browser) OVERRIDE; 90 virtual void Apply(Browser* browser) OVERRIDE;
91 virtual void Discard(Browser* browser) OVERRIDE; 91 virtual void Discard(Browser* browser) OVERRIDE;
92 virtual void Timeout() OVERRIDE; 92 virtual void Timeout() OVERRIDE;
93 virtual int GetBadgeIconID() const OVERRIDE; 93 virtual int GetBadgeIconID() const OVERRIDE;
94 virtual int GetMenuItemIconID() const OVERRIDE; 94 virtual int GetMenuItemIconID() const OVERRIDE;
95 virtual int GetBubbleIconID() const OVERRIDE; 95 virtual int GetBubbleIconID() const OVERRIDE;
96 virtual string16 GetBubbleTitle() const OVERRIDE; 96 virtual string16 GetBubbleTitle() const OVERRIDE;
97 virtual string16 GetBubbleMessage() const OVERRIDE; 97 virtual string16 GetBubbleMessage() const OVERRIDE;
98 virtual string16 GetApplyButtonText() const OVERRIDE; 98 virtual string16 GetApplyButtonText() const OVERRIDE;
99 virtual string16 GetDiscardButtonText() const OVERRIDE; 99 virtual string16 GetDiscardButtonText() const OVERRIDE;
100 virtual DisplayName GetApplyDisplayName() const OVERRIDE;
101 virtual GURL GetNewSettingURL() const OVERRIDE;
100 102
101 private: 103 private:
102 virtual ~DefaultSearchProviderChange(); 104 virtual ~DefaultSearchProviderChange();
103 105
104 // TemplateURLServiceObserver overrides: 106 // TemplateURLServiceObserver overrides:
105 virtual void OnTemplateURLServiceChanged() OVERRIDE; 107 virtual void OnTemplateURLServiceChanged() OVERRIDE;
106 108
107 // content::NotificationObserver overrides: 109 // content::NotificationObserver overrides:
108 virtual void Observe(int type, 110 virtual void Observe(int type,
109 const content::NotificationSource& source, 111 const content::NotificationSource& source,
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 if (!is_fallback_) { 317 if (!is_fallback_) {
316 string16 name = default_search_provider_->short_name(); 318 string16 name = default_search_provider_->short_name();
317 return (name.length() > kMaxDisplayedNameLength) ? 319 return (name.length() > kMaxDisplayedNameLength) ?
318 l10n_util::GetStringUTF16(IDS_KEEP_SETTING) : 320 l10n_util::GetStringUTF16(IDS_KEEP_SETTING) :
319 l10n_util::GetStringFUTF16(IDS_KEEP_SEARCH_ENGINE, name); 321 l10n_util::GetStringFUTF16(IDS_KEEP_SEARCH_ENGINE, name);
320 } 322 }
321 // Old setting is lost, offer to go to settings. 323 // Old setting is lost, offer to go to settings.
322 return l10n_util::GetStringUTF16(IDS_SELECT_SEARCH_ENGINE); 324 return l10n_util::GetStringUTF16(IDS_SELECT_SEARCH_ENGINE);
323 } 325 }
324 326
327 BaseSettingChange::DisplayName
328 DefaultSearchProviderChange::GetApplyDisplayName() const {
329 if (new_search_provider_ &&
330 new_search_provider_->short_name().length() <= kMaxDisplayedNameLength) {
331 return DisplayName(kDefaultSearchProviderChangeNamePriority,
332 new_search_provider_->short_name());
333 }
334 // Return the default empty name.
335 return BaseSettingChange::GetApplyDisplayName();
336 }
337
338 GURL DefaultSearchProviderChange::GetNewSettingURL() const {
339 if (is_fallback_) {
340 // Do not collide this change when fallback was made, since the message
341 // and Discard behaviour is pretty different.
342 return GURL();
343 }
344 if (!new_search_provider_)
345 return GURL();
346 return TemplateURLService::GenerateSearchURL(new_search_provider_);
347 }
348
325 void DefaultSearchProviderChange::OnTemplateURLServiceChanged() { 349 void DefaultSearchProviderChange::OnTemplateURLServiceChanged() {
326 TemplateURLService* url_service = GetTemplateURLService(); 350 TemplateURLService* url_service = GetTemplateURLService();
327 if (url_service->GetDefaultSearchProvider() != default_search_provider_) { 351 if (url_service->GetDefaultSearchProvider() != default_search_provider_) {
328 VLOG(1) << "Default search provider has been changed by user"; 352 VLOG(1) << "Default search provider has been changed by user";
329 default_search_provider_ = NULL; 353 default_search_provider_ = NULL;
330 url_service->RemoveObserver(this); 354 url_service->RemoveObserver(this);
331 // Will delete this DefaultSearchProviderChange instance. 355 // Will delete this DefaultSearchProviderChange instance.
332 ProtectorServiceFactory::GetForProfile(profile())->DismissChange(this); 356 ProtectorServiceFactory::GetForProfile(profile())->DismissChange(this);
333 } 357 }
334 } 358 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 DCHECK(url_service); 415 DCHECK(url_service);
392 return url_service; 416 return url_service;
393 } 417 }
394 418
395 BaseSettingChange* CreateDefaultSearchProviderChange(const TemplateURL* actual, 419 BaseSettingChange* CreateDefaultSearchProviderChange(const TemplateURL* actual,
396 TemplateURL* backup) { 420 TemplateURL* backup) {
397 return new DefaultSearchProviderChange(actual, backup); 421 return new DefaultSearchProviderChange(actual, backup);
398 } 422 }
399 423
400 } // namespace protector 424 } // namespace protector
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698