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

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

Issue 6162006: Changes to default apps promo per ui leads: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix unit tests Created 9 years, 11 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) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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/default_apps.h" 5 #include "chrome/browser/extensions/default_apps.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/prefs/pref_service.h" 9 #include "chrome/browser/prefs/pref_service.h"
10 #include "chrome/common/chrome_switches.h" 10 #include "chrome/common/chrome_switches.h"
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 // installed before showing the apps section. We also show it if any 80 // installed before showing the apps section. We also show it if any
81 // non-default app is installed (eg because the user installed the app in a 81 // non-default app is installed (eg because the user installed the app in a
82 // previous version of Chrome). 82 // previous version of Chrome).
83 if (GetDefaultAppsInstalled() || NonDefaultAppIsInstalled(installed_ids)) 83 if (GetDefaultAppsInstalled() || NonDefaultAppIsInstalled(installed_ids))
84 return true; 84 return true;
85 else 85 else
86 return false; 86 return false;
87 #endif 87 #endif
88 } 88 }
89 89
90 bool DefaultApps::ShouldShowPromo(const ExtensionIdSet& installed_ids) { 90 bool DefaultApps::ShouldShowPromo(const ExtensionIdSet& installed_ids,
91 bool* just_expired) {
92 *just_expired = false;
93
91 if (CommandLine::ForCurrentProcess()->HasSwitch( 94 if (CommandLine::ForCurrentProcess()->HasSwitch(
92 switches::kForceAppsPromoVisible)) { 95 switches::kForceAppsPromoVisible)) {
93 return true; 96 return true;
94 } 97 }
95 98
96 if (!DefaultAppSupported()) 99 if (!DefaultAppSupported())
97 return false; 100 return false;
98 101
99 if (GetDefaultAppsInstalled() && GetPromoCounter() < kAppsPromoCounterMax) { 102 if (!GetDefaultAppsInstalled())
100 // If we have the exact set of default apps, show the promo. If we don't 103 return false;
101 // have the exact set of default apps, this means that the user manually 104
102 // installed or uninstalled one. The promo doesn't make sense if it shows 105 int promo_counter = GetPromoCounter();
103 // apps the user manually installed, so expire it immediately in that 106 if (promo_counter <= kAppsPromoCounterMax) {
104 // situation. 107 if (ids_ != installed_ids) {
105 if (installed_ids == ids_) 108 SetPromoHidden();
109 return false;
110 }
111
112 if (promo_counter == kAppsPromoCounterMax) {
113 *just_expired = true;
114 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram,
115 extension_misc::PROMO_EXPIRE,
116 extension_misc::PROMO_BUCKET_BOUNDARY);
117 SetPromoCounter(++promo_counter);
118 return false;
119 } else {
120 SetPromoCounter(++promo_counter);
Erik does not do reviews 2011/01/10 16:48:57 while you're in here, could you add a histogram va
Aaron Boodman 2011/01/10 19:36:19 Done, can you check my changes to chrome/common/ex
106 return true; 121 return true;
107 else 122 }
108 SetPromoHidden();
109 } 123 }
110 124
111 return false; 125 return false;
112 } 126 }
113 127
114 void DefaultApps::DidInstallApp(const ExtensionIdSet& installed_ids) { 128 void DefaultApps::DidInstallApp(const ExtensionIdSet& installed_ids) {
115 // If all the default apps have been installed, stop trying to install them. 129 // If all the default apps have been installed, stop trying to install them.
116 // Note that we use std::includes here instead of == because apps might have 130 // Note that we use std::includes here instead of == because apps might have
117 // been manually installed while the the default apps were installing and we 131 // been manually installed while the the default apps were installing and we
118 // wouldn't want to keep trying to install them in that case. 132 // wouldn't want to keep trying to install them in that case.
119 if (!GetDefaultAppsInstalled() && 133 if (!GetDefaultAppsInstalled() &&
120 std::includes(installed_ids.begin(), installed_ids.end(), 134 std::includes(installed_ids.begin(), installed_ids.end(),
121 ids_.begin(), ids_.end())) { 135 ids_.begin(), ids_.end())) {
122 SetDefaultAppsInstalled(true); 136 SetDefaultAppsInstalled(true);
123 } 137 }
124 } 138 }
125 139
126 void DefaultApps::DidShowPromo() {
127 if (!GetDefaultAppsInstalled()) {
128 NOTREACHED() << "Should not show promo until default apps are installed.";
129 return;
130 }
131
132 int promo_counter = GetPromoCounter();
133 if (promo_counter == kAppsPromoCounterMax) {
134 NOTREACHED() << "Promo has already been shown the maximum number of times.";
135 return;
136 }
137
138 if (promo_counter < kAppsPromoCounterMax) {
139 if (promo_counter + 1 == kAppsPromoCounterMax)
140 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram,
141 extension_misc::PROMO_EXPIRE,
142 extension_misc::PROMO_BUCKET_BOUNDARY);
143 SetPromoCounter(++promo_counter);
144 } else {
145 SetPromoHidden();
146 }
147 }
148
149 bool DefaultApps::NonDefaultAppIsInstalled( 140 bool DefaultApps::NonDefaultAppIsInstalled(
150 const ExtensionIdSet& installed_ids) const { 141 const ExtensionIdSet& installed_ids) const {
151 for (ExtensionIdSet::const_iterator iter = installed_ids.begin(); 142 for (ExtensionIdSet::const_iterator iter = installed_ids.begin();
152 iter != installed_ids.end(); ++iter) { 143 iter != installed_ids.end(); ++iter) {
153 if (ids_.find(*iter) == ids_.end()) 144 if (ids_.find(*iter) == ids_.end())
154 return true; 145 return true;
155 } 146 }
156 147
157 return false; 148 return false;
158 } 149 }
159 150
160 void DefaultApps::SetPromoHidden() { 151 void DefaultApps::SetPromoHidden() {
161 SetPromoCounter(kAppsPromoCounterMax); 152 SetPromoCounter(kAppsPromoCounterMax + 1);
162 } 153 }
163 154
164 int DefaultApps::GetPromoCounter() const { 155 int DefaultApps::GetPromoCounter() const {
165 return prefs_->GetInteger(prefs::kAppsPromoCounter); 156 return prefs_->GetInteger(prefs::kAppsPromoCounter);
166 } 157 }
167 158
168 void DefaultApps::SetPromoCounter(int val) { 159 void DefaultApps::SetPromoCounter(int val) {
169 prefs_->SetInteger(prefs::kAppsPromoCounter, val); 160 prefs_->SetInteger(prefs::kAppsPromoCounter, val);
170 prefs_->ScheduleSavePersistentPrefs(); 161 prefs_->ScheduleSavePersistentPrefs();
171 } 162 }
172 163
173 bool DefaultApps::GetDefaultAppsInstalled() const { 164 bool DefaultApps::GetDefaultAppsInstalled() const {
174 return prefs_->GetBoolean(prefs::kDefaultAppsInstalled); 165 return prefs_->GetBoolean(prefs::kDefaultAppsInstalled);
175 } 166 }
176 167
177 void DefaultApps::SetDefaultAppsInstalled(bool val) { 168 void DefaultApps::SetDefaultAppsInstalled(bool val) {
178 prefs_->SetBoolean(prefs::kDefaultAppsInstalled, val); 169 prefs_->SetBoolean(prefs::kDefaultAppsInstalled, val);
179 prefs_->ScheduleSavePersistentPrefs(); 170 prefs_->ScheduleSavePersistentPrefs();
180 } 171 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698