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

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

Issue 9116037: [NTP4] Make TilePage and CardSlider evented to simplify code and fix page switcher bug (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase + event order change Created 8 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) 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"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } // namespace 71 } // namespace
72 72
73 AppLauncherHandler::AppInstallInfo::AppInstallInfo() {} 73 AppLauncherHandler::AppInstallInfo::AppInstallInfo() {}
74 74
75 AppLauncherHandler::AppInstallInfo::~AppInstallInfo() {} 75 AppLauncherHandler::AppInstallInfo::~AppInstallInfo() {}
76 76
77 AppLauncherHandler::AppLauncherHandler(ExtensionService* extension_service) 77 AppLauncherHandler::AppLauncherHandler(ExtensionService* extension_service)
78 : extension_service_(extension_service), 78 : extension_service_(extension_service),
79 ignore_changes_(false), 79 ignore_changes_(false),
80 attempted_bookmark_app_install_(false), 80 attempted_bookmark_app_install_(false),
81 has_loaded_apps_(false) { 81 has_loaded_apps_(false),
82 uninstall_from_page_(false) {
82 } 83 }
83 84
84 AppLauncherHandler::~AppLauncherHandler() {} 85 AppLauncherHandler::~AppLauncherHandler() {}
85 86
86 // Serializes |notification| into a new DictionaryValue which the caller then 87 // Serializes |notification| into a new DictionaryValue which the caller then
87 // owns. 88 // owns.
88 static DictionaryValue* SerializeNotification( 89 static DictionaryValue* SerializeNotification(
89 const AppNotification& notification) { 90 const AppNotification& notification) {
90 DictionaryValue* dictionary = new DictionaryValue(); 91 DictionaryValue* dictionary = new DictionaryValue();
91 dictionary->SetString("title", notification.title()); 92 dictionary->SetString("title", notification.title());
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 content::Details<UnloadedExtensionInfo>(details)->extension; 299 content::Details<UnloadedExtensionInfo>(details)->extension;
299 if (!extension->is_app()) 300 if (!extension->is_app())
300 return; 301 return;
301 302
302 scoped_ptr<DictionaryValue> app_info(GetAppInfo(extension)); 303 scoped_ptr<DictionaryValue> app_info(GetAppInfo(extension));
303 scoped_ptr<base::FundamentalValue> uninstall_value( 304 scoped_ptr<base::FundamentalValue> uninstall_value(
304 Value::CreateBooleanValue( 305 Value::CreateBooleanValue(
305 content::Details<UnloadedExtensionInfo>(details)->reason == 306 content::Details<UnloadedExtensionInfo>(details)->reason ==
306 extension_misc::UNLOAD_REASON_UNINSTALL)); 307 extension_misc::UNLOAD_REASON_UNINSTALL));
307 if (app_info.get()) { 308 if (app_info.get()) {
309 scoped_ptr<base::FundamentalValue> from_page(
310 Value::CreateBooleanValue(uninstall_from_page_));
308 web_ui()->CallJavascriptFunction( 311 web_ui()->CallJavascriptFunction(
309 "ntp4.appRemoved", *app_info, *uninstall_value); 312 "ntp4.appRemoved", *app_info, *uninstall_value, *from_page);
310 } 313 }
311 break; 314 break;
312 } 315 }
313 case chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED: 316 case chrome::NOTIFICATION_EXTENSION_LAUNCHER_REORDERED:
314 // The promo may not load until a couple seconds after the first NTP view, 317 // The promo may not load until a couple seconds after the first NTP view,
315 // so we listen for the load notification and notify the NTP when ready. 318 // so we listen for the load notification and notify the NTP when ready.
316 case chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED: 319 case chrome::NOTIFICATION_WEB_STORE_PROMO_LOADED:
317 // TODO(estade): try to get rid of this inefficient operation. 320 // TODO(estade): Try to get rid of this inefficient operation.
318 HandleGetApps(NULL); 321 HandleGetApps(NULL);
319 break; 322 break;
320 case chrome::NOTIFICATION_PREF_CHANGED: { 323 case chrome::NOTIFICATION_PREF_CHANGED: {
321 DictionaryValue dictionary; 324 DictionaryValue dictionary;
322 FillAppDictionary(&dictionary); 325 FillAppDictionary(&dictionary);
323 web_ui()->CallJavascriptFunction("appsPrefChangeCallback", dictionary); 326 web_ui()->CallJavascriptFunction("appsPrefChangeCallback", dictionary);
324 break; 327 break;
325 } 328 }
326 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: { 329 case chrome::NOTIFICATION_EXTENSION_INSTALL_ERROR: {
327 CrxInstaller* crx_installer = content::Source<CrxInstaller>(source).ptr(); 330 CrxInstaller* crx_installer = content::Source<CrxInstaller>(source).ptr();
328 if (!Profile::FromWebUI(web_ui())->IsSameProfile( 331 if (!Profile::FromWebUI(web_ui())->IsSameProfile(
329 crx_installer->profile())) { 332 crx_installer->profile())) {
330 return; 333 return;
331 } 334 }
332 // Fall Through. 335 // Fall through.
333 } 336 }
334 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: { 337 case chrome::NOTIFICATION_EXTENSION_LOAD_ERROR: {
335 attempted_bookmark_app_install_ = false; 338 attempted_bookmark_app_install_ = false;
336 break; 339 break;
337 } 340 }
338 default: 341 default:
339 NOTREACHED(); 342 NOTREACHED();
340 } 343 }
341 } 344 }
342 345
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 if (!extension_id_prompting_.empty()) 616 if (!extension_id_prompting_.empty())
614 return; // Only one prompt at a time. 617 return; // Only one prompt at a time.
615 618
616 extension_id_prompting_ = extension_id; 619 extension_id_prompting_ = extension_id;
617 620
618 bool dont_confirm = false; 621 bool dont_confirm = false;
619 if (args->GetBoolean(1, &dont_confirm) && dont_confirm) { 622 if (args->GetBoolean(1, &dont_confirm) && dont_confirm) {
620 AutoReset<bool> auto_reset(&ignore_changes_, true); 623 AutoReset<bool> auto_reset(&ignore_changes_, true);
621 ExtensionUninstallAccepted(); 624 ExtensionUninstallAccepted();
622 } else { 625 } else {
626 // We don't use an AutoReset<bool> here as the uninstall dialog runs in a
Evan Stade 2012/01/17 19:45:29 the uninstall dialog runs in the UI thread, same a
Dan Beam 2012/01/18 00:07:23 Done. (removed because of following review comment
627 // different thread so it's not sync.
628 uninstall_from_page_ = true;
Evan Stade 2012/01/17 19:45:29 I don't see why you need this new boolean. What is
Dan Beam 2012/01/17 21:33:09 Done.
623 GetExtensionUninstallDialog()->ConfirmUninstall(extension); 629 GetExtensionUninstallDialog()->ConfirmUninstall(extension);
624 } 630 }
625 } 631 }
626 632
627 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) { 633 void AppLauncherHandler::HandleHideAppsPromo(const ListValue* args) {
628 // If the user has intentionally hidden the promotion, we'll uninstall all the 634 // If the user has intentionally hidden the promotion, we'll uninstall all the
629 // default apps (we know the user hasn't installed any apps on their own at 635 // default apps (we know the user hasn't installed any apps on their own at
630 // this point, or the promotion wouldn't have been shown). 636 // this point, or the promotion wouldn't have been shown).
631 // TODO(estade): this isn't used right now as we sort out the future of the 637 // TODO(estade): this isn't used right now as we sort out the future of the
632 // apps promo on ntp4. 638 // apps promo on ntp4.
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 highlight_app_id_.clear(); 841 highlight_app_id_.clear();
836 } 842 }
837 843
838 // static 844 // static
839 void AppLauncherHandler::RegisterUserPrefs(PrefService* pref_service) { 845 void AppLauncherHandler::RegisterUserPrefs(PrefService* pref_service) {
840 // TODO(csharp): We will want this to be a syncable preference instead. 846 // TODO(csharp): We will want this to be a syncable preference instead.
841 pref_service->RegisterListPref(prefs::kNTPAppPageNames, 847 pref_service->RegisterListPref(prefs::kNTPAppPageNames,
842 PrefService::UNSYNCABLE_PREF); 848 PrefService::UNSYNCABLE_PREF);
843 } 849 }
844 850
851 void AppLauncherHandler::CleanupAfterUninstall() {
852 uninstall_from_page_ = false;
853 extension_id_prompting_ = "";
Evan Stade 2012/01/17 19:45:29 .clear()
Dan Beam 2012/01/18 00:04:27 Done.
854 }
855
845 // static 856 // static
846 void AppLauncherHandler::RecordWebStoreLaunch(bool promo_active) { 857 void AppLauncherHandler::RecordWebStoreLaunch(bool promo_active) {
847 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, 858 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram,
848 extension_misc::APP_LAUNCH_NTP_WEBSTORE, 859 extension_misc::APP_LAUNCH_NTP_WEBSTORE,
849 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); 860 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY);
850 861
851 if (!promo_active) return; 862 if (!promo_active) return;
852 863
853 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, 864 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram,
854 extension_misc::PROMO_LAUNCH_WEB_STORE, 865 extension_misc::PROMO_LAUNCH_WEB_STORE,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 931
921 // The extension can be uninstalled in another window while the UI was 932 // The extension can be uninstalled in another window while the UI was
922 // showing. Do nothing in that case. 933 // showing. Do nothing in that case.
923 const Extension* extension = 934 const Extension* extension =
924 extension_service_->GetExtensionById(extension_id_prompting_, true); 935 extension_service_->GetExtensionById(extension_id_prompting_, true);
925 if (!extension) 936 if (!extension)
926 return; 937 return;
927 938
928 extension_service_->UninstallExtension(extension_id_prompting_, 939 extension_service_->UninstallExtension(extension_id_prompting_,
929 false /* external_uninstall */, NULL); 940 false /* external_uninstall */, NULL);
930 941 CleanupAfterUninstall();
931 extension_id_prompting_ = "";
932 } 942 }
933 943
934 void AppLauncherHandler::ExtensionUninstallCanceled() { 944 void AppLauncherHandler::ExtensionUninstallCanceled() {
935 extension_id_prompting_ = ""; 945 CleanupAfterUninstall();
936 } 946 }
937 947
938 void AppLauncherHandler::InstallUIProceed() { 948 void AppLauncherHandler::InstallUIProceed() {
939 // Do the re-enable work here. 949 // Do the re-enable work here.
940 DCHECK(!extension_id_prompting_.empty()); 950 DCHECK(!extension_id_prompting_.empty());
941 951
942 // The extension can be uninstalled in another window while the UI was 952 // The extension can be uninstalled in another window while the UI was
943 // showing. Do nothing in that case. 953 // showing. Do nothing in that case.
944 const Extension* extension = 954 const Extension* extension =
945 extension_service_->GetExtensionById(extension_id_prompting_, true); 955 extension_service_->GetExtensionById(extension_id_prompting_, true);
(...skipping 16 matching lines...) Expand all
962 // We record the histograms here because ExtensionUninstallCanceled is also 972 // We record the histograms here because ExtensionUninstallCanceled is also
963 // called when the extension uninstall dialog is canceled. 973 // called when the extension uninstall dialog is canceled.
964 const Extension* extension = 974 const Extension* extension =
965 extension_service_->GetExtensionById(extension_id_prompting_, true); 975 extension_service_->GetExtensionById(extension_id_prompting_, true);
966 std::string histogram_name = user_initiated ? 976 std::string histogram_name = user_initiated ?
967 "Extensions.Permissions_ReEnableCancel" : 977 "Extensions.Permissions_ReEnableCancel" :
968 "Extensions.Permissions_ReEnableAbort"; 978 "Extensions.Permissions_ReEnableAbort";
969 ExtensionService::RecordPermissionMessagesHistogram( 979 ExtensionService::RecordPermissionMessagesHistogram(
970 extension, histogram_name.c_str()); 980 extension, histogram_name.c_str());
971 981
972 ExtensionUninstallCanceled(); 982 CleanupAfterUninstall();
973 } 983 }
974 984
975 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() { 985 ExtensionUninstallDialog* AppLauncherHandler::GetExtensionUninstallDialog() {
976 if (!extension_uninstall_dialog_.get()) { 986 if (!extension_uninstall_dialog_.get()) {
977 extension_uninstall_dialog_.reset( 987 extension_uninstall_dialog_.reset(
978 ExtensionUninstallDialog::Create(Profile::FromWebUI(web_ui()), this)); 988 ExtensionUninstallDialog::Create(Profile::FromWebUI(web_ui()), this));
979 } 989 }
980 return extension_uninstall_dialog_.get(); 990 return extension_uninstall_dialog_.get();
981 } 991 }
982 992
983 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() { 993 ExtensionInstallUI* AppLauncherHandler::GetExtensionInstallUI() {
984 if (!extension_install_ui_.get()) { 994 if (!extension_install_ui_.get()) {
985 extension_install_ui_.reset( 995 extension_install_ui_.reset(
986 new ExtensionInstallUI(Profile::FromWebUI(web_ui()))); 996 new ExtensionInstallUI(Profile::FromWebUI(web_ui())));
987 } 997 }
988 return extension_install_ui_.get(); 998 return extension_install_ui_.get();
989 } 999 }
990 1000
991 void AppLauncherHandler::UninstallDefaultApps() { 1001 void AppLauncherHandler::UninstallDefaultApps() {
992 AppsPromo* apps_promo = extension_service_->apps_promo(); 1002 AppsPromo* apps_promo = extension_service_->apps_promo();
993 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); 1003 const ExtensionIdSet& app_ids = apps_promo->old_default_apps();
994 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); 1004 for (ExtensionIdSet::const_iterator iter = app_ids.begin();
995 iter != app_ids.end(); ++iter) { 1005 iter != app_ids.end(); ++iter) {
996 if (extension_service_->GetExtensionById(*iter, true)) 1006 if (extension_service_->GetExtensionById(*iter, true))
997 extension_service_->UninstallExtension(*iter, false, NULL); 1007 extension_service_->UninstallExtension(*iter, false, NULL);
998 } 1008 }
999 } 1009 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698