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() { |
70 dom_ui_->RegisterMessageCallback("getApps", | 72 dom_ui_->RegisterMessageCallback("getApps", |
71 NewCallback(this, &AppLauncherHandler::HandleGetApps)); | 73 NewCallback(this, &AppLauncherHandler::HandleGetApps)); |
72 dom_ui_->RegisterMessageCallback("launchApp", | 74 dom_ui_->RegisterMessageCallback("launchApp", |
73 NewCallback(this, &AppLauncherHandler::HandleLaunchApp)); | 75 NewCallback(this, &AppLauncherHandler::HandleLaunchApp)); |
74 dom_ui_->RegisterMessageCallback("setLaunchType", | 76 dom_ui_->RegisterMessageCallback("setLaunchType", |
75 NewCallback(this, &AppLauncherHandler::HandleSetLaunchType)); | 77 NewCallback(this, &AppLauncherHandler::HandleSetLaunchType)); |
76 dom_ui_->RegisterMessageCallback("uninstallApp", | 78 dom_ui_->RegisterMessageCallback("uninstallApp", |
77 NewCallback(this, &AppLauncherHandler::HandleUninstallApp)); | 79 NewCallback(this, &AppLauncherHandler::HandleUninstallApp)); |
78 dom_ui_->RegisterMessageCallback("hideAppsPromo", | 80 dom_ui_->RegisterMessageCallback("hideAppsPromo", |
79 NewCallback(this, &AppLauncherHandler::HandleHideAppsPromo)); | 81 NewCallback(this, &AppLauncherHandler::HandleHideAppsPromo)); |
82 dom_ui_->RegisterMessageCallback("recordWebStoreLaunch", | |
83 NewCallback(this, &AppLauncherHandler::HandleRecordWebStoreLaunch)); | |
84 dom_ui_->RegisterMessageCallback("recordAppLaunch", | |
85 NewCallback(this, &AppLauncherHandler::HandleRecordAppLaunch)); | |
80 } | 86 } |
81 | 87 |
82 void AppLauncherHandler::Observe(NotificationType type, | 88 void AppLauncherHandler::Observe(NotificationType type, |
83 const NotificationSource& source, | 89 const NotificationSource& source, |
84 const NotificationDetails& details) { | 90 const NotificationDetails& details) { |
85 switch (type.value) { | 91 switch (type.value) { |
86 case NotificationType::EXTENSION_LOADED: | 92 case NotificationType::EXTENSION_LOADED: |
87 case NotificationType::EXTENSION_UNLOADED: | 93 case NotificationType::EXTENSION_UNLOADED: |
88 if (dom_ui_->tab_contents()) | 94 if (dom_ui_->tab_contents()) |
89 HandleGetApps(NULL); | 95 HandleGetApps(NULL); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 CreateAppInfo(*it, extensions_service_->extension_prefs(), app_info); | 149 CreateAppInfo(*it, extensions_service_->extension_prefs(), app_info); |
144 list->Append(app_info); | 150 list->Append(app_info); |
145 } | 151 } |
146 } | 152 } |
147 dictionary->Set("apps", list); | 153 dictionary->Set("apps", list); |
148 | 154 |
149 DefaultApps* default_apps = extensions_service_->default_apps(); | 155 DefaultApps* default_apps = extensions_service_->default_apps(); |
150 if (default_apps->ShouldShowPromo(extensions_service_->GetAppIds())) { | 156 if (default_apps->ShouldShowPromo(extensions_service_->GetAppIds())) { |
151 dictionary->SetBoolean("showPromo", true); | 157 dictionary->SetBoolean("showPromo", true); |
152 default_apps->DidShowPromo(); | 158 default_apps->DidShowPromo(); |
159 promo_active_ = true; | |
153 } else { | 160 } else { |
154 dictionary->SetBoolean("showPromo", false); | 161 dictionary->SetBoolean("showPromo", false); |
162 promo_active_ = false; | |
155 } | 163 } |
156 | 164 |
157 bool showLauncher = | 165 bool showLauncher = |
158 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAppLauncher); | 166 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableAppLauncher); |
159 dictionary->SetBoolean("showLauncher", showLauncher); | 167 dictionary->SetBoolean("showLauncher", showLauncher); |
160 } | 168 } |
161 | 169 |
162 void AppLauncherHandler::HandleGetApps(const ListValue* args) { | 170 void AppLauncherHandler::HandleGetApps(const ListValue* args) { |
163 DictionaryValue dictionary; | 171 DictionaryValue dictionary; |
164 FillAppDictionary(&dictionary); | 172 FillAppDictionary(&dictionary); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 return; // Only one prompt at a time. | 272 return; // Only one prompt at a time. |
265 | 273 |
266 extension_id_prompting_ = extension_id; | 274 extension_id_prompting_ = extension_id; |
267 GetExtensionInstallUI()->ConfirmUninstall(this, extension); | 275 GetExtensionInstallUI()->ConfirmUninstall(this, extension); |
268 } | 276 } |
269 | 277 |
270 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) { | 278 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) { |
271 // If the user has intentionally hidden the promotion, we'll uninstall all the | 279 // 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 | 280 // 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). | 281 // this point, or the promotion wouldn't have been shown). |
282 UMA_HISTOGRAM_ENUMERATION("Extensions.AppsPromo", | |
283 extension_misc::CLOSE_PROMO, | |
284 extension_misc::MAX); | |
Erik does not do reviews
2010/11/10 23:29:51
given that you're using a common namespace for the
| |
274 DefaultApps* default_apps = extensions_service_->default_apps(); | 285 DefaultApps* default_apps = extensions_service_->default_apps(); |
275 const ExtensionIdSet* app_ids = default_apps->GetDefaultApps(); | 286 const ExtensionIdSet* app_ids = default_apps->GetDefaultApps(); |
276 DCHECK(*app_ids == extensions_service_->GetAppIds()); | 287 DCHECK(*app_ids == extensions_service_->GetAppIds()); |
277 | 288 |
278 for (ExtensionIdSet::const_iterator iter = app_ids->begin(); | 289 for (ExtensionIdSet::const_iterator iter = app_ids->begin(); |
279 iter != app_ids->end(); ++iter) { | 290 iter != app_ids->end(); ++iter) { |
280 if (extensions_service_->GetExtensionById(*iter, true)) | 291 if (extensions_service_->GetExtensionById(*iter, true)) |
281 extensions_service_->UninstallExtension(*iter, false); | 292 extensions_service_->UninstallExtension(*iter, false); |
282 } | 293 } |
283 | 294 |
284 extensions_service_->default_apps()->SetPromoHidden(); | 295 extensions_service_->default_apps()->SetPromoHidden(); |
285 } | 296 } |
286 | 297 |
298 void AppLauncherHandler::HandleRecordWebStoreLaunch(const ListValue* args) { | |
299 if (promo_active_) { | |
300 UMA_HISTOGRAM_ENUMERATION("Extensions.AppsPromo", | |
301 extension_misc::LAUNCH_WEB_STORE, | |
302 extension_misc::MAX); | |
303 } | |
304 } | |
305 | |
306 void AppLauncherHandler::HandleRecordAppLaunch(const ListValue* args) { | |
307 if (promo_active_) { | |
308 UMA_HISTOGRAM_ENUMERATION("Extensions.AppsPromo", | |
309 extension_misc::LAUNCH_APP, | |
310 extension_misc::MAX); | |
311 | |
312 // If we're launching the web store application, then we may have to bump | |
Erik does not do reviews
2010/11/10 23:29:51
if that's the case, then we shouldn't bump LAUNCH_
| |
313 // the web store launch histogram. | |
314 std::string extension_id; | |
315 | |
316 if (!args->GetString(0, &extension_id)) { | |
317 NOTREACHED(); | |
318 return; | |
319 } | |
320 if (extension_id == extension_misc::kWebStoreAppId || | |
321 extension_id == extension_misc::kNTPWebStoreAppId) | |
322 HandleRecordWebStoreLaunch(args); | |
323 } | |
324 } | |
325 | |
287 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() { | 326 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() { |
288 if (!install_ui_.get()) | 327 if (!install_ui_.get()) |
289 install_ui_.reset(new ExtensionInstallUI(dom_ui_->GetProfile())); | 328 install_ui_.reset(new ExtensionInstallUI(dom_ui_->GetProfile())); |
290 return install_ui_.get(); | 329 return install_ui_.get(); |
291 } | 330 } |
292 | 331 |
293 void AppLauncherHandler::InstallUIProceed() { | 332 void AppLauncherHandler::InstallUIProceed() { |
294 DCHECK(!extension_id_prompting_.empty()); | 333 DCHECK(!extension_id_prompting_.empty()); |
295 | 334 |
296 // The extension can be uninstalled in another window while the UI was | 335 // The extension can be uninstalled in another window while the UI was |
297 // showing. Do nothing in that case. | 336 // showing. Do nothing in that case. |
298 const Extension* extension = | 337 const Extension* extension = |
299 extensions_service_->GetExtensionById(extension_id_prompting_, true); | 338 extensions_service_->GetExtensionById(extension_id_prompting_, true); |
300 if (!extension) | 339 if (!extension) |
301 return; | 340 return; |
302 | 341 |
303 extensions_service_->UninstallExtension(extension_id_prompting_, | 342 extensions_service_->UninstallExtension(extension_id_prompting_, |
304 false /* external_uninstall */); | 343 false /* external_uninstall */); |
305 extension_id_prompting_ = ""; | 344 extension_id_prompting_ = ""; |
306 } | 345 } |
307 | 346 |
308 void AppLauncherHandler::InstallUIAbort() { | 347 void AppLauncherHandler::InstallUIAbort() { |
309 extension_id_prompting_ = ""; | 348 extension_id_prompting_ = ""; |
310 } | 349 } |
OLD | NEW |