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

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

Issue 8198003: Convert app_launch_index and page_index from int to StringOrdinal. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 9 years, 2 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 ExtensionPrefs::LAUNCH_DEFAULT)); 153 ExtensionPrefs::LAUNCH_DEFAULT));
154 value->SetBoolean("offline_enabled", extension->offline_enabled()); 154 value->SetBoolean("offline_enabled", extension->offline_enabled());
155 value->SetBoolean("is_component", 155 value->SetBoolean("is_component",
156 extension->location() == Extension::COMPONENT); 156 extension->location() == Extension::COMPONENT);
157 value->SetBoolean("is_webstore", 157 value->SetBoolean("is_webstore",
158 extension->id() == extension_misc::kWebStoreAppId); 158 extension->id() == extension_misc::kWebStoreAppId);
159 159
160 if (notification) 160 if (notification)
161 value->Set("notification", SerializeNotification(*notification)); 161 value->Set("notification", SerializeNotification(*notification));
162 162
163 int app_launch_index = prefs->GetAppLaunchIndex(extension->id()); 163 std::string app_launch_index = prefs->GetAppLaunchIndex(extension->id());
164 if (app_launch_index == -1) { 164 if (app_launch_index.compare(extension_misc::kUnsetIndex) == 0) {
165 // Make sure every app has a launch index (some predate the launch index). 165 // Make sure every app has a launch index (some predate the launch index).
166 // The webstore's app launch index is set to -2 to make sure it's first. 166 // The webstore's app launch index is set to -2 to make sure it's first.
167 // The next time the user drags (any) app this will be set to something 167 // The next time the user drags (any) app this will be set to something
168 // sane (i.e. >= 0). 168 // sane (i.e. >= 0).
169 app_launch_index = extension->id() == extension_misc::kWebStoreAppId ? 169 app_launch_index = extension->id() == extension_misc::kWebStoreAppId ?
170 -2 : prefs->GetNextAppLaunchIndex(0); 170 "-2" : prefs->GetNextAppLaunchIndex("0");
171 prefs->SetAppLaunchIndex(extension->id(), app_launch_index); 171 prefs->SetAppLaunchIndex(extension->id(), app_launch_index);
172 } 172 }
173 value->SetInteger("app_launch_index", app_launch_index); 173 value->SetString("app_launch_index", app_launch_index);
174 174
175 int page_index = prefs->GetPageIndex(extension->id()); 175 std::string page_index = prefs->GetPageIndex(extension->id());
176 if (page_index < 0) { 176 if (page_index.compare(extension_misc::kUnsetIndex) == 0) {
177 // Make sure every app has a page index (some predate the page index). 177 // Make sure every app has a page index (some predate the page index).
178 // The webstore app should be on the first page. 178 // The webstore app should be on the first page.
179 page_index = extension->id() == extension_misc::kWebStoreAppId ? 179 page_index = extension->id() == extension_misc::kWebStoreAppId ?
180 0 : prefs->GetNaturalAppPageIndex(); 180 "0" : prefs->GetNaturalAppPageIndex();
181 prefs->SetPageIndex(extension->id(), page_index); 181 prefs->SetPageIndex(extension->id(), page_index);
182 } 182 }
183 value->SetInteger("page_index", page_index); 183 value->SetString("page_index", page_index);
184 } 184 }
185 185
186 // TODO(estade): remove this. We record app launches via js calls rather than 186 // TODO(estade): remove this. We record app launches via js calls rather than
187 // pings for ntp4. 187 // pings for ntp4.
188 // static 188 // static
189 bool AppLauncherHandler::HandlePing(Profile* profile, const std::string& path) { 189 bool AppLauncherHandler::HandlePing(Profile* profile, const std::string& path) {
190 std::vector<std::string> params; 190 std::vector<std::string> params;
191 base::SplitString(path, '+', &params); 191 base::SplitString(path, '+', &params);
192 192
193 // Check if the user launched an app from the most visited or recently 193 // Check if the user launched an app from the most visited or recently
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 dictionary->SetBoolean("disableCreateAppShortcut", true); 414 dictionary->SetBoolean("disableCreateAppShortcut", true);
415 #endif 415 #endif
416 416
417 dictionary->SetBoolean( 417 dictionary->SetBoolean(
418 "showLauncher", 418 "showLauncher",
419 extension_service_->apps_promo()->ShouldShowAppLauncher( 419 extension_service_->apps_promo()->ShouldShowAppLauncher(
420 extension_service_->GetAppIds())); 420 extension_service_->GetAppIds()));
421 421
422 if (NewTabUI::NTP4Enabled()) { 422 if (NewTabUI::NTP4Enabled()) {
423 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); 423 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs();
424 const ListValue* app_page_names = prefs->GetList(prefs::kNTPAppPageNames); 424 const DictionaryValue* app_page_names =
425 if (app_page_names && app_page_names->GetSize()) { 425 prefs->GetDictionary(prefs::kNTPAppPageNames);
426 if (app_page_names && app_page_names->size()) {
426 dictionary->Set("appPageNames", 427 dictionary->Set("appPageNames",
427 static_cast<ListValue*>(app_page_names->DeepCopy())); 428 static_cast<DictionaryValue*>(app_page_names->DeepCopy())) ;
428 } 429 }
429 } 430 }
430 } 431 }
431 432
432 DictionaryValue* AppLauncherHandler::GetAppInfo(const Extension* extension) { 433 DictionaryValue* AppLauncherHandler::GetAppInfo(const Extension* extension) {
433 AppNotificationManager* notification_manager = 434 AppNotificationManager* notification_manager =
434 extension_service_->app_notification_manager(); 435 extension_service_->app_notification_manager();
435 DictionaryValue* app_info = new DictionaryValue(); 436 DictionaryValue* app_info = new DictionaryValue();
436 // CreateAppInfo can change the extension prefs. 437 // CreateAppInfo can change the extension prefs.
437 AutoReset<bool> auto_reset(&ignore_changes_, true); 438 AutoReset<bool> auto_reset(&ignore_changes_, true);
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 710
710 extension_service_->extension_prefs()->SetAppDraggedByUser(dragged_app_id); 711 extension_service_->extension_prefs()->SetAppDraggedByUser(dragged_app_id);
711 extension_service_->extension_prefs()->SetAppLauncherOrder(extension_ids); 712 extension_service_->extension_prefs()->SetAppLauncherOrder(extension_ids);
712 } 713 }
713 714
714 void AppLauncherHandler::HandleSetPageIndex(const ListValue* args) { 715 void AppLauncherHandler::HandleSetPageIndex(const ListValue* args) {
715 std::string extension_id; 716 std::string extension_id;
716 double page_index; 717 double page_index;
717 CHECK(args->GetString(0, &extension_id)); 718 CHECK(args->GetString(0, &extension_id));
718 CHECK(args->GetDouble(1, &page_index)); 719 CHECK(args->GetDouble(1, &page_index));
720 std::string page_index_str = base::IntToString(static_cast<int>(page_index));
719 721
720 // Don't update the page; it already knows the apps have been reordered. 722 // Don't update the page; it already knows the apps have been reordered.
721 scoped_ptr<AutoReset<bool> > auto_reset; 723 scoped_ptr<AutoReset<bool> > auto_reset;
722 if (NewTabUI::NTP4Enabled()) 724 if (NewTabUI::NTP4Enabled())
723 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); 725 auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true));
724 726
725 extension_service_->extension_prefs()->SetPageIndex(extension_id, 727 extension_service_->extension_prefs()->SetPageIndex(extension_id,
726 static_cast<int>(page_index)); 728 page_index_str);
727 } 729 }
728 730
729 void AppLauncherHandler::HandlePromoSeen(const ListValue* args) { 731 void AppLauncherHandler::HandlePromoSeen(const ListValue* args) {
730 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, 732 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram,
731 extension_misc::PROMO_SEEN, 733 extension_misc::PROMO_SEEN,
732 extension_misc::PROMO_BUCKET_BOUNDARY); 734 extension_misc::PROMO_BUCKET_BOUNDARY);
733 } 735 }
734 736
735 void AppLauncherHandler::HandleSaveAppPageName(const ListValue* args) { 737 void AppLauncherHandler::HandleSaveAppPageName(const ListValue* args) {
736 string16 name; 738 string16 name;
737 CHECK(args->GetString(0, &name)); 739 CHECK(args->GetString(0, &name));
738 740
739 double page_index; 741 double page_index;
740 CHECK(args->GetDouble(1, &page_index)); 742 CHECK(args->GetDouble(1, &page_index));
743 std::string page_index_str = base::IntToString(static_cast<int>(page_index));
741 744
742 AutoReset<bool> auto_reset(&ignore_changes_, true); 745 AutoReset<bool> auto_reset(&ignore_changes_, true);
743 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs(); 746 PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs();
744 ListPrefUpdate update(prefs, prefs::kNTPAppPageNames); 747 DictionaryPrefUpdate update(prefs, prefs::kNTPAppPageNames);
745 ListValue* list = update.Get(); 748 DictionaryValue* dictionary = update.Get();
746 list->Set(static_cast<size_t>(page_index), Value::CreateStringValue(name)); 749 dictionary->Set(page_index_str, Value::CreateStringValue(name));
747 } 750 }
748 751
749 void AppLauncherHandler::HandleGenerateAppForLink(const ListValue* args) { 752 void AppLauncherHandler::HandleGenerateAppForLink(const ListValue* args) {
750 std::string url; 753 std::string url;
751 CHECK(args->GetString(0, &url)); 754 CHECK(args->GetString(0, &url));
752 GURL launch_url(url); 755 GURL launch_url(url);
753 756
754 string16 title; 757 string16 title;
755 CHECK(args->GetString(1, &title)); 758 CHECK(args->GetString(1, &title));
756 759
757 double page_index; 760 double page_index;
758 CHECK(args->GetDouble(2, &page_index)); 761 CHECK(args->GetDouble(2, &page_index));
762 std::string page_index_str = base::IntToString(static_cast<int>(page_index));
759 763
760 Profile* profile = Profile::FromWebUI(web_ui_); 764 Profile* profile = Profile::FromWebUI(web_ui_);
761 FaviconService* favicon_service = 765 FaviconService* favicon_service =
762 profile->GetFaviconService(Profile::EXPLICIT_ACCESS); 766 profile->GetFaviconService(Profile::EXPLICIT_ACCESS);
763 if (!favicon_service) { 767 if (!favicon_service) {
764 LOG(ERROR) << "No favicon service"; 768 LOG(ERROR) << "No favicon service";
765 return; 769 return;
766 } 770 }
767 771
768 scoped_ptr<AppInstallInfo> install_info(new AppInstallInfo()); 772 scoped_ptr<AppInstallInfo> install_info(new AppInstallInfo());
769 install_info->is_bookmark_app = true; 773 install_info->is_bookmark_app = true;
770 install_info->title = title; 774 install_info->title = title;
771 install_info->app_url = launch_url; 775 install_info->app_url = launch_url;
772 install_info->page_index = static_cast<int>(page_index); 776 install_info->page_index = page_index_str;
773 777
774 FaviconService::Handle h = favicon_service->GetFaviconForURL( 778 FaviconService::Handle h = favicon_service->GetFaviconForURL(
775 launch_url, history::FAVICON, &favicon_consumer_, 779 launch_url, history::FAVICON, &favicon_consumer_,
776 NewCallback(this, &AppLauncherHandler::OnFaviconForApp)); 780 NewCallback(this, &AppLauncherHandler::OnFaviconForApp));
777 favicon_consumer_.SetClientData(favicon_service, h, install_info.release()); 781 favicon_consumer_.SetClientData(favicon_service, h, install_info.release());
778 } 782 }
779 783
780 void AppLauncherHandler::HandleRecordAppLaunchByURL( 784 void AppLauncherHandler::HandleRecordAppLaunchByURL(
781 const base::ListValue* args) { 785 const base::ListValue* args) {
782 std::string url; 786 std::string url;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 return; 829 return;
826 830
827 scoped_ptr<StringValue> app_id(Value::CreateStringValue(highlight_app_id_)); 831 scoped_ptr<StringValue> app_id(Value::CreateStringValue(highlight_app_id_));
828 web_ui_->CallJavascriptFunction("ntp4.setAppToBeHighlighted", *app_id); 832 web_ui_->CallJavascriptFunction("ntp4.setAppToBeHighlighted", *app_id);
829 highlight_app_id_.clear(); 833 highlight_app_id_.clear();
830 } 834 }
831 835
832 // static 836 // static
833 void AppLauncherHandler::RegisterUserPrefs(PrefService* pref_service) { 837 void AppLauncherHandler::RegisterUserPrefs(PrefService* pref_service) {
834 // TODO(csilv): We will want this to be a syncable preference instead. 838 // TODO(csilv): We will want this to be a syncable preference instead.
835 pref_service->RegisterListPref(prefs::kNTPAppPageNames, 839 pref_service->RegisterDictionaryPref(prefs::kNTPAppPageNames,
836 PrefService::UNSYNCABLE_PREF); 840 PrefService::UNSYNCABLE_PREF);
837 } 841 }
838 842
839 // statiic 843 // static
840 void AppLauncherHandler::RecordWebStoreLaunch(bool promo_active) { 844 void AppLauncherHandler::RecordWebStoreLaunch(bool promo_active) {
841 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, 845 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram,
842 extension_misc::APP_LAUNCH_NTP_WEBSTORE, 846 extension_misc::APP_LAUNCH_NTP_WEBSTORE,
843 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY); 847 extension_misc::APP_LAUNCH_BUCKET_BOUNDARY);
844 848
845 if (!promo_active) return; 849 if (!promo_active) return;
846 850
847 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram, 851 UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppsPromoHistogram,
848 extension_misc::PROMO_LAUNCH_WEB_STORE, 852 extension_misc::PROMO_LAUNCH_WEB_STORE,
849 extension_misc::PROMO_BUCKET_BOUNDARY); 853 extension_misc::PROMO_BUCKET_BOUNDARY);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 994
991 void AppLauncherHandler::UninstallDefaultApps() { 995 void AppLauncherHandler::UninstallDefaultApps() {
992 AppsPromo* apps_promo = extension_service_->apps_promo(); 996 AppsPromo* apps_promo = extension_service_->apps_promo();
993 const ExtensionIdSet& app_ids = apps_promo->old_default_apps(); 997 const ExtensionIdSet& app_ids = apps_promo->old_default_apps();
994 for (ExtensionIdSet::const_iterator iter = app_ids.begin(); 998 for (ExtensionIdSet::const_iterator iter = app_ids.begin();
995 iter != app_ids.end(); ++iter) { 999 iter != app_ids.end(); ++iter) {
996 if (extension_service_->GetExtensionById(*iter, true)) 1000 if (extension_service_->GetExtensionById(*iter, true))
997 extension_service_->UninstallExtension(*iter, false, NULL); 1001 extension_service_->UninstallExtension(*iter, false, NULL);
998 } 1002 }
999 } 1003 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698