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

Side by Side Diff: chrome/browser/ui/webui/ntp/app_launcher_handler.cc

Issue 10827102: Delete dead AppsPromo code (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: . Created 8 years, 4 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/webui/ntp/app_launcher_handler.h" 5 #include "chrome/browser/ui/webui/ntp/app_launcher_handler.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/auto_reset.h" 10 #include "base/auto_reset.h"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/i18n/rtl.h" 13 #include "base/i18n/rtl.h"
14 #include "base/metrics/field_trial.h" 14 #include "base/metrics/field_trial.h"
15 #include "base/metrics/histogram.h" 15 #include "base/metrics/histogram.h"
16 #include "base/string_number_conversions.h" 16 #include "base/string_number_conversions.h"
17 #include "base/string_split.h" 17 #include "base/string_split.h"
18 #include "base/string_util.h" 18 #include "base/string_util.h"
19 #include "base/utf_string_conversions.h" 19 #include "base/utf_string_conversions.h"
20 #include "base/values.h" 20 #include "base/values.h"
21 #include "chrome/browser/extensions/app_notification_manager.h" 21 #include "chrome/browser/extensions/app_notification_manager.h"
22 #include "chrome/browser/extensions/apps_promo.h"
23 #include "chrome/browser/extensions/crx_installer.h" 22 #include "chrome/browser/extensions/crx_installer.h"
24 #include "chrome/browser/extensions/extension_prefs.h" 23 #include "chrome/browser/extensions/extension_prefs.h"
25 #include "chrome/browser/extensions/extension_service.h" 24 #include "chrome/browser/extensions/extension_service.h"
26 #include "chrome/browser/extensions/extension_sorting.h" 25 #include "chrome/browser/extensions/extension_sorting.h"
27 #include "chrome/browser/extensions/extension_system.h" 26 #include "chrome/browser/extensions/extension_system.h"
28 #include "chrome/browser/prefs/pref_service.h" 27 #include "chrome/browser/prefs/pref_service.h"
29 #include "chrome/browser/prefs/scoped_user_pref_update.h" 28 #include "chrome/browser/prefs/scoped_user_pref_update.h"
30 #include "chrome/browser/profiles/profile.h" 29 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/browser/ui/browser_finder.h" 30 #include "chrome/browser/ui/browser_finder.h"
32 #include "chrome/browser/ui/browser_window.h" 31 #include "chrome/browser/ui/browser_window.h"
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 base::Unretained(this))); 198 base::Unretained(this)));
200 web_ui()->RegisterMessageCallback("createAppShortcut", 199 web_ui()->RegisterMessageCallback("createAppShortcut",
201 base::Bind(&AppLauncherHandler::HandleCreateAppShortcut, 200 base::Bind(&AppLauncherHandler::HandleCreateAppShortcut,
202 base::Unretained(this))); 201 base::Unretained(this)));
203 web_ui()->RegisterMessageCallback("reorderApps", 202 web_ui()->RegisterMessageCallback("reorderApps",
204 base::Bind(&AppLauncherHandler::HandleReorderApps, 203 base::Bind(&AppLauncherHandler::HandleReorderApps,
205 base::Unretained(this))); 204 base::Unretained(this)));
206 web_ui()->RegisterMessageCallback("setPageIndex", 205 web_ui()->RegisterMessageCallback("setPageIndex",
207 base::Bind(&AppLauncherHandler::HandleSetPageIndex, 206 base::Bind(&AppLauncherHandler::HandleSetPageIndex,
208 base::Unretained(this))); 207 base::Unretained(this)));
209 web_ui()->RegisterMessageCallback("promoSeen",
210 base::Bind(&AppLauncherHandler::HandlePromoSeen,
211 base::Unretained(this)));
212 web_ui()->RegisterMessageCallback("saveAppPageName", 208 web_ui()->RegisterMessageCallback("saveAppPageName",
213 base::Bind(&AppLauncherHandler::HandleSaveAppPageName, 209 base::Bind(&AppLauncherHandler::HandleSaveAppPageName,
214 base::Unretained(this))); 210 base::Unretained(this)));
215 web_ui()->RegisterMessageCallback("generateAppForLink", 211 web_ui()->RegisterMessageCallback("generateAppForLink",
216 base::Bind(&AppLauncherHandler::HandleGenerateAppForLink, 212 base::Bind(&AppLauncherHandler::HandleGenerateAppForLink,
217 base::Unretained(this))); 213 base::Unretained(this)));
218 web_ui()->RegisterMessageCallback("recordAppLaunchByURL", 214 web_ui()->RegisterMessageCallback("recordAppLaunchByURL",
219 base::Bind(&AppLauncherHandler::HandleRecordAppLaunchByURL, 215 base::Bind(&AppLauncherHandler::HandleRecordAppLaunchByURL,
220 base::Unretained(this))); 216 base::Unretained(this)));
221 web_ui()->RegisterMessageCallback("closeNotification", 217 web_ui()->RegisterMessageCallback("closeNotification",
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 dictionary->SetBoolean("disableAppWindowLaunch", true); 397 dictionary->SetBoolean("disableAppWindowLaunch", true);
402 dictionary->SetBoolean("disableCreateAppShortcut", true); 398 dictionary->SetBoolean("disableCreateAppShortcut", true);
403 #endif 399 #endif
404 400
405 #if defined(OS_CHROMEOS) 401 #if defined(OS_CHROMEOS)
406 // Making shortcut does not make sense on ChromeOS because it does not have 402 // Making shortcut does not make sense on ChromeOS because it does not have
407 // a desktop. 403 // a desktop.
408 dictionary->SetBoolean("disableCreateAppShortcut", true); 404 dictionary->SetBoolean("disableCreateAppShortcut", true);
409 #endif 405 #endif
410 406
411 dictionary->SetBoolean(
412 "showLauncher",
413 extension_service_->apps_promo()->ShouldShowAppLauncher(
414 extension_service_->GetAppIds()));
415
416 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); 407 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
417 const ListValue* app_page_names = prefs->GetList(prefs::kNtpAppPageNames); 408 const ListValue* app_page_names = prefs->GetList(prefs::kNtpAppPageNames);
418 if (!app_page_names || !app_page_names->GetSize()) { 409 if (!app_page_names || !app_page_names->GetSize()) {
419 ListPrefUpdate update(prefs, prefs::kNtpAppPageNames); 410 ListPrefUpdate update(prefs, prefs::kNtpAppPageNames);
420 ListValue* list = update.Get(); 411 ListValue* list = update.Get();
421 list->Set(0, Value::CreateStringValue( 412 list->Set(0, Value::CreateStringValue(
422 l10n_util::GetStringUTF16(IDS_APP_DEFAULT_PAGE_NAME))); 413 l10n_util::GetStringUTF16(IDS_APP_DEFAULT_PAGE_NAME)));
423 dictionary->Set("appPageNames", 414 dictionary->Set("appPageNames",
424 static_cast<ListValue*>(list->DeepCopy())); 415 static_cast<ListValue*>(list->DeepCopy()));
425 } else { 416 } else {
426 dictionary->Set("appPageNames", 417 dictionary->Set("appPageNames",
427 static_cast<ListValue*>(app_page_names->DeepCopy())); 418 static_cast<ListValue*>(app_page_names->DeepCopy()));
428 } 419 }
429 } 420 }
430 421
431 DictionaryValue* AppLauncherHandler::GetAppInfo(const Extension* extension) { 422 DictionaryValue* AppLauncherHandler::GetAppInfo(const Extension* extension) {
432 AppNotificationManager* notification_manager = 423 AppNotificationManager* notification_manager =
433 extension_service_->app_notification_manager(); 424 extension_service_->app_notification_manager();
434 DictionaryValue* app_info = new DictionaryValue(); 425 DictionaryValue* app_info = new DictionaryValue();
435 // CreateAppInfo can change the extension prefs. 426 // CreateAppInfo can change the extension prefs.
436 AutoReset<bool> auto_reset(&ignore_changes_, true); 427 AutoReset<bool> auto_reset(&ignore_changes_, true);
437 CreateAppInfo(extension, 428 CreateAppInfo(extension,
438 notification_manager->GetLast(extension->id()), 429 notification_manager->GetLast(extension->id()),
439 extension_service_, 430 extension_service_,
440 app_info); 431 app_info);
441 return app_info; 432 return app_info;
442 } 433 }
443 434
444 void AppLauncherHandler::FillPromoDictionary(DictionaryValue* dictionary) {
445 AppsPromo::PromoData data = AppsPromo::GetPromo();
446 dictionary->SetString("promoHeader", data.header);
Mihai Parparita -not on Chrome 2012/07/31 18:41:28 This promo data is referenced in chrome/browser/re
447 dictionary->SetString("promoButton", data.button);
448 dictionary->SetString("promoLink", data.link.spec());
449 dictionary->SetString("promoLogo", data.logo.spec());
450 dictionary->SetString("promoExpire", data.expire);
451 }
452
453 void AppLauncherHandler::HandleGetApps(const ListValue* args) { 435 void AppLauncherHandler::HandleGetApps(const ListValue* args) {
454 DictionaryValue dictionary; 436 DictionaryValue dictionary;
455 437
456 // Tell the client whether to show the promo for this view. We don't do this 438 // Tell the client whether to show the promo for this view. We don't do this
457 // in the case of PREF_CHANGED because: 439 // in the case of PREF_CHANGED because:
458 // 440 //
459 // a) At that point in time, depending on the pref that changed, it can look 441 // a) At that point in time, depending on the pref that changed, it can look
460 // like the set of apps installed has changed, and we will mark the promo 442 // like the set of apps installed has changed, and we will mark the promo
461 // expired. 443 // expired.
462 // b) Conceptually, it doesn't really make sense to count a 444 // b) Conceptually, it doesn't really make sense to count a
463 // prefchange-triggered refresh as a promo 'view'. 445 // prefchange-triggered refresh as a promo 'view'.
464 AppsPromo* apps_promo = extension_service_->apps_promo();
465 Profile* profile = Profile::FromWebUI(web_ui()); 446 Profile* profile = Profile::FromWebUI(web_ui());
466 bool apps_promo_just_expired = false;
467 if (apps_promo->ShouldShowPromo(extension_service_->GetAppIds(),
468 &apps_promo_just_expired)) {
469 dictionary.SetBoolean("showPromo", true);
470 FillPromoDictionary(&dictionary);
471 } else {
472 dictionary.SetBoolean("showPromo", false);
473 }
474
475 // If the default apps have just expired (user viewed them too many times with
476 // no interaction), then we uninstall them and focus the recent sites section.
477 if (apps_promo_just_expired) {
478 ignore_changes_ = true;
479 UninstallDefaultApps();
480 ignore_changes_ = false;
481 }
482 447
483 SetAppToBeHighlighted(); 448 SetAppToBeHighlighted();
484 FillAppDictionary(&dictionary); 449 FillAppDictionary(&dictionary);
485 web_ui()->CallJavascriptFunction("ntp.getAppsCallback", dictionary); 450 web_ui()->CallJavascriptFunction("ntp.getAppsCallback", dictionary);
486 451
487 // First time we get here we set up the observer so that we can tell update 452 // First time we get here we set up the observer so that we can tell update
488 // the apps as they change. 453 // the apps as they change.
489 if (!has_loaded_apps_) { 454 if (!has_loaded_apps_) {
490 pref_change_registrar_.Init( 455 pref_change_registrar_.Init(
491 extension_service_->extension_prefs()->pref_service()); 456 extension_service_->extension_prefs()->pref_service());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 PromptToEnableApp(extension_id); 500 PromptToEnableApp(extension_id);
536 return; 501 return;
537 } 502 }
538 503
539 Profile* profile = extension_service_->profile(); 504 Profile* profile = extension_service_->profile();
540 505
541 WindowOpenDisposition disposition = args->GetSize() > 3 ? 506 WindowOpenDisposition disposition = args->GetSize() > 3 ?
542 web_ui_util::GetDispositionFromClick(args, 3) : CURRENT_TAB; 507 web_ui_util::GetDispositionFromClick(args, 3) : CURRENT_TAB;
543 if (extension_id != extension_misc::kWebStoreAppId) { 508 if (extension_id != extension_misc::kWebStoreAppId) {
544 RecordAppLaunchByID(launch_bucket); 509 RecordAppLaunchByID(launch_bucket);
545 extension_service_->apps_promo()->ExpireDefaultApps();
546 } else { 510 } else {
547 RecordWebStoreLaunch(url.find("chrome-ntp-promo") != std::string::npos); 511 RecordWebStoreLaunch();
548 } 512 }
549 513
550 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { 514 if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) {
551 // TODO(jamescook): Proper support for background tabs. 515 // TODO(jamescook): Proper support for background tabs.
552 application_launch::OpenApplication( 516 application_launch::OpenApplication(
553 profile, extension, extension_misc::LAUNCH_TAB, GURL(url), disposition, 517 profile, extension, extension_misc::LAUNCH_TAB, GURL(url), disposition,
554 NULL); 518 NULL);
555 } else if (disposition == NEW_WINDOW) { 519 } else if (disposition == NEW_WINDOW) {
556 // Force a new window open. 520 // Force a new window open.
557 application_launch::OpenApplication( 521 application_launch::OpenApplication(
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 CHECK(args->GetDouble(1, &page_index)); 650 CHECK(args->GetDouble(1, &page_index));
687 const StringOrdinal& page_ordinal = 651 const StringOrdinal& page_ordinal =
688 extension_sorting->PageIntegerAsStringOrdinal( 652 extension_sorting->PageIntegerAsStringOrdinal(
689 static_cast<size_t>(page_index)); 653 static_cast<size_t>(page_index));
690 654
691 // Don't update the page; it already knows the apps have been reordered. 655 // Don't update the page; it already knows the apps have been reordered.
692 AutoReset<bool> auto_reset(&ignore_changes_, true); 656 AutoReset<bool> auto_reset(&ignore_changes_, true);
693 extension_sorting->SetPageOrdinal(extension_id, page_ordinal); 657 extension_sorting->SetPageOrdinal(extension_id, page_ordinal);
694 } 658 }
695 659
696 void AppLauncherHandler::HandlePromoSeen(const ListValue* args) {
697 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram,
698 extension_misc::PROMO_SEEN,
699 extension_misc::PROMO_BUCKET_BOUNDARY);
700 }
701
702 void AppLauncherHandler::HandleSaveAppPageName(const ListValue* args) { 660 void AppLauncherHandler::HandleSaveAppPageName(const ListValue* args) {
703 string16 name; 661 string16 name;
704 CHECK(args->GetString(0, &name)); 662 CHECK(args->GetString(0, &name));
705 663
706 double page_index; 664 double page_index;
707 CHECK(args->GetDouble(1, &page_index)); 665 CHECK(args->GetDouble(1, &page_index));
708 666
709 AutoReset<bool> auto_reset(&ignore_changes_, true); 667 AutoReset<bool> auto_reset(&ignore_changes_, true);
710 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs(); 668 PrefService* prefs = Profile::FromWebUI(web_ui())->GetPrefs();
711 ListPrefUpdate update(prefs, prefs::kNtpAppPageNames); 669 ListPrefUpdate update(prefs, prefs::kNtpAppPageNames);
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 } 800 }
843 801
844 // static 802 // static
845 void AppLauncherHandler::RecordAppLaunchType( 803 void AppLauncherHandler::RecordAppLaunchType(
846 extension_misc::AppLaunchBucket bucket) { 804 extension_misc::AppLaunchBucket bucket) {
847 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, bucket, 805 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, bucket,
848 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); 806 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY);
849 } 807 }
850 808
851 // static 809 // static
852 void AppLauncherHandler::RecordWebStoreLaunch(bool promo_active) { 810 void AppLauncherHandler::RecordWebStoreLaunch() {
853 RecordAppLaunchType(extension_misc::APP_LAUNCH_NTP_WEBSTORE); 811 RecordAppLaunchType(extension_misc::APP_LAUNCH_NTP_WEBSTORE);
854
855 if (!promo_active) return;
856
857 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram,
858 extension_misc::PROMO_LAUNCH_WEB_STORE,
859 extension_misc::PROMO_BUCKET_BOUNDARY);
860 } 812 }
861 813
862 // static 814 // static
863 void AppLauncherHandler::RecordAppLaunchByID( 815 void AppLauncherHandler::RecordAppLaunchByID(
864 extension_misc::AppLaunchBucket bucket) { 816 extension_misc::AppLaunchBucket bucket) {
865 CHECK(bucket != extension_misc::APP_LAUNCH_BUCKET_INVALID); 817 CHECK(bucket != extension_misc::APP_LAUNCH_BUCKET_INVALID);
866 818
867 RecordAppLaunchType(bucket); 819 RecordAppLaunchType(bucket);
868 } 820 }
869 821
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 } 936 }
985 937
986 ExtensionInstallPrompt* AppLauncherHandler::GetExtensionInstallPrompt() { 938 ExtensionInstallPrompt* AppLauncherHandler::GetExtensionInstallPrompt() {
987 if (!extension_install_ui_.get()) { 939 if (!extension_install_ui_.get()) {
988 Browser* browser = browser::FindBrowserWithWebContents( 940 Browser* browser = browser::FindBrowserWithWebContents(
989 web_ui()->GetWebContents()); 941 web_ui()->GetWebContents());
990 extension_install_ui_.reset(new ExtensionInstallPrompt(browser)); 942 extension_install_ui_.reset(new ExtensionInstallPrompt(browser));
991 } 943 }
992 return extension_install_ui_.get(); 944 return extension_install_ui_.get();
993 } 945 }
994
995 void AppLauncherHandler::UninstallDefaultApps() {
996 AppsPromo* apps_promo = extension_service_->apps_promo();
997 const extensions::ExtensionIdSet& app_ids = apps_promo->old_default_apps();
998 for (extensions::ExtensionIdSet::const_iterator iter = app_ids.begin();
999 iter != app_ids.end(); ++iter) {
1000 if (extension_service_->GetExtensionById(*iter, true))
1001 extension_service_->UninstallExtension(*iter, false, NULL);
1002 }
1003 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/ntp/app_launcher_handler.h ('k') | chrome/chrome_browser_extensions.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698