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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/ntp/app_launcher_handler.cc
diff --git a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc
index e8919666bc8d72fb723baebf5c15732b9c627e8b..742cbb2d5c0bc5c5c072cb9b8aca3cd06f135b38 100644
--- a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc
+++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc
@@ -160,27 +160,27 @@ void AppLauncherHandler::CreateAppInfo(const Extension* extension,
if (notification)
value->Set("notification", SerializeNotification(*notification));
- int app_launch_index = prefs->GetAppLaunchIndex(extension->id());
- if (app_launch_index == -1) {
+ std::string app_launch_index = prefs->GetAppLaunchIndex(extension->id());
+ if (app_launch_index.compare(extension_misc::kUnsetIndex) == 0) {
// Make sure every app has a launch index (some predate the launch index).
// The webstore's app launch index is set to -2 to make sure it's first.
// The next time the user drags (any) app this will be set to something
// sane (i.e. >= 0).
app_launch_index = extension->id() == extension_misc::kWebStoreAppId ?
- -2 : prefs->GetNextAppLaunchIndex(0);
+ "-2" : prefs->GetNextAppLaunchIndex("0");
prefs->SetAppLaunchIndex(extension->id(), app_launch_index);
}
- value->SetInteger("app_launch_index", app_launch_index);
+ value->SetString("app_launch_index", app_launch_index);
- int page_index = prefs->GetPageIndex(extension->id());
- if (page_index < 0) {
+ std::string page_index = prefs->GetPageIndex(extension->id());
+ if (page_index.compare(extension_misc::kUnsetIndex) == 0) {
// Make sure every app has a page index (some predate the page index).
// The webstore app should be on the first page.
page_index = extension->id() == extension_misc::kWebStoreAppId ?
- 0 : prefs->GetNaturalAppPageIndex();
+ "0" : prefs->GetNaturalAppPageIndex();
prefs->SetPageIndex(extension->id(), page_index);
}
- value->SetInteger("page_index", page_index);
+ value->SetString("page_index", page_index);
}
// TODO(estade): remove this. We record app launches via js calls rather than
@@ -421,10 +421,11 @@ void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) {
if (NewTabUI::NTP4Enabled()) {
PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs();
- const ListValue* app_page_names = prefs->GetList(prefs::kNTPAppPageNames);
- if (app_page_names && app_page_names->GetSize()) {
+ const DictionaryValue* app_page_names =
+ prefs->GetDictionary(prefs::kNTPAppPageNames);
+ if (app_page_names && app_page_names->size()) {
dictionary->Set("appPageNames",
- static_cast<ListValue*>(app_page_names->DeepCopy()));
+ static_cast<DictionaryValue*>(app_page_names->DeepCopy()));
}
}
}
@@ -716,6 +717,7 @@ void AppLauncherHandler::HandleSetPageIndex(const ListValue* args) {
double page_index;
CHECK(args->GetString(0, &extension_id));
CHECK(args->GetDouble(1, &page_index));
+ std::string page_index_str = base::IntToString(static_cast<int>(page_index));
// Don't update the page; it already knows the apps have been reordered.
scoped_ptr<AutoReset<bool> > auto_reset;
@@ -723,7 +725,7 @@ void AppLauncherHandler::HandleSetPageIndex(const ListValue* args) {
auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true));
extension_service_->extension_prefs()->SetPageIndex(extension_id,
- static_cast<int>(page_index));
+ page_index_str);
}
void AppLauncherHandler::HandlePromoSeen(const ListValue* args) {
@@ -738,12 +740,13 @@ void AppLauncherHandler::HandleSaveAppPageName(const ListValue* args) {
double page_index;
CHECK(args->GetDouble(1, &page_index));
+ std::string page_index_str = base::IntToString(static_cast<int>(page_index));
AutoReset<bool> auto_reset(&ignore_changes_, true);
PrefService* prefs = Profile::FromWebUI(web_ui_)->GetPrefs();
- ListPrefUpdate update(prefs, prefs::kNTPAppPageNames);
- ListValue* list = update.Get();
- list->Set(static_cast<size_t>(page_index), Value::CreateStringValue(name));
+ DictionaryPrefUpdate update(prefs, prefs::kNTPAppPageNames);
+ DictionaryValue* dictionary = update.Get();
+ dictionary->Set(page_index_str, Value::CreateStringValue(name));
}
void AppLauncherHandler::HandleGenerateAppForLink(const ListValue* args) {
@@ -756,6 +759,7 @@ void AppLauncherHandler::HandleGenerateAppForLink(const ListValue* args) {
double page_index;
CHECK(args->GetDouble(2, &page_index));
+ std::string page_index_str = base::IntToString(static_cast<int>(page_index));
Profile* profile = Profile::FromWebUI(web_ui_);
FaviconService* favicon_service =
@@ -769,7 +773,7 @@ void AppLauncherHandler::HandleGenerateAppForLink(const ListValue* args) {
install_info->is_bookmark_app = true;
install_info->title = title;
install_info->app_url = launch_url;
- install_info->page_index = static_cast<int>(page_index);
+ install_info->page_index = page_index_str;
FaviconService::Handle h = favicon_service->GetFaviconForURL(
launch_url, history::FAVICON, &favicon_consumer_,
@@ -832,11 +836,11 @@ void AppLauncherHandler::SetAppToBeHighlighted() {
// static
void AppLauncherHandler::RegisterUserPrefs(PrefService* pref_service) {
// TODO(csilv): We will want this to be a syncable preference instead.
- pref_service->RegisterListPref(prefs::kNTPAppPageNames,
- PrefService::UNSYNCABLE_PREF);
+ pref_service->RegisterDictionaryPref(prefs::kNTPAppPageNames,
+ PrefService::UNSYNCABLE_PREF);
}
-// statiic
+// static
void AppLauncherHandler::RecordWebStoreLaunch(bool promo_active) {
UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram,
extension_misc::APP_LAUNCH_NTP_WEBSTORE,

Powered by Google App Engine
This is Rietveld 408576698