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..6d782df671632fb10674d8d0a97c58dec4d1e100 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_index| is kUnsetIndex, and the 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_index); |
// Called when an extension is uninstalled, so that prefs get cleaned up. |
void OnExtensionUninstalled(const std::string& extension_id, |
@@ -304,37 +306,52 @@ class ExtensionPrefs : public ExtensionContentSettingsStore::Observer { |
bool GetWebStoreLogin(std::string* result); |
void SetWebStoreLogin(const std::string& login); |
+ // Get the first page index StringOrdinal value. |
+ StringOrdinal GetFirstAppPage(); |
Dan Beam
2011/11/12 02:28:30
From style guide:
"Declare methods to be const wh
csharp
2011/11/14 16:22:28
Good point, I'd forgotten about this. The methods
|
+ |
+ // Create a StringOrdinal which will be the first element for the given page. |
+ StringOrdinal CreateFirstAppLaunchIndex(const StringOrdinal& page_index); |
+ |
// 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); |
+ // A value close to |A*| generally indicates top left. If the extension has no |
+ // launch index a invalid StringOrdinal is returned. |
+ StringOrdinal 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); |
+ void SetAppLaunchIndex(const std::string& extension_id, |
+ const StringOrdinal& index); |
- // Gets the next available application launch index. This is 1 higher than the |
+ // Gets the next available application launch index. This is higher than the |
// highest current application launch index found for the page |on_page|. |
- int GetNextAppLaunchIndex(int on_page); |
+ StringOrdinal GetNextAppLaunchIndex(StringOrdinal 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(); |
+ // Gets the page a new app should install to. Starts the first page, and if |
+ // there are N or more apps on it, tries to install on the next page. |
+ StringOrdinal GetNaturalAppPageIndex(); |
// 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, |
+ const std::string& moved_extension_id); |
// 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); |
+ // the app has no page specified, kUnsetIndex is returned. |
+ StringOrdinal 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); |
+ void SetPageIndex(const std::string& extension_id, |
+ const StringOrdinal& index); |
// Removes the page index for an extension. |
void ClearPageIndex(const std::string& extension_id); |
+ // Convert the page index StringOrdinal value to its integer equivalent. |
+ int PageIndexAsInteger(const StringOrdinal& page_index); |
+ |
+ // Converts the page index integer to its StringOrdinal equivalent. |
+ StringOrdinal PageIndexAsStringOrdinal(size_t page_index); |
+ |
// Returns true if the user repositioned the app on the app launcher via drag |
// and drop. |
bool WasAppDraggedByUser(const std::string& extension_id); |
@@ -457,6 +474,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); |
+ |
// 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 +536,39 @@ 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; |
+ // Searches though all loaded app and returns all the apps that appear on |
+ // the page |page_index|. |
+ void GetAllAppsOnPageSorted( |
+ const StringOrdinal& page_index, |
+ std::set<StringOrdinal, StringOrdinal::Comparsion>* indexs_on_page); |
+ |
+ // Initialize the page_index_map_ with the page indexes used by the |
+ // given extensions. |
+ void InitializePageIndexMap(const ExtensionIdSet& extension_ids); |
+ |
+ // Update a value in the page_index_map_. |
+ void UpdatePageIndexMap(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 indexs 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, StringOrdinal::Comparsion> page_index_map_; |
+ |
// Weak pointer, owned by Profile. |
ExtensionPrefValueMap* extension_pref_value_map_; |