Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 20 matching lines...) Expand all Loading... | |
| 31 #include "grit/theme_resources.h" | 31 #include "grit/theme_resources.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 33 | 33 |
| 34 namespace protector { | 34 namespace protector { |
| 35 | 35 |
| 36 namespace { | 36 namespace { |
| 37 | 37 |
| 38 // Maximum length of the search engine name to be displayed. | 38 // Maximum length of the search engine name to be displayed. |
| 39 const size_t kMaxDisplayedNameLength = 16; | 39 const size_t kMaxDisplayedNameLength = 16; |
| 40 | 40 |
| 41 // Priority for the display name. | |
| 42 const size_t kNamePriority = 100U; | |
| 43 | |
| 41 // Matches TemplateURL with all fields set from the prepopulated data equal | 44 // Matches TemplateURL with all fields set from the prepopulated data equal |
| 42 // to fields in another TemplateURL. | 45 // to fields in another TemplateURL. |
| 43 class TemplateURLIsSame { | 46 class TemplateURLIsSame { |
| 44 public: | 47 public: |
| 45 // Creates a matcher based on |other|. | 48 // Creates a matcher based on |other|. |
| 46 explicit TemplateURLIsSame(const TemplateURL* other) : other_(other) { | 49 explicit TemplateURLIsSame(const TemplateURL* other) : other_(other) { |
| 47 } | 50 } |
| 48 | 51 |
| 49 // Returns true if both |other| and |url| are NULL or have same field values. | 52 // Returns true if both |other| and |url| are NULL or have same field values. |
| 50 bool operator()(const TemplateURL* url) { | 53 bool operator()(const TemplateURL* url) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 virtual void Apply(Browser* browser) OVERRIDE; | 93 virtual void Apply(Browser* browser) OVERRIDE; |
| 91 virtual void Discard(Browser* browser) OVERRIDE; | 94 virtual void Discard(Browser* browser) OVERRIDE; |
| 92 virtual void Timeout() OVERRIDE; | 95 virtual void Timeout() OVERRIDE; |
| 93 virtual int GetBadgeIconID() const OVERRIDE; | 96 virtual int GetBadgeIconID() const OVERRIDE; |
| 94 virtual int GetMenuItemIconID() const OVERRIDE; | 97 virtual int GetMenuItemIconID() const OVERRIDE; |
| 95 virtual int GetBubbleIconID() const OVERRIDE; | 98 virtual int GetBubbleIconID() const OVERRIDE; |
| 96 virtual string16 GetBubbleTitle() const OVERRIDE; | 99 virtual string16 GetBubbleTitle() const OVERRIDE; |
| 97 virtual string16 GetBubbleMessage() const OVERRIDE; | 100 virtual string16 GetBubbleMessage() const OVERRIDE; |
| 98 virtual string16 GetApplyButtonText() const OVERRIDE; | 101 virtual string16 GetApplyButtonText() const OVERRIDE; |
| 99 virtual string16 GetDiscardButtonText() const OVERRIDE; | 102 virtual string16 GetDiscardButtonText() const OVERRIDE; |
| 103 virtual DisplayName GetApplyDisplayName() const OVERRIDE; | |
| 104 virtual std::string GetApplyKeyword() const OVERRIDE; | |
| 100 | 105 |
| 101 private: | 106 private: |
| 102 virtual ~DefaultSearchProviderChange(); | 107 virtual ~DefaultSearchProviderChange(); |
| 103 | 108 |
| 104 // TemplateURLServiceObserver overrides: | 109 // TemplateURLServiceObserver overrides: |
| 105 virtual void OnTemplateURLServiceChanged() OVERRIDE; | 110 virtual void OnTemplateURLServiceChanged() OVERRIDE; |
| 106 | 111 |
| 107 // content::NotificationObserver overrides: | 112 // content::NotificationObserver overrides: |
| 108 virtual void Observe(int type, | 113 virtual void Observe(int type, |
| 109 const content::NotificationSource& source, | 114 const content::NotificationSource& source, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 141 const TemplateURL* new_search_provider_; | 146 const TemplateURL* new_search_provider_; |
| 142 // Default search provider set by Init for the period until user makes a | 147 // Default search provider set by Init for the period until user makes a |
| 143 // choice and either Apply or Discard is performed. Never is |NULL| during | 148 // choice and either Apply or Discard is performed. Never is |NULL| during |
| 144 // that period since the change will dismiss itself if this provider gets | 149 // that period since the change will dismiss itself if this provider gets |
| 145 // deleted or stops being the default. | 150 // deleted or stops being the default. |
| 146 const TemplateURL* default_search_provider_; | 151 const TemplateURL* default_search_provider_; |
| 147 // Stores backup of the default search until it becomes owned by the | 152 // Stores backup of the default search until it becomes owned by the |
| 148 // TemplateURLService or deleted. | 153 // TemplateURLService or deleted. |
| 149 scoped_ptr<TemplateURL> backup_search_provider_; | 154 scoped_ptr<TemplateURL> backup_search_provider_; |
| 150 content::NotificationRegistrar registrar_; | 155 content::NotificationRegistrar registrar_; |
| 151 | |
|
whywhat
2012/04/06 16:28:32
Could you, please, leave the blank line?
Ivan Korotkov
2012/04/09 14:46:47
Done.
| |
| 152 DISALLOW_COPY_AND_ASSIGN(DefaultSearchProviderChange); | 156 DISALLOW_COPY_AND_ASSIGN(DefaultSearchProviderChange); |
| 153 }; | 157 }; |
| 154 | 158 |
| 155 DefaultSearchProviderChange::DefaultSearchProviderChange( | 159 DefaultSearchProviderChange::DefaultSearchProviderChange( |
| 156 const TemplateURL* new_search_provider, | 160 const TemplateURL* new_search_provider, |
| 157 TemplateURL* backup_search_provider) | 161 TemplateURL* backup_search_provider) |
| 158 : new_histogram_id_(GetSearchProviderHistogramID(new_search_provider)), | 162 : new_histogram_id_(GetSearchProviderHistogramID(new_search_provider)), |
| 159 is_fallback_(false), | 163 is_fallback_(false), |
| 160 fallback_is_new_(false), | 164 fallback_is_new_(false), |
| 161 new_search_provider_(new_search_provider), | 165 new_search_provider_(new_search_provider), |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 if (!is_fallback_) { | 319 if (!is_fallback_) { |
| 316 string16 name = default_search_provider_->short_name(); | 320 string16 name = default_search_provider_->short_name(); |
| 317 return (name.length() > kMaxDisplayedNameLength) ? | 321 return (name.length() > kMaxDisplayedNameLength) ? |
| 318 l10n_util::GetStringUTF16(IDS_KEEP_SETTING) : | 322 l10n_util::GetStringUTF16(IDS_KEEP_SETTING) : |
| 319 l10n_util::GetStringFUTF16(IDS_KEEP_SEARCH_ENGINE, name); | 323 l10n_util::GetStringFUTF16(IDS_KEEP_SEARCH_ENGINE, name); |
| 320 } | 324 } |
| 321 // Old setting is lost, offer to go to settings. | 325 // Old setting is lost, offer to go to settings. |
| 322 return l10n_util::GetStringUTF16(IDS_SELECT_SEARCH_ENGINE); | 326 return l10n_util::GetStringUTF16(IDS_SELECT_SEARCH_ENGINE); |
| 323 } | 327 } |
| 324 | 328 |
| 329 BaseSettingChange::DisplayName | |
| 330 DefaultSearchProviderChange::GetApplyDisplayName() const { | |
| 331 if (new_search_provider_ && | |
| 332 new_search_provider_->short_name().length() <= kMaxDisplayedNameLength) { | |
| 333 return DisplayName(kNamePriority, new_search_provider_->short_name()); | |
| 334 } | |
| 335 return DisplayName(kDefaultNamePriority, string16()); | |
| 336 } | |
| 337 | |
| 338 std::string DefaultSearchProviderChange::GetApplyKeyword() const { | |
| 339 std::string host; | |
| 340 if (is_fallback_) { | |
| 341 // Do not collide this change when fallback was made, since the message | |
| 342 // and Discard behaviour is pretty different. | |
| 343 return host; | |
| 344 } | |
| 345 if (!new_search_provider_) | |
| 346 return host; | |
| 347 // TODO(ivankr): may need to check for google base URL and return something | |
| 348 // like "google.com" in that case (same in other changes), so that all google | |
|
whywhat
2012/04/06 16:28:32
using .com in this case could be confusing ("I tho
Ivan Korotkov
2012/04/09 14:46:47
This "keyword" is only used for comparing changes
| |
| 349 // domains are treated as equal. | |
| 350 host = new_search_provider_->url_ref().GetHost(); | |
| 351 DCHECK(!host.empty()); | |
| 352 return host; | |
| 353 } | |
| 354 | |
| 325 void DefaultSearchProviderChange::OnTemplateURLServiceChanged() { | 355 void DefaultSearchProviderChange::OnTemplateURLServiceChanged() { |
| 326 TemplateURLService* url_service = GetTemplateURLService(); | 356 TemplateURLService* url_service = GetTemplateURLService(); |
| 327 if (url_service->GetDefaultSearchProvider() != default_search_provider_) { | 357 if (url_service->GetDefaultSearchProvider() != default_search_provider_) { |
| 328 VLOG(1) << "Default search provider has been changed by user"; | 358 VLOG(1) << "Default search provider has been changed by user"; |
| 329 default_search_provider_ = NULL; | 359 default_search_provider_ = NULL; |
| 330 url_service->RemoveObserver(this); | 360 url_service->RemoveObserver(this); |
| 331 // Will delete this DefaultSearchProviderChange instance. | 361 // Will delete this DefaultSearchProviderChange instance. |
| 332 ProtectorServiceFactory::GetForProfile(profile())->DismissChange(this); | 362 ProtectorServiceFactory::GetForProfile(profile())->DismissChange(this); |
| 333 } | 363 } |
| 334 } | 364 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 DCHECK(url_service); | 421 DCHECK(url_service); |
| 392 return url_service; | 422 return url_service; |
| 393 } | 423 } |
| 394 | 424 |
| 395 BaseSettingChange* CreateDefaultSearchProviderChange(const TemplateURL* actual, | 425 BaseSettingChange* CreateDefaultSearchProviderChange(const TemplateURL* actual, |
| 396 TemplateURL* backup) { | 426 TemplateURL* backup) { |
| 397 return new DefaultSearchProviderChange(actual, backup); | 427 return new DefaultSearchProviderChange(actual, backup); |
| 398 } | 428 } |
| 399 | 429 |
| 400 } // namespace protector | 430 } // namespace protector |
| OLD | NEW |