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

Unified Diff: chrome/browser/extensions/extension_prefs.h

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: Addressing review comments Created 9 years, 1 month 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
« no previous file with comments | « chrome/browser/extensions/extension_browsertest.cc ('k') | chrome/browser/extensions/extension_prefs.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/extensions/extension_prefs.h
diff --git a/chrome/browser/extensions/extension_prefs.h b/chrome/browser/extensions/extension_prefs.h
index d7760a76d98a7210d7a0aae4bbb75cdd10689c7c..7591149885514cc83ef59a9e63cf7c51405b279c 100644
--- a/chrome/browser/extensions/extension_prefs.h
+++ b/chrome/browser/extensions/extension_prefs.h
@@ -16,6 +16,7 @@
#include "chrome/browser/extensions/extension_prefs_scope.h"
#include "chrome/browser/prefs/pref_service.h"
#include "chrome/common/extensions/extension.h"
+#include "chrome/common/string_ordinal.h"
#include "googleurl/src/gurl.h"
class ExtensionPrefValueMap;
@@ -99,11 +100,12 @@ class ExtensionPrefs : public ExtensionContentSettingsStore::Observer {
void SetToolbarOrder(const std::vector<std::string>& extension_ids);
// Called when an extension is installed, so that prefs get created.
- // If |page_index| is -1, and the then a page will be found for the App.
+ // If |page_ordinal| is an invalid ordinal, then a page will be found
+ // for the App.
void OnExtensionInstalled(const Extension* extension,
Extension::State initial_state,
bool from_webstore,
- int page_index);
+ const StringOrdinal& page_ordinal);
// Called when an extension is uninstalled, so that prefs get cleaned up.
void OnExtensionUninstalled(const std::string& extension_id,
@@ -304,36 +306,60 @@ class ExtensionPrefs : public ExtensionContentSettingsStore::Observer {
bool GetWebStoreLogin(std::string* result);
void SetWebStoreLogin(const std::string& login);
- // Get the application launch index for an extension with |extension_id|. This
- // determines the order of which the applications appear on the New Tab Page.
- // A value of 0 generally indicates top left. If the extension has no launch
- // index a -1 value is returned.
- int GetAppLaunchIndex(const std::string& extension_id);
-
- // Sets a specific launch index for an extension with |extension_id|.
- void SetAppLaunchIndex(const std::string& extension_id, int index);
-
- // Gets the next available application launch index. This is 1 higher than the
- // highest current application launch index found for the page |on_page|.
- int GetNextAppLaunchIndex(int on_page);
-
- // Gets the page a new app should install to. Starts on page 0, and if there
- // are N or more apps on it, tries to install on the next page.
- int GetNaturalAppPageIndex();
-
- // 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);
-
- // Removes the page index for an extension.
- void ClearPageIndex(const std::string& extension_id);
+ // Get the first page ordinal value.
+ StringOrdinal GetFirstAppPage() const;
+
+ // Create a StringOrdinal which will be the first element for the given page.
+ StringOrdinal CreateFirstAppLaunchOrdinal(const StringOrdinal& page_ordinal)
+ const;
+
+ // Get the application launch ordinal for an extension with |extension_id|.
+ // This determines the order of which the applications appear on the New Tab
+ // Page. A string value close to |a*| generally indicates top left. If the
+ // extension has no launch ordinal, an invalid StringOrdinal is returned.
+ StringOrdinal GetAppLaunchOrdinal(const std::string& extension_id) const;
+
+ // Sets a specific launch ordinal for an extension with |extension_id|.
+ void SetAppLaunchOrdinal(const std::string& extension_id,
+ const StringOrdinal& ordinal);
+
+ // Gets the next available application launch ordinal. This is higher than the
+ // highest current application launch ordinal found for the page
+ // |page_ordinal|.
+ StringOrdinal GetNextAppLaunchOrdinal(const StringOrdinal& page_ordinal)
+ const;
+
+ // Gets the page a new app should install to. Starts on the first page, and if
+ // there are N or more apps on it, tries to install on the next page.
+ StringOrdinal GetNaturalAppPageOrdinal() const;
+
+ // Updates the app launcher value for the moved extension so that it is now
+ // located after the given predecessor and before the successor.
+ // Empty strings are used to indicate no successor or predecessor.
+ void OnExtensionMoved(
+ const std::string& moved_extension_id,
+ const std::string& predecessor_extension_id,
+ const std::string& successor_extension_id);
+
+ // Get the application page ordinal 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, an invalid StringOrdinal is returned.
+ StringOrdinal GetPageOrdinal(const std::string& extension_id) const;
+
+ // Sets a specific page ordinal for an extension with |extension_id|.
+ void SetPageOrdinal(const std::string& extension_id,
+ const StringOrdinal& ordinal);
+
+ // Removes the page ordinal for an extension.
+ void ClearPageOrdinal(const std::string& extension_id);
+
+ // Convert the page StringOrdinal value to its integer equivalent. This takes
+ // O(# of apps) worst-case.
+ int PageStringOrdinalAsInteger(const StringOrdinal& page_ordinal) const;
+
+ // Converts the page index integer to its StringOrdinal equivalent. This takes
+ // O(# of apps) worst-case.
+ StringOrdinal PageIntegerAsStringOrdinal(size_t page_index);
// Returns true if the user repositioned the app on the app launcher via drag
// and drop.
@@ -457,6 +483,11 @@ class ExtensionPrefs : public ExtensionContentSettingsStore::Observer {
const std::string& pref_key,
const base::ListValue** out_value);
+ // Reads a string pref |pref_key| from extension with id |extension_id|.
+ bool ReadExtensionPrefString(const std::string& extension_id,
+ const std::string& pref_key,
+ std::string* out_value) const;
+
// Interprets the list pref, |pref_key| in |extension_id|'s preferences, as a
// URLPatternSet. The |valid_schemes| specify how to parse the URLPatterns.
bool ReadExtensionPrefURLPatternSet(const std::string& extension_id,
@@ -514,17 +545,52 @@ class ExtensionPrefs : public ExtensionContentSettingsStore::Observer {
// Migrates the permissions data in the pref store.
void MigratePermissions(const ExtensionIdSet& extension_ids);
+ // Migrates the app launcher and page index values.
+ void MigrateAppIndex(const ExtensionIdSet& extension_ids);
+
// Checks whether there is a state pref for the extension and if so, whether
// it matches |check_state|.
bool DoesExtensionHaveState(const std::string& id,
Extension::State check_state) const;
+ // If page |page_ordinal| contains at least 1 apps, this function returns
+ // true with |min_app_launch_value| containing the lowest ordinal on the page
+ // and |max_app_launch_value| containing the largest ordinal on the page. If
+ // there are no apps on the page this function returns false. It is an
+ // error to call this function with an invalid |page_ordinal| or
+ // NULl values for |min_app_launch_value| or |max_app_launch_value|.
Dan Beam 2011/11/29 01:28:25 NULL
csharp 2011/11/29 14:50:51 Done.
+ bool GetMaxAndMinAppLaunchOrdinalsOnPage(
+ const StringOrdinal& page_ordinal,
+ StringOrdinal* min_app_launch_value,
+ StringOrdinal* max_app_launch_value) const;
+
+ // Initialize the |page_ordinal_map_| with the page ordinals used by the
+ // given extensions.
+ void InitializePageOrdinalMap(const ExtensionIdSet& extension_ids);
+
+ // Called when an application changes the value of its page ordinal so that
+ // |page_ordinal_map_| is aware that |old_value| page ordinal has been
+ // replace by the |new_value| page ordinal and adjusts its mapping
+ // accordingly. This works with valid and invalid StringOrdinals.
+ void UpdatePageOrdinalMap(const StringOrdinal& old_value,
+ const StringOrdinal& new_value);
+
+ // Called when an application is installed to set the |page_ordinal| value and
+ // app launch value in |extension_dict| for the new application.
+ void SetAppOrdinalValues(DictionaryValue* extension_dict,
+ const StringOrdinal& page_ordinal);
+
// The pref service specific to this set of extension prefs. Owned by profile.
PrefService* prefs_;
// Base extensions install directory.
FilePath install_directory_;
+ // A map of all the StringOrdinal page indices mapping to how often they are
+ // used, this is used for mapping the StringOrdinals to their integer
+ // equivalent as well as quick lookup of the sorted StringOrdinals.
+ std::map<StringOrdinal, int, StringOrdinalLessThan> page_ordinal_map_;
+
// Weak pointer, owned by Profile.
ExtensionPrefValueMap* extension_pref_value_map_;
« no previous file with comments | « chrome/browser/extensions/extension_browsertest.cc ('k') | chrome/browser/extensions/extension_prefs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698