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

Side by Side Diff: chrome/browser/extensions/apps_promo.cc

Issue 6825052: Update the web store promo to be clearer and configurable at run-time. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix URL. Created 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/extensions/apps_promo.h"
6
7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/ui/webui/shown_sections_handler.h"
12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/extensions/extension.h"
14 #include "chrome/common/pref_names.h"
15
16 namespace {
17
18 PrefService* GetLocalState() {
19 return g_browser_process->local_state();
Miranda Callahan 2011/04/13 14:29:29 I would remove this whole anonymous namespace and
jstritar 2011/04/13 19:52:27 Done.
20 }
21
22 } // namespace
23
24 const int AppsPromo::kDefaultAppsCounterMax = 10;
25
26 // static
27 void AppsPromo::RegisterPrefs(PrefService* local_state) {
28 std::string str;
29 local_state->RegisterStringPref(prefs::kNTPWebStorePromoId, str);
30 local_state->RegisterStringPref(prefs::kNTPWebStorePromoHeader, str);
31 local_state->RegisterStringPref(prefs::kNTPWebStorePromoButton, str);
32 local_state->RegisterStringPref(prefs::kNTPWebStorePromoLink, str);
33 local_state->RegisterStringPref(prefs::kNTPWebStorePromoExpire, str);
34 }
35
36 // static
37 void AppsPromo::RegisterUserPrefs(PrefService* prefs) {
38 // Set the default value for the counter to max+1 since we don't install
39 // default apps for new users.
40 prefs->RegisterIntegerPref(
41 prefs::kAppsPromoCounter, kDefaultAppsCounterMax + 1);
42 prefs->RegisterBooleanPref(prefs::kDefaultAppsInstalled, false);
43 prefs->RegisterStringPref(prefs::kNTPWebStorePromoLastId, std::string());
44 }
45
46 // static
47 void AppsPromo::ClearPromo() {
48 PrefService* local_state = GetLocalState();
49 local_state->ClearPref(prefs::kNTPWebStorePromoId);
50 local_state->ClearPref(prefs::kNTPWebStorePromoHeader);
51 local_state->ClearPref(prefs::kNTPWebStorePromoButton);
52 local_state->ClearPref(prefs::kNTPWebStorePromoLink);
53 local_state->ClearPref(prefs::kNTPWebStorePromoExpire);
54 }
55
56 // static
57 std::string AppsPromo::GetPromoButtonText() {
58 PrefService* local_state = GetLocalState();
59 return local_state->GetString(prefs::kNTPWebStorePromoButton);
60 }
61
62 // static
63 std::string AppsPromo::GetPromoId() {
64 PrefService* local_state = GetLocalState();
65 return local_state->GetString(prefs::kNTPWebStorePromoId);
66 }
67
68 // static
69 std::string AppsPromo::GetPromoHeaderText() {
70 PrefService* local_state = GetLocalState();
71 return local_state->GetString(prefs::kNTPWebStorePromoHeader);
72 }
73
74 // static
75 GURL AppsPromo::GetPromoLink() {
76 PrefService* local_state = GetLocalState();
77 return GURL(local_state->GetString(prefs::kNTPWebStorePromoLink));
78 }
79
80 // static
81 std::string AppsPromo::GetPromoExpireText() {
82 PrefService* local_state = GetLocalState();
83 return local_state->GetString(prefs::kNTPWebStorePromoExpire);
84 }
85
86 // static
87 void AppsPromo::SetPromo(const std::string& id,
88 const std::string& header_text,
89 const std::string& button_text,
90 const GURL& link,
91 const std::string& expire_text) {
92 PrefService* local_state = GetLocalState();
93 local_state->SetString(prefs::kNTPWebStorePromoId, id);
94 local_state->SetString(prefs::kNTPWebStorePromoButton, button_text);
95 local_state->SetString(prefs::kNTPWebStorePromoHeader, header_text);
96 local_state->SetString(prefs::kNTPWebStorePromoLink, link.spec());
97 local_state->SetString(prefs::kNTPWebStorePromoExpire, expire_text);
98 }
99
100 // static
101 bool AppsPromo::IsPromoSupportedForLocale() {
102 PrefService* local_state = GetLocalState();
103 // PromoResourceService will clear the promo data if the current locale is
104 // not supported.
105 return local_state->HasPrefPath(prefs::kNTPWebStorePromoId) &&
106 local_state->HasPrefPath(prefs::kNTPWebStorePromoHeader) &&
107 local_state->HasPrefPath(prefs::kNTPWebStorePromoButton) &&
108 local_state->HasPrefPath(prefs::kNTPWebStorePromoLink) &&
109 local_state->HasPrefPath(prefs::kNTPWebStorePromoExpire);
110 }
111
112 AppsPromo::AppsPromo(PrefService* prefs)
113 : prefs_(prefs) {
114 // Poppit, Entanglement
Miranda Callahan 2011/04/13 14:29:29 Thanks for the comment -- I am not familiar with h
jstritar 2011/04/13 19:52:27 This is actually the one place they're defined. Th
115 ids_.insert("mcbkbpnkkkipelfledbfocopglifcfmi");
116 ids_.insert("aciahcmjmecflokailenpkdchphgkefd");
117 }
118
119 AppsPromo::~AppsPromo() {}
120
121 bool AppsPromo::ShouldShowPromo(const ExtensionIdSet& installed_ids,
122 bool* just_expired) {
123 *just_expired = false;
124
125 if (CommandLine::ForCurrentProcess()->HasSwitch(
126 switches::kForceAppsPromoVisible)) {
Miranda Callahan 2011/04/13 14:29:29 indent more nicely
jstritar 2011/04/13 19:52:27 I think this is the correct indentation because th
127 return true;
128 }
129
130 // Don't show the promo if one wasn't served to this locale.
131 if (!IsPromoSupportedForLocale())
132 return false;
133
134 int promo_counter = GetPromoCounter();
135 if (GetDefaultAppsInstalled() && promo_counter <= kDefaultAppsCounterMax) {
136 // If the default apps were installed from a previous Chrome version, we
137 // should still show the promo. If we don't have the exact set of default
138 // apps, this means that the user manually installed or uninstalled one.
139 // We no longer keep track of the default apps once others have been
140 // installed, so expire them immediately.
141 if (ids_ != installed_ids) {
142 ExpireDefaultApps();
143 return false;
144 }
145
146 if (promo_counter == kDefaultAppsCounterMax) {
147 *just_expired = true;
148
149 // The default apps have expired due to inaction, so ping PROMO_EXPIRE.
150 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram,
151 extension_misc::PROMO_EXPIRE,
152 extension_misc::PROMO_BUCKET_BOUNDARY);
153
154 ExpireDefaultApps();
155 return true;
156 } else {
157 SetPromoCounter(++promo_counter);
158 return true;
159 }
160 } else if (installed_ids.empty()) {
161 return true;
162 }
163
164 return false;
165 }
166
167 bool AppsPromo::ShouldShowAppLauncher(const ExtensionIdSet& installed_ids) {
168 // On Chrome OS the default apps are installed via a separate mechanism that
169 // is always enabled. Therefore we always show the launcher.
170 #if defined(OS_CHROME)
171 return true;
172 #else
173
174 // Always show the app launcher if an app is installed.
175 if (!installed_ids.empty())
176 return true;
177
178 // Otherwise, only show the app launcher if there's a promo for this locale.
179 return IsPromoSupportedForLocale();
180 #endif
181 }
182
183 void AppsPromo::ExpireDefaultApps() {
184 SetPromoCounter(kDefaultAppsCounterMax + 1);
185 }
186
187 void AppsPromo::MaximizeAppsIfFirstView() {
188 std::string promo_id = GetPromoId();
189
190 // Maximize the apps section of the NTP if this is the first time viewing the
191 // specific promo.
192 if (GetLastPromoId() != promo_id) {
193 prefs_->SetString(prefs::kNTPWebStorePromoLastId, promo_id);
194 ShownSectionsHandler::SetShownSection(prefs_, APPS);
195 }
196 }
197
198 void AppsPromo::HidePromo() {
199 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram,
200 extension_misc::PROMO_CLOSE,
201 extension_misc::PROMO_BUCKET_BOUNDARY);
202
203 // Put the apps section into menu mode, and maximize the recent section.
204 ShownSectionsHandler::SetShownSection(prefs_, MENU_APPS);
205 ShownSectionsHandler::SetShownSection(prefs_, THUMB);
206
207 ExpireDefaultApps();
208 }
209
210 std::string AppsPromo::GetLastPromoId() {
211 return prefs_->GetString(prefs::kNTPWebStorePromoLastId);
212 }
213
214 void AppsPromo::SetLastPromoId(const std::string& id) {
215 prefs_->SetString(prefs::kNTPWebStorePromoLastId, id);
216 }
217
218 int AppsPromo::GetPromoCounter() const {
219 return prefs_->GetInteger(prefs::kAppsPromoCounter);
220 }
221
222 void AppsPromo::SetPromoCounter(int val) {
223 prefs_->SetInteger(prefs::kAppsPromoCounter, val);
224 prefs_->ScheduleSavePersistentPrefs();
225 }
226
227 bool AppsPromo::GetDefaultAppsInstalled() const {
228 return prefs_->GetBoolean(prefs::kDefaultAppsInstalled);
229 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698