diff options
author | rbyers@chromium.org <rbyers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-04 15:37:34 +0000 |
---|---|---|
committer | rbyers@chromium.org <rbyers@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-04 15:37:34 +0000 |
commit | 3fb815de6240e629ecad71911f93e4e369d9c9eb (patch) | |
tree | eb4b21c3de18bb5e8d66e312712d35a357752556 | |
parent | 9c68deafbad5602922934ed412750636621ba938 (diff) | |
download | chromium_src-3fb815de6240e629ecad71911f93e4e369d9c9eb.zip chromium_src-3fb815de6240e629ecad71911f93e4e369d9c9eb.tar.gz chromium_src-3fb815de6240e629ecad71911f93e4e369d9c9eb.tar.bz2 |
Add an optional 'page_index' preference to apps and 'setPageIndex' message which can be used to set it.
This doesn't actually modify the behavior of the NTP whatsoever. It's a small extension which will be used by a future alternate NTP front-end that shares the same WebUI back-end code. Any NTP front-end that doesn't support pagination of apps will simply ignore this.
This also includes a simple unit test to verify the functioning of this preference.
BUG=73437
TEST=new test in unit_tests ('ExtensionPrefsPageIndex')
Review URL: http://codereview.chromium.org/6546017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76916 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/browser/extensions/extension_prefs.cc | 20 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_prefs.h | 8 | ||||
-rw-r--r-- | chrome/browser/extensions/extension_prefs_unittest.cc | 27 | ||||
-rw-r--r-- | chrome/browser/ui/webui/app_launcher_handler.cc | 18 | ||||
-rw-r--r-- | chrome/browser/ui/webui/app_launcher_handler.h | 5 |
5 files changed, 77 insertions, 1 deletions
diff --git a/chrome/browser/extensions/extension_prefs.cc b/chrome/browser/extensions/extension_prefs.cc index 2f6a31a..2022c11 100644 --- a/chrome/browser/extensions/extension_prefs.cc +++ b/chrome/browser/extensions/extension_prefs.cc @@ -79,6 +79,9 @@ const char kPrefLaunchType[] = "launchType"; // A preference determining the order of which the apps appear on the NTP. const char kPrefAppLaunchIndex[] = "app_launcher_index"; +// A preference determining the page on which an app appears in the NTP. +const char kPrefPageIndex[] = "page_index"; + // A preference specifying if the user dragged the app on the NTP. const char kPrefUserDraggedApp[] = "user_dragged_app_ntp"; @@ -1129,6 +1132,23 @@ void ExtensionPrefs::SetAppLauncherOrder( NotificationService::NoDetails()); } +int ExtensionPrefs::GetPageIndex(const std::string& extension_id) +{ + int value; + if (ReadExtensionPrefInteger(extension_id, kPrefPageIndex, &value)) + return value; + + return -1; +} + +void ExtensionPrefs::SetPageIndex(const std::string& extension_id, int index) +{ + CHECK_GE(index, 0); + UpdateExtensionPref(extension_id, kPrefPageIndex, + Value::CreateIntegerValue(index)); + SavePrefsAndNotify(); +} + bool ExtensionPrefs::WasAppDraggedByUser(const std::string& extension_id) { DictionaryValue* dictionary = GetExtensionPref(extension_id); if (!dictionary) { diff --git a/chrome/browser/extensions/extension_prefs.h b/chrome/browser/extensions/extension_prefs.h index 611d4b1..d672ce3 100644 --- a/chrome/browser/extensions/extension_prefs.h +++ b/chrome/browser/extensions/extension_prefs.h @@ -260,6 +260,14 @@ class ExtensionPrefs { // Sets the order the apps should be displayed in the app launcher. void SetAppLauncherOrder(const std::vector<std::string>& extension_ids); + // Get the application page index for an extension with |extension_id|. This + // determines which page an app will appear on in page-based NTPs. If + // the app has no page specified, -1 is returned. + int GetPageIndex(const std::string& extension_id); + + // Sets a specific page index for an extension with |extension_id|. + void SetPageIndex(const std::string& extension_id, int index); + // Returns true if the user repositioned the app on the app launcher via drag // and drop. bool WasAppDraggedByUser(const std::string& extension_id); diff --git a/chrome/browser/extensions/extension_prefs_unittest.cc b/chrome/browser/extensions/extension_prefs_unittest.cc index e6bd0a5..fd83f56 100644 --- a/chrome/browser/extensions/extension_prefs_unittest.cc +++ b/chrome/browser/extensions/extension_prefs_unittest.cc @@ -550,6 +550,33 @@ class ExtensionPrefsAppLaunchIndex : public ExtensionPrefsTest { }; TEST_F(ExtensionPrefsAppLaunchIndex, ExtensionPrefsAppLaunchIndex) {} +class ExtensionPrefsPageIndex : public ExtensionPrefsTest { + public: + virtual void Initialize() { + extension_id_ = prefs_.AddExtensionAndReturnId("page_index"); + + int page_index = prefs()->GetPageIndex(extension_id_); + // Extension should not have been assigned a page + EXPECT_EQ(page_index, -1); + + // Set the page index + prefs()->SetPageIndex(extension_id_, 2); + } + + virtual void Verify() { + // Verify the page index. + int page_index = prefs()->GetPageIndex(extension_id_); + EXPECT_EQ(page_index, 2); + + // This extension doesn't exist, so it should return -1. + EXPECT_EQ(-1, prefs()->GetPageIndex("foo")); + } + + private: + std::string extension_id_; +}; +TEST_F(ExtensionPrefsPageIndex, ExtensionPrefsPageIndex) {} + class ExtensionPrefsAppDraggedByUser : public ExtensionPrefsTest { public: virtual void Initialize() { diff --git a/chrome/browser/ui/webui/app_launcher_handler.cc b/chrome/browser/ui/webui/app_launcher_handler.cc index 955e8f9..51cd4ac 100644 --- a/chrome/browser/ui/webui/app_launcher_handler.cc +++ b/chrome/browser/ui/webui/app_launcher_handler.cc @@ -107,6 +107,12 @@ void AppLauncherHandler::CreateAppInfo(const Extension* extension, 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) { + // Only provide a value if one is stored + value->SetInteger("page_index", page_index); + } } // static @@ -170,6 +176,8 @@ void AppLauncherHandler::RegisterMessages() { NewCallback(this, &AppLauncherHandler::HandleCreateAppShortcut)); web_ui_->RegisterMessageCallback("reorderApps", NewCallback(this, &AppLauncherHandler::HandleReorderApps)); + web_ui_->RegisterMessageCallback("setPageIndex", + NewCallback(this, &AppLauncherHandler::HandleSetPageIndex)); } void AppLauncherHandler::Observe(NotificationType type, @@ -463,6 +471,16 @@ void AppLauncherHandler::HandleReorderApps(const ListValue* args) { extensions_service_->extension_prefs()->SetAppLauncherOrder(extension_ids); } +void AppLauncherHandler::HandleSetPageIndex(const ListValue* args) { + std::string extension_id; + double page_index; + CHECK(args->GetString(0, &extension_id)); + CHECK(args->GetDouble(1, &page_index)); + + extensions_service_->extension_prefs()->SetPageIndex(extension_id, + static_cast<int>(page_index)); +} + // static void AppLauncherHandler::RecordWebStoreLaunch(bool promo_active) { UMA_HISTOGRAM_ENUMERATION(extension_misc::kAppLaunchHistogram, diff --git a/chrome/browser/ui/webui/app_launcher_handler.h b/chrome/browser/ui/webui/app_launcher_handler.h index ba058ca..50a3ebb 100644 --- a/chrome/browser/ui/webui/app_launcher_handler.h +++ b/chrome/browser/ui/webui/app_launcher_handler.h @@ -72,9 +72,12 @@ class AppLauncherHandler // Callback for the "createAppShortcut" message. void HandleCreateAppShortcut(const ListValue* args); - // Callback for the 'reorderApps" message. + // Callback for the "reorderApps" message. void HandleReorderApps(const ListValue* args); + // Callback for the "setPageIndex" message. + void HandleSetPageIndex(const ListValue* args); + private: // Records a web store launch in the appropriate histograms. |promo_active| // specifies if the web store promotion was active. |