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/dom_ui/app_launcher_handler.h" | 5 #include "chrome/browser/dom_ui/app_launcher_handler.h" |
6 | 6 |
7 #include "app/animation.h" | 7 #include "app/animation.h" |
| 8 #include "base/metrics/histogram.h" |
8 #include "base/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
9 #include "base/string_util.h" | 10 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
11 #include "base/values.h" | 12 #include "base/values.h" |
12 #include "chrome/browser/app_launched_animation.h" | 13 #include "chrome/browser/app_launched_animation.h" |
13 #include "chrome/browser/browser.h" | 14 #include "chrome/browser/browser.h" |
14 #include "chrome/browser/browser_list.h" | 15 #include "chrome/browser/browser_list.h" |
15 #include "chrome/browser/extensions/default_apps.h" | 16 #include "chrome/browser/extensions/default_apps.h" |
16 #include "chrome/browser/extensions/extension_prefs.h" | 17 #include "chrome/browser/extensions/extension_prefs.h" |
17 #include "chrome/browser/extensions/extensions_service.h" | 18 #include "chrome/browser/extensions/extensions_service.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 GURL url = extension->GetIconURL(icon, ExtensionIconSet::MATCH_EXACTLY); | 50 GURL url = extension->GetIconURL(icon, ExtensionIconSet::MATCH_EXACTLY); |
50 if (!url.is_empty()) | 51 if (!url.is_empty()) |
51 return url.spec(); | 52 return url.spec(); |
52 else | 53 else |
53 return default_val; | 54 return default_val; |
54 } | 55 } |
55 | 56 |
56 } // namespace | 57 } // namespace |
57 | 58 |
58 AppLauncherHandler::AppLauncherHandler(ExtensionsService* extension_service) | 59 AppLauncherHandler::AppLauncherHandler(ExtensionsService* extension_service) |
59 : extensions_service_(extension_service) { | 60 : extensions_service_(extension_service), |
| 61 promo_active_(false) { |
60 } | 62 } |
61 | 63 |
62 AppLauncherHandler::~AppLauncherHandler() {} | 64 AppLauncherHandler::~AppLauncherHandler() {} |
63 | 65 |
64 DOMMessageHandler* AppLauncherHandler::Attach(DOMUI* dom_ui) { | 66 DOMMessageHandler* AppLauncherHandler::Attach(DOMUI* dom_ui) { |
65 // TODO(arv): Add initialization code to the Apps store etc. | 67 // TODO(arv): Add initialization code to the Apps store etc. |
66 return DOMMessageHandler::Attach(dom_ui); | 68 return DOMMessageHandler::Attach(dom_ui); |
67 } | 69 } |
68 | 70 |
69 void AppLauncherHandler::RegisterMessages() { | 71 void AppLauncherHandler::RegisterMessages() { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 CreateAppInfo(*it, extensions_service_->extension_prefs(), app_info); | 145 CreateAppInfo(*it, extensions_service_->extension_prefs(), app_info); |
144 list->Append(app_info); | 146 list->Append(app_info); |
145 } | 147 } |
146 } | 148 } |
147 dictionary->Set("apps", list); | 149 dictionary->Set("apps", list); |
148 | 150 |
149 DefaultApps* default_apps = extensions_service_->default_apps(); | 151 DefaultApps* default_apps = extensions_service_->default_apps(); |
150 if (default_apps->ShouldShowPromo(extensions_service_->GetAppIds())) { | 152 if (default_apps->ShouldShowPromo(extensions_service_->GetAppIds())) { |
151 dictionary->SetBoolean("showPromo", true); | 153 dictionary->SetBoolean("showPromo", true); |
152 default_apps->DidShowPromo(); | 154 default_apps->DidShowPromo(); |
| 155 promo_active_ = true; |
153 } else { | 156 } else { |
154 dictionary->SetBoolean("showPromo", false); | 157 dictionary->SetBoolean("showPromo", false); |
| 158 promo_active_ = false; |
155 } | 159 } |
156 | 160 |
157 bool showLauncher = | 161 bool showLauncher = |
158 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAppLauncher); | 162 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAppLauncher); |
159 dictionary->SetBoolean("showLauncher", showLauncher); | 163 dictionary->SetBoolean("showLauncher", showLauncher); |
160 } | 164 } |
161 | 165 |
162 void AppLauncherHandler::HandleGetApps(const ListValue* args) { | 166 void AppLauncherHandler::HandleGetApps(const ListValue* args) { |
163 DictionaryValue dictionary; | 167 DictionaryValue dictionary; |
164 FillAppDictionary(&dictionary); | 168 FillAppDictionary(&dictionary); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 TabContents* old_contents = NULL; | 217 TabContents* old_contents = NULL; |
214 if (browser) | 218 if (browser) |
215 old_contents = browser->GetSelectedTabContents(); | 219 old_contents = browser->GetSelectedTabContents(); |
216 | 220 |
217 AnimateAppIcon(extension, rect); | 221 AnimateAppIcon(extension, rect); |
218 TabContents* new_contents = Browser::OpenApplication( | 222 TabContents* new_contents = Browser::OpenApplication( |
219 profile, extension, extension->launch_container(), old_contents); | 223 profile, extension, extension->launch_container(), old_contents); |
220 | 224 |
221 if (new_contents != old_contents && browser->tab_count() > 1) | 225 if (new_contents != old_contents && browser->tab_count() > 1) |
222 browser->CloseTabContents(old_contents); | 226 browser->CloseTabContents(old_contents); |
| 227 |
| 228 if (promo_active_ && extension_id != extension_misc::kWebStoreAppId) { |
| 229 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, |
| 230 extension_misc::PROMO_LAUNCH_APP, |
| 231 extension_misc::PROMO_BUCKET_BOUNDARY); |
| 232 } |
| 233 // TODO(jstritar): record histogram data for app launches that occur when |
| 234 // the promo is not active. |
223 } | 235 } |
224 | 236 |
225 void AppLauncherHandler::HandleSetLaunchType(const ListValue* args) { | 237 void AppLauncherHandler::HandleSetLaunchType(const ListValue* args) { |
226 std::string extension_id; | 238 std::string extension_id; |
227 int launch_type; | 239 int launch_type; |
228 if (!args->GetString(0, &extension_id) || | 240 if (!args->GetString(0, &extension_id) || |
229 !ExtractInt(args, 1, &launch_type)) { | 241 !ExtractInt(args, 1, &launch_type)) { |
230 NOTREACHED(); | 242 NOTREACHED(); |
231 return; | 243 return; |
232 } | 244 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 return; // Only one prompt at a time. | 276 return; // Only one prompt at a time. |
265 | 277 |
266 extension_id_prompting_ = extension_id; | 278 extension_id_prompting_ = extension_id; |
267 GetExtensionInstallUI()->ConfirmUninstall(this, extension); | 279 GetExtensionInstallUI()->ConfirmUninstall(this, extension); |
268 } | 280 } |
269 | 281 |
270 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) { | 282 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) { |
271 // If the user has intentionally hidden the promotion, we'll uninstall all the | 283 // If the user has intentionally hidden the promotion, we'll uninstall all the |
272 // default apps (we know the user hasn't installed any apps on their own at | 284 // default apps (we know the user hasn't installed any apps on their own at |
273 // this point, or the promotion wouldn't have been shown). | 285 // this point, or the promotion wouldn't have been shown). |
| 286 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, |
| 287 extension_misc::PROMO_CLOSE, |
| 288 extension_misc::PROMO_BUCKET_BOUNDARY); |
274 DefaultApps* default_apps = extensions_service_->default_apps(); | 289 DefaultApps* default_apps = extensions_service_->default_apps(); |
275 const ExtensionIdSet* app_ids = default_apps->GetDefaultApps(); | 290 const ExtensionIdSet* app_ids = default_apps->GetDefaultApps(); |
276 DCHECK(*app_ids == extensions_service_->GetAppIds()); | 291 DCHECK(*app_ids == extensions_service_->GetAppIds()); |
277 | 292 |
278 for (ExtensionIdSet::const_iterator iter = app_ids->begin(); | 293 for (ExtensionIdSet::const_iterator iter = app_ids->begin(); |
279 iter != app_ids->end(); ++iter) { | 294 iter != app_ids->end(); ++iter) { |
280 if (extensions_service_->GetExtensionById(*iter, true)) | 295 if (extensions_service_->GetExtensionById(*iter, true)) |
281 extensions_service_->UninstallExtension(*iter, false); | 296 extensions_service_->UninstallExtension(*iter, false); |
282 } | 297 } |
283 | 298 |
(...skipping 17 matching lines...) Expand all Loading... |
301 return; | 316 return; |
302 | 317 |
303 extensions_service_->UninstallExtension(extension_id_prompting_, | 318 extensions_service_->UninstallExtension(extension_id_prompting_, |
304 false /* external_uninstall */); | 319 false /* external_uninstall */); |
305 extension_id_prompting_ = ""; | 320 extension_id_prompting_ = ""; |
306 } | 321 } |
307 | 322 |
308 void AppLauncherHandler::InstallUIAbort() { | 323 void AppLauncherHandler::InstallUIAbort() { |
309 extension_id_prompting_ = ""; | 324 extension_id_prompting_ = ""; |
310 } | 325 } |
OLD | NEW |