OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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 "chrome/browser/extensions/apps_promo.h" | 5 #include "chrome/browser/extensions/apps_promo.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/prefs/pref_service.h" | 10 #include "chrome/browser/prefs/pref_service.h" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
54 // default apps for new users. | 54 // default apps for new users. |
55 prefs->RegisterIntegerPref(prefs::kAppsPromoCounter, | 55 prefs->RegisterIntegerPref(prefs::kAppsPromoCounter, |
56 kDefaultAppsCounterMax + 1, | 56 kDefaultAppsCounterMax + 1, |
57 PrefService::UNSYNCABLE_PREF); | 57 PrefService::UNSYNCABLE_PREF); |
58 prefs->RegisterBooleanPref(prefs::kDefaultAppsInstalled, | 58 prefs->RegisterBooleanPref(prefs::kDefaultAppsInstalled, |
59 false, | 59 false, |
60 PrefService::UNSYNCABLE_PREF); | 60 PrefService::UNSYNCABLE_PREF); |
61 prefs->RegisterStringPref(prefs::kNTPWebStorePromoLastId, | 61 prefs->RegisterStringPref(prefs::kNTPWebStorePromoLastId, |
62 std::string(), | 62 std::string(), |
63 PrefService::UNSYNCABLE_PREF); | 63 PrefService::UNSYNCABLE_PREF); |
64 prefs->RegisterBooleanPref(prefs::kNTPHideWebStorePromo, | |
65 false, | |
66 PrefService::UNSYNCABLE_PREF); | |
64 } | 67 } |
65 | 68 |
66 // static | 69 // static |
67 void AppsPromo::ClearPromo() { | 70 void AppsPromo::ClearPromo() { |
68 PrefService* local_state = g_browser_process->local_state(); | 71 PrefService* local_state = g_browser_process->local_state(); |
69 local_state->ClearPref(prefs::kNTPWebStoreEnabled); | 72 local_state->ClearPref(prefs::kNTPWebStoreEnabled); |
70 local_state->ClearPref(prefs::kNTPWebStorePromoId); | 73 local_state->ClearPref(prefs::kNTPWebStorePromoId); |
71 local_state->ClearPref(prefs::kNTPWebStorePromoHeader); | 74 local_state->ClearPref(prefs::kNTPWebStorePromoHeader); |
72 local_state->ClearPref(prefs::kNTPWebStorePromoButton); | 75 local_state->ClearPref(prefs::kNTPWebStorePromoButton); |
73 local_state->ClearPref(prefs::kNTPWebStorePromoLink); | 76 local_state->ClearPref(prefs::kNTPWebStorePromoLink); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 | 182 |
180 bool AppsPromo::ShouldShowPromo(const ExtensionIdSet& installed_ids, | 183 bool AppsPromo::ShouldShowPromo(const ExtensionIdSet& installed_ids, |
181 bool* just_expired) { | 184 bool* just_expired) { |
182 *just_expired = false; | 185 *just_expired = false; |
183 | 186 |
184 if (CommandLine::ForCurrentProcess()->HasSwitch( | 187 if (CommandLine::ForCurrentProcess()->HasSwitch( |
185 switches::kForceAppsPromoVisible)) { | 188 switches::kForceAppsPromoVisible)) { |
186 return true; | 189 return true; |
187 } | 190 } |
188 | 191 |
192 // Don't show the promo if the policy says not to. | |
193 if (prefs_->GetBoolean(prefs::kNTPHideWebStorePromo)) { | |
194 ExpireDefaultApps(); | |
195 return false; | |
196 } | |
197 | |
189 // Don't show the promo if one wasn't served to this locale. | 198 // Don't show the promo if one wasn't served to this locale. |
190 if (!IsPromoSupportedForLocale()) | 199 if (!IsPromoSupportedForLocale()) |
191 return false; | 200 return false; |
192 | 201 |
193 int promo_counter = GetPromoCounter(); | 202 int promo_counter = GetPromoCounter(); |
194 if (GetDefaultAppsInstalled() && promo_counter <= kDefaultAppsCounterMax) { | 203 if (GetDefaultAppsInstalled() && promo_counter <= kDefaultAppsCounterMax) { |
195 // If the default apps were installed from a previous Chrome version, we | 204 // If the default apps were installed from a previous Chrome version, we |
196 // should still show the promo. If we don't have the exact set of default | 205 // should still show the promo. If we don't have the exact set of default |
197 // apps, this means that the user manually installed or uninstalled one. | 206 // apps, this means that the user manually installed or uninstalled one. |
198 // We no longer keep track of the default apps once others have been | 207 // We no longer keep track of the default apps once others have been |
199 // installed, so expire them immediately. | 208 // installed, so expire them immediately. |
200 if (old_default_app_ids_ != installed_ids) { | 209 if (old_default_app_ids_ != installed_ids) { |
201 ExpireDefaultApps(); | 210 ExpireDefaultApps(); |
202 return false; | 211 return false; |
203 } | 212 } |
204 | 213 |
205 if (promo_counter == kDefaultAppsCounterMax) { | 214 if (promo_counter == kDefaultAppsCounterMax) { |
206 *just_expired = true; | 215 *just_expired = true; |
207 | 216 |
208 // The default apps have expired due to inaction, so ping PROMO_EXPIRE. | 217 // The default apps have expired due to inaction, so ping PROMO_EXPIRE. |
209 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, | 218 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, |
210 extension_misc::PROMO_EXPIRE, | 219 extension_misc::PROMO_EXPIRE, |
211 extension_misc::PROMO_BUCKET_BOUNDARY); | 220 extension_misc::PROMO_BUCKET_BOUNDARY); |
212 | 221 |
213 ExpireDefaultApps(); | 222 ExpireDefaultApps(); |
214 return true; | |
215 } else { | 223 } else { |
216 SetPromoCounter(++promo_counter); | 224 SetPromoCounter(++promo_counter); |
217 return true; | |
218 } | 225 } |
226 return true; | |
Evan Stade
2011/08/09 19:54:55
as long as you are changing the logic around, I th
| |
219 } else if (installed_ids.empty()) { | 227 } else if (installed_ids.empty()) { |
220 return true; | 228 return true; |
221 } | 229 } |
222 | 230 |
223 return false; | 231 return false; |
224 } | 232 } |
225 | 233 |
226 bool AppsPromo::ShouldShowAppLauncher(const ExtensionIdSet& installed_ids) { | 234 bool AppsPromo::ShouldShowAppLauncher(const ExtensionIdSet& installed_ids) { |
227 // On Chrome OS the default apps are installed via a separate mechanism that | 235 // On Chrome OS the default apps are installed via a separate mechanism that |
228 // is always enabled. Therefore we always show the launcher. | 236 // is always enabled. Therefore we always show the launcher. |
229 #if defined(OS_CHROME) | 237 #if defined(OS_CHROMEOS) |
230 return true; | 238 return true; |
231 #else | 239 #else |
232 | 240 |
233 // Always show the app launcher if an app is installed. | 241 // Always show the app launcher if an app is installed. |
234 if (!installed_ids.empty()) | 242 if (!installed_ids.empty()) |
235 return true; | 243 return true; |
236 | 244 |
237 // Otherwise, only show the app launcher if the web store is supported for the | 245 // Otherwise, only show the app launcher if the web store is supported for the |
238 // current locale. | 246 // current locale. |
239 return IsWebStoreSupportedForLocale(); | 247 return IsWebStoreSupportedForLocale(); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 bool AppsPromo::GetDefaultAppsInstalled() const { | 297 bool AppsPromo::GetDefaultAppsInstalled() const { |
290 return prefs_->GetBoolean(prefs::kDefaultAppsInstalled); | 298 return prefs_->GetBoolean(prefs::kDefaultAppsInstalled); |
291 } | 299 } |
292 | 300 |
293 AppsPromo::UserGroup AppsPromo::GetCurrentUserGroup() const { | 301 AppsPromo::UserGroup AppsPromo::GetCurrentUserGroup() const { |
294 const PrefService::Preference* last_promo_id | 302 const PrefService::Preference* last_promo_id |
295 = prefs_->FindPreference(prefs::kNTPWebStorePromoLastId); | 303 = prefs_->FindPreference(prefs::kNTPWebStorePromoLastId); |
296 CHECK(last_promo_id); | 304 CHECK(last_promo_id); |
297 return last_promo_id->IsDefaultValue() ? USERS_NEW : USERS_EXISTING; | 305 return last_promo_id->IsDefaultValue() ? USERS_NEW : USERS_EXISTING; |
298 } | 306 } |
OLD | NEW |