OLD | NEW |
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 Loading... |
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()) |
| 103 return false; |
| 104 |
| 105 int promo_counter = GetPromoCounter(); |
| 106 if (promo_counter <= kAppsPromoCounterMax) { |
100 // If we have the exact set of default apps, show the promo. If we don't | 107 // If we have the exact set of default apps, show the promo. If we don't |
101 // have the exact set of default apps, this means that the user manually | 108 // have the exact set of default apps, this means that the user manually |
102 // installed or uninstalled one. The promo doesn't make sense if it shows | 109 // installed or uninstalled one. The promo doesn't make sense if it shows |
103 // apps the user manually installed, so expire it immediately in that | 110 // apps the user manually installed, so expire it immediately in that |
104 // situation. | 111 // situation. |
105 if (installed_ids == ids_) | 112 if (ids_ != installed_ids) { |
| 113 SetPromoHidden(); |
| 114 return false; |
| 115 } |
| 116 |
| 117 if (promo_counter == kAppsPromoCounterMax) { |
| 118 *just_expired = true; |
| 119 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, |
| 120 extension_misc::PROMO_EXPIRE, |
| 121 extension_misc::PROMO_BUCKET_BOUNDARY); |
| 122 SetPromoCounter(++promo_counter); |
| 123 return false; |
| 124 } else { |
| 125 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, |
| 126 extension_misc::PROMO_SEEN, |
| 127 extension_misc::PROMO_BUCKET_BOUNDARY); |
| 128 SetPromoCounter(++promo_counter); |
106 return true; | 129 return true; |
107 else | 130 } |
108 SetPromoHidden(); | |
109 } | 131 } |
110 | 132 |
111 return false; | 133 return false; |
112 } | 134 } |
113 | 135 |
114 void DefaultApps::DidInstallApp(const ExtensionIdSet& installed_ids) { | 136 void DefaultApps::DidInstallApp(const ExtensionIdSet& installed_ids) { |
115 // If all the default apps have been installed, stop trying to install them. | 137 // 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 | 138 // 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 | 139 // 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. | 140 // wouldn't want to keep trying to install them in that case. |
119 if (!GetDefaultAppsInstalled() && | 141 if (!GetDefaultAppsInstalled() && |
120 std::includes(installed_ids.begin(), installed_ids.end(), | 142 std::includes(installed_ids.begin(), installed_ids.end(), |
121 ids_.begin(), ids_.end())) { | 143 ids_.begin(), ids_.end())) { |
122 SetDefaultAppsInstalled(true); | 144 SetDefaultAppsInstalled(true); |
123 } | 145 } |
124 } | 146 } |
125 | 147 |
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( | 148 bool DefaultApps::NonDefaultAppIsInstalled( |
150 const ExtensionIdSet& installed_ids) const { | 149 const ExtensionIdSet& installed_ids) const { |
151 for (ExtensionIdSet::const_iterator iter = installed_ids.begin(); | 150 for (ExtensionIdSet::const_iterator iter = installed_ids.begin(); |
152 iter != installed_ids.end(); ++iter) { | 151 iter != installed_ids.end(); ++iter) { |
153 if (ids_.find(*iter) == ids_.end()) | 152 if (ids_.find(*iter) == ids_.end()) |
154 return true; | 153 return true; |
155 } | 154 } |
156 | 155 |
157 return false; | 156 return false; |
158 } | 157 } |
159 | 158 |
160 void DefaultApps::SetPromoHidden() { | 159 void DefaultApps::SetPromoHidden() { |
161 SetPromoCounter(kAppsPromoCounterMax); | 160 SetPromoCounter(kAppsPromoCounterMax + 1); |
162 } | 161 } |
163 | 162 |
164 int DefaultApps::GetPromoCounter() const { | 163 int DefaultApps::GetPromoCounter() const { |
165 return prefs_->GetInteger(prefs::kAppsPromoCounter); | 164 return prefs_->GetInteger(prefs::kAppsPromoCounter); |
166 } | 165 } |
167 | 166 |
168 void DefaultApps::SetPromoCounter(int val) { | 167 void DefaultApps::SetPromoCounter(int val) { |
169 prefs_->SetInteger(prefs::kAppsPromoCounter, val); | 168 prefs_->SetInteger(prefs::kAppsPromoCounter, val); |
170 prefs_->ScheduleSavePersistentPrefs(); | 169 prefs_->ScheduleSavePersistentPrefs(); |
171 } | 170 } |
172 | 171 |
173 bool DefaultApps::GetDefaultAppsInstalled() const { | 172 bool DefaultApps::GetDefaultAppsInstalled() const { |
174 return prefs_->GetBoolean(prefs::kDefaultAppsInstalled); | 173 return prefs_->GetBoolean(prefs::kDefaultAppsInstalled); |
175 } | 174 } |
176 | 175 |
177 void DefaultApps::SetDefaultAppsInstalled(bool val) { | 176 void DefaultApps::SetDefaultAppsInstalled(bool val) { |
178 prefs_->SetBoolean(prefs::kDefaultAppsInstalled, val); | 177 prefs_->SetBoolean(prefs::kDefaultAppsInstalled, val); |
179 prefs_->ScheduleSavePersistentPrefs(); | 178 prefs_->ScheduleSavePersistentPrefs(); |
180 } | 179 } |
OLD | NEW |