Chromium Code Reviews| 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..5bfc65ae781ecfec549ea17d8a10fe38c15e1582 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); |
| + StringOrdinal page_ordinal); |
|
akalin
2011/11/23 18:50:19
const ref
csharp
2011/11/23 22:10:01
Done.
|
| // Called when an extension is uninstalled, so that prefs get cleaned up. |
| void OnExtensionUninstalled(const std::string& extension_id, |
| @@ -304,36 +306,56 @@ 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); |
| + // Get the first page ordinal value. |
| + StringOrdinal GetFirstAppPage() const; |
| - // Sets a specific launch index for an extension with |extension_id|. |
| - void SetAppLaunchIndex(const std::string& extension_id, int index); |
| + // Create a StringOrdinal which will be the first element for the given page. |
| + StringOrdinal CreateFirstAppLaunchOrdinal(const StringOrdinal& page_ordinal) |
| + const; |
| - // 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); |
| + // 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; |
| - // 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 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; |
| // Sets the order the apps should be displayed in the app launcher. |
| - void SetAppLauncherOrder(const std::vector<std::string>& extension_ids); |
| + void SetAppLauncherOrder(const std::vector<std::string>& extension_ids, |
|
akalin
2011/11/23 18:50:19
this function doesn't really do what it says anymo
csharp
2011/11/23 22:10:01
Done.
|
| + const std::string& moved_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; |
| - // 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 ordinal for an extension with |extension_id|. |
| + void SetPageOrdinal(const std::string& extension_id, |
| + const StringOrdinal& ordinal); |
| - // Sets a specific page index for an extension with |extension_id|. |
| - void SetPageIndex(const std::string& extension_id, int index); |
| + // Removes the page ordinal for an extension. |
| + void ClearPageOrdinal(const std::string& extension_id); |
| - // Removes the page index for an extension. |
| - void ClearPageIndex(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 +479,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 +541,47 @@ 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|. |
| + 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); |
| + |
| // 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_; |