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

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

Issue 10261002: [protector] Homepage UI polishing. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comment added. Created 8 years, 7 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 | « no previous file | chrome/browser/protector/homepage_change_unittest.cc » ('j') | 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) 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 "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/metrics/histogram.h" 6 #include "base/metrics/histogram.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/prefs/pref_service.h" 8 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/browser/protector/base_prefs_change.h" 9 #include "chrome/browser/protector/base_prefs_change.h"
10 #include "chrome/browser/protector/histograms.h" 10 #include "chrome/browser/protector/histograms.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 virtual void Timeout() OVERRIDE; 42 virtual void Timeout() OVERRIDE;
43 virtual int GetBadgeIconID() const OVERRIDE; 43 virtual int GetBadgeIconID() const OVERRIDE;
44 virtual int GetMenuItemIconID() const OVERRIDE; 44 virtual int GetMenuItemIconID() const OVERRIDE;
45 virtual int GetBubbleIconID() const OVERRIDE; 45 virtual int GetBubbleIconID() const OVERRIDE;
46 virtual string16 GetBubbleTitle() const OVERRIDE; 46 virtual string16 GetBubbleTitle() const OVERRIDE;
47 virtual string16 GetBubbleMessage() const OVERRIDE; 47 virtual string16 GetBubbleMessage() const OVERRIDE;
48 virtual string16 GetApplyButtonText() const OVERRIDE; 48 virtual string16 GetApplyButtonText() const OVERRIDE;
49 virtual string16 GetDiscardButtonText() const OVERRIDE; 49 virtual string16 GetDiscardButtonText() const OVERRIDE;
50 virtual DisplayName GetApplyDisplayName() const OVERRIDE; 50 virtual DisplayName GetApplyDisplayName() const OVERRIDE;
51 virtual GURL GetNewSettingURL() const OVERRIDE; 51 virtual GURL GetNewSettingURL() const OVERRIDE;
52 virtual bool IsUserVisible() const OVERRIDE;
53 52
54 private: 53 private:
55 virtual ~HomepageChange(); 54 virtual ~HomepageChange();
56 55
57 const std::string new_homepage_; 56 const std::string new_homepage_;
58 const std::string backup_homepage_; 57 const std::string backup_homepage_;
59 const bool new_homepage_is_ntp_; 58 const bool new_homepage_is_ntp_;
60 const bool backup_homepage_is_ntp_; 59 const bool backup_homepage_is_ntp_;
61 const bool new_show_homepage_; 60 const bool new_show_homepage_;
62 const bool backup_show_homepage_; 61 const bool backup_show_homepage_;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 prefs->SetString(prefs::kHomePage, backup_homepage_); 94 prefs->SetString(prefs::kHomePage, backup_homepage_);
96 prefs->SetBoolean(prefs::kHomePageIsNewTabPage, backup_homepage_is_ntp_); 95 prefs->SetBoolean(prefs::kHomePageIsNewTabPage, backup_homepage_is_ntp_);
97 prefs->SetBoolean(prefs::kShowHomeButton, backup_show_homepage_); 96 prefs->SetBoolean(prefs::kShowHomeButton, backup_show_homepage_);
98 DismissOnPrefChange(prefs::kHomePage); 97 DismissOnPrefChange(prefs::kHomePage);
99 DismissOnPrefChange(prefs::kHomePageIsNewTabPage); 98 DismissOnPrefChange(prefs::kHomePageIsNewTabPage);
100 DismissOnPrefChange(prefs::kShowHomeButton); 99 DismissOnPrefChange(prefs::kShowHomeButton);
101 return true; 100 return true;
102 } 101 }
103 102
104 void HomepageChange::Apply(Browser* browser) { 103 void HomepageChange::Apply(Browser* browser) {
105 if (IsUserVisible()) { 104 UMA_HISTOGRAM_ENUMERATION(
106 // Don't report statistics if this change was applied as part of a composite 105 kProtectorHistogramHomepageApplied,
107 // change and is not user-visible. 106 new_homepage_type_,
108 UMA_HISTOGRAM_ENUMERATION( 107 HOMEPAGE_TYPE_COUNT);
109 kProtectorHistogramHomepageApplied,
110 new_homepage_type_,
111 HOMEPAGE_TYPE_COUNT);
112 }
113 IgnorePrefChanges(); 108 IgnorePrefChanges();
114 PrefService* prefs = profile()->GetPrefs(); 109 PrefService* prefs = profile()->GetPrefs();
115 prefs->SetString(prefs::kHomePage, new_homepage_); 110 prefs->SetString(prefs::kHomePage, new_homepage_);
116 prefs->SetBoolean(prefs::kHomePageIsNewTabPage, new_homepage_is_ntp_); 111 prefs->SetBoolean(prefs::kHomePageIsNewTabPage, new_homepage_is_ntp_);
117 prefs->SetBoolean(prefs::kShowHomeButton, new_show_homepage_); 112 prefs->SetBoolean(prefs::kShowHomeButton, new_show_homepage_);
118 } 113 }
119 114
120 void HomepageChange::Discard(Browser* browser) { 115 void HomepageChange::Discard(Browser* browser) {
121 if (IsUserVisible()) { 116 UMA_HISTOGRAM_ENUMERATION(
122 UMA_HISTOGRAM_ENUMERATION( 117 kProtectorHistogramHomepageDiscarded,
123 kProtectorHistogramHomepageDiscarded, 118 new_homepage_type_,
124 new_homepage_type_, 119 HOMEPAGE_TYPE_COUNT);
125 HOMEPAGE_TYPE_COUNT);
126 }
127 IgnorePrefChanges(); 120 IgnorePrefChanges();
128 // Nothing to do here since backup has already been made active by Init(). 121 // Nothing to do here since backup has already been made active by Init().
129 } 122 }
130 123
131 void HomepageChange::Timeout() { 124 void HomepageChange::Timeout() {
132 if (IsUserVisible()) { 125 UMA_HISTOGRAM_ENUMERATION(
133 UMA_HISTOGRAM_ENUMERATION( 126 kProtectorHistogramHomepageTimeout,
134 kProtectorHistogramHomepageTimeout, 127 new_homepage_type_,
135 new_homepage_type_, 128 HOMEPAGE_TYPE_COUNT);
136 HOMEPAGE_TYPE_COUNT);
137 }
138 } 129 }
139 130
140 int HomepageChange::GetBadgeIconID() const { 131 int HomepageChange::GetBadgeIconID() const {
141 // Icons are the same for homepage and startup settings. 132 // Icons are the same for homepage and startup settings.
142 return IDR_HOMEPAGE_CHANGE_BADGE; 133 return IDR_HOMEPAGE_CHANGE_BADGE;
143 } 134 }
144 135
145 int HomepageChange::GetMenuItemIconID() const { 136 int HomepageChange::GetMenuItemIconID() const {
146 return IDR_HOMEPAGE_CHANGE_MENU; 137 return IDR_HOMEPAGE_CHANGE_MENU;
147 } 138 }
148 139
149 int HomepageChange::GetBubbleIconID() const { 140 int HomepageChange::GetBubbleIconID() const {
150 return IDR_HOMEPAGE_CHANGE_ALERT; 141 return IDR_HOMEPAGE_CHANGE_ALERT;
151 } 142 }
152 143
153 string16 HomepageChange::GetBubbleTitle() const { 144 string16 HomepageChange::GetBubbleTitle() const {
154 return l10n_util::GetStringUTF16(IDS_HOMEPAGE_CHANGE_TITLE); 145 return l10n_util::GetStringUTF16(IDS_HOMEPAGE_CHANGE_TITLE);
155 } 146 }
156 147
157 string16 HomepageChange::GetBubbleMessage() const { 148 string16 HomepageChange::GetBubbleMessage() const {
158 return l10n_util::GetStringUTF16(IDS_HOMEPAGE_CHANGE_BUBBLE_MESSAGE); 149 return l10n_util::GetStringUTF16(IDS_HOMEPAGE_CHANGE_BUBBLE_MESSAGE);
159 } 150 }
160 151
161 string16 HomepageChange::GetApplyButtonText() const { 152 string16 HomepageChange::GetApplyButtonText() const {
162 return new_homepage_is_ntp_ ? 153 GURL homepage_url(GetNewSettingURL());
154 return homepage_url.is_empty() ?
163 l10n_util::GetStringUTF16(IDS_CHANGE_HOMEPAGE_NTP) : 155 l10n_util::GetStringUTF16(IDS_CHANGE_HOMEPAGE_NTP) :
164 l10n_util::GetStringFUTF16(IDS_CHANGE_HOMEPAGE, 156 l10n_util::GetStringFUTF16(IDS_CHANGE_HOMEPAGE,
165 UTF8ToUTF16(GURL(new_homepage_).host())); 157 UTF8ToUTF16(homepage_url.host()));
166 } 158 }
167 159
168 string16 HomepageChange::GetDiscardButtonText() const { 160 string16 HomepageChange::GetDiscardButtonText() const {
169 return backup_homepage_is_ntp_ ? 161 GURL new_homepage_url(GetNewSettingURL());
162 GURL backup_homepage_url;
163 if (!backup_homepage_is_ntp_)
164 backup_homepage_url = GURL(backup_homepage_);
165 if (backup_homepage_url.host() == new_homepage_url.host()) {
166 // Display a generic string if new setting looks the same as the backup (for
167 // example, when homepage hasn't changed but 'show homepage button' has).
168 return l10n_util::GetStringUTF16(IDS_KEEP_SETTING);
169 }
170 return backup_homepage_url.is_empty() ?
170 l10n_util::GetStringUTF16(IDS_KEEP_HOMEPAGE_NTP) : 171 l10n_util::GetStringUTF16(IDS_KEEP_HOMEPAGE_NTP) :
171 l10n_util::GetStringFUTF16(IDS_KEEP_HOMEPAGE, 172 l10n_util::GetStringFUTF16(IDS_KEEP_HOMEPAGE,
172 UTF8ToUTF16(GURL(backup_homepage_).host())); 173 UTF8ToUTF16(backup_homepage_url.host()));
173 } 174 }
174 175
175 BaseSettingChange::DisplayName HomepageChange::GetApplyDisplayName() const { 176 BaseSettingChange::DisplayName HomepageChange::GetApplyDisplayName() const {
176 return new_homepage_is_ntp_ ? 177 GURL homepage_url(GetNewSettingURL());
178 return homepage_url.is_empty() ?
177 DisplayName(kDefaultNamePriority, string16()) : 179 DisplayName(kDefaultNamePriority, string16()) :
178 DisplayName(kHomepageChangeNamePriority, 180 DisplayName(kHomepageChangeNamePriority,
179 UTF8ToUTF16(GURL(new_homepage_).host())); 181 UTF8ToUTF16(homepage_url.host()));
180 } 182 }
181 183
182 GURL HomepageChange::GetNewSettingURL() const { 184 GURL HomepageChange::GetNewSettingURL() const {
183 return new_homepage_is_ntp_ ? GURL() : GURL(new_homepage_); 185 return new_homepage_is_ntp_ ? GURL() : GURL(new_homepage_);
184 } 186 }
185 187
186 bool HomepageChange::IsUserVisible() const {
187 // Should not be presented to user unless the homepage button was previously
188 // visible or has been made visible by this change.
189 return new_show_homepage_ || backup_show_homepage_;
190 }
191
192 BaseSettingChange* CreateHomepageChange( 188 BaseSettingChange* CreateHomepageChange(
193 const std::string& actual_homepage, 189 const std::string& actual_homepage,
194 bool actual_homepage_is_ntp, 190 bool actual_homepage_is_ntp,
195 bool actual_show_homepage, 191 bool actual_show_homepage,
196 const std::string& backup_homepage, 192 const std::string& backup_homepage,
197 bool backup_homepage_is_ntp, 193 bool backup_homepage_is_ntp,
198 bool backup_show_homepage) { 194 bool backup_show_homepage) {
199 return new HomepageChange( 195 return new HomepageChange(
200 actual_homepage, actual_homepage_is_ntp, actual_show_homepage, 196 actual_homepage, actual_homepage_is_ntp, actual_show_homepage,
201 backup_homepage, backup_homepage_is_ntp, backup_show_homepage); 197 backup_homepage, backup_homepage_is_ntp, backup_show_homepage);
202 } 198 }
203 199
204 } // namespace protector 200 } // namespace protector
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/protector/homepage_change_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698