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 71d2ca82a3aa4568027c3f88a285b9370c94c056..7dccd79034a63f5cd594df4a0839347d5539bada 100644 |
--- a/chrome/browser/ui/webui/ntp/app_launcher_handler.cc |
+++ b/chrome/browser/ui/webui/ntp/app_launcher_handler.cc |
@@ -160,27 +160,31 @@ 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) { |
+ StringOrdinal page_index = prefs->GetPageIndex(extension->id()); |
+ if (!page_index.IsValid()) { |
+ // 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 ? |
+ prefs->GetFirstAppPage() : prefs->GetNaturalAppPageIndex(); |
+ prefs->SetPageIndex(extension->id(), page_index); |
+ } |
+ // We convert the page_index to an integer becuase the pages are referenced |
+ // from within an array in the javascript code, which can't be easily |
+ // changed to handle the StringOrdinal values, so we do the conversion here. |
+ value->SetInteger("page_index", prefs->PageIndexAsInteger(page_index)); |
+ |
+ StringOrdinal app_launch_index = prefs->GetAppLaunchIndex(extension->id()); |
+ if (!app_launch_index.IsValid()) { |
// 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); |
+ prefs->CreateFirstAppLaunchIndex(page_index) |
+ : prefs->GetNextAppLaunchIndex(page_index); |
prefs->SetAppLaunchIndex(extension->id(), app_launch_index); |
} |
- value->SetInteger("app_launch_index", app_launch_index); |
- |
- int page_index = prefs->GetPageIndex(extension->id()); |
- if (page_index < 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(); |
- prefs->SetPageIndex(extension->id(), page_index); |
- } |
- value->SetInteger("page_index", page_index); |
+ value->SetString("app_launch_index", app_launch_index.ToString()); |
} |
WebUIMessageHandler* AppLauncherHandler::Attach(WebUI* web_ui) { |
@@ -357,7 +361,7 @@ void AppLauncherHandler::FillAppDictionary(DictionaryValue* dictionary) { |
// and this fixes it. If we don't fix it, GetNaturalAppPageIndex() doesn't |
// work. See http://crbug.com/98325 |
ExtensionPrefs* prefs = extension_service_->extension_prefs(); |
- if (prefs->GetPageIndex((*it)->id()) != -1) |
+ if (prefs->GetPageIndex((*it)->id()).IsValid()) |
prefs->ClearPageIndex((*it)->id()); |
} |
} |
@@ -409,17 +413,21 @@ 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()) { |
- ListPrefUpdate update(prefs, prefs::kNTPAppPageNames); |
- ListValue* list = update.Get(); |
- list->Set(0, Value::CreateStringValue( |
+ const DictionaryValue* app_page_names = |
+ prefs->GetDictionary(prefs::kNTPAppPageNames); |
+ if (!app_page_names || !app_page_names->size()) { |
+ DictionaryPrefUpdate update(prefs, prefs::kNTPAppPageNames); |
+ DictionaryValue* names_dictionary = update.Get(); |
+ StringOrdinal new_page = StringOrdinal::CreateInitialOrdinal(); |
+ names_dictionary->Set(new_page.ToString(), Value::CreateStringValue( |
l10n_util::GetStringUTF16(IDS_APP_DEFAULT_PAGE_NAME))); |
dictionary->Set("appPageNames", |
- static_cast<ListValue*>(list->DeepCopy())); |
+ static_cast<DictionaryValue*>( |
+ names_dictionary->DeepCopy())); |
} else { |
dictionary->Set("appPageNames", |
- static_cast<ListValue*>(app_page_names->DeepCopy())); |
+ static_cast<DictionaryValue*>( |
+ app_page_names->DeepCopy())); |
} |
} |
} |
@@ -705,14 +713,18 @@ void AppLauncherHandler::HandleReorderApps(const ListValue* args) { |
auto_reset.reset(new AutoReset<bool>(&ignore_changes_, true)); |
extension_service_->extension_prefs()->SetAppDraggedByUser(dragged_app_id); |
- extension_service_->extension_prefs()->SetAppLauncherOrder(extension_ids); |
+ extension_service_->extension_prefs()->SetAppLauncherOrder(extension_ids, |
+ dragged_app_id); |
} |
void AppLauncherHandler::HandleSetPageIndex(const ListValue* args) { |
std::string extension_id; |
- double page_index; |
+ double page_index_raw; |
CHECK(args->GetString(0, &extension_id)); |
- CHECK(args->GetDouble(1, &page_index)); |
+ CHECK(args->GetDouble(1, &page_index_raw)); |
+ StringOrdinal page_index = |
+ extension_service_->extension_prefs()->PageIndexAsStringOrdinal( |
+ static_cast<size_t>(page_index_raw)); |
// Don't update the page; it already knows the apps have been reordered. |
scoped_ptr<AutoReset<bool> > auto_reset; |
@@ -720,7 +732,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); |
} |
void AppLauncherHandler::HandlePromoSeen(const ListValue* args) { |
@@ -735,12 +747,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) { |
@@ -753,6 +766,9 @@ void AppLauncherHandler::HandleGenerateAppForLink(const ListValue* args) { |
double page_index; |
CHECK(args->GetDouble(2, &page_index)); |
+ StringOrdinal page_index_str = |
+ extension_service_->extension_prefs()->PageIndexAsStringOrdinal( |
+ static_cast<int>(page_index)); |
Profile* profile = Profile::FromWebUI(web_ui_); |
FaviconService* favicon_service = |
@@ -766,7 +782,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_, |
@@ -843,11 +859,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, |