| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SORTING_H_ | 5 #ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_SORTING_H_ |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SORTING_H_ | 6 #define CHROME_BROWSER_EXTENSIONS_EXTENSION_SORTING_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> |
| 9 #include <string> | 10 #include <string> |
| 10 | 11 |
| 11 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 12 #include "chrome/browser/extensions/extension_prefs.h" | 13 #include "chrome/browser/extensions/extension_prefs.h" |
| 13 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
| 14 #include "sync/api/string_ordinal.h" | 15 #include "sync/api/string_ordinal.h" |
| 15 | 16 |
| 16 class ExtensionScopedPrefs; | 17 class ExtensionScopedPrefs; |
| 17 class ExtensionServiceInterface; | 18 class ExtensionServiceInterface; |
| 18 class PrefService; | 19 class PrefService; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 95 |
| 95 // Convert the page StringOrdinal value to its integer equivalent. This takes | 96 // Convert the page StringOrdinal value to its integer equivalent. This takes |
| 96 // O(# of apps) worst-case. | 97 // O(# of apps) worst-case. |
| 97 int PageStringOrdinalAsInteger( | 98 int PageStringOrdinalAsInteger( |
| 98 const syncer::StringOrdinal& page_ordinal) const; | 99 const syncer::StringOrdinal& page_ordinal) const; |
| 99 | 100 |
| 100 // Converts the page index integer to its StringOrdinal equivalent. This takes | 101 // Converts the page index integer to its StringOrdinal equivalent. This takes |
| 101 // O(# of apps) worst-case. | 102 // O(# of apps) worst-case. |
| 102 syncer::StringOrdinal PageIntegerAsStringOrdinal(size_t page_index); | 103 syncer::StringOrdinal PageIntegerAsStringOrdinal(size_t page_index); |
| 103 | 104 |
| 105 // Hidden extensions don't appear in the new tab page. |
| 106 void MarkExtensionAsHidden(const std::string& extension_id); |
| 107 |
| 104 private: | 108 private: |
| 109 // The StringOrdinal is the app launch ordinal and the string is the extension |
| 110 // id. |
| 111 typedef std::multimap< |
| 112 syncer::StringOrdinal, std::string, |
| 113 syncer::StringOrdinal::LessThanFn> AppLaunchOrdinalMap; |
| 114 // The StringOrdinal is the page ordinal and the AppLaunchOrdinalMap is the |
| 115 // contents of that page. |
| 116 typedef std::map< |
| 117 syncer::StringOrdinal, AppLaunchOrdinalMap, |
| 118 syncer::StringOrdinal::LessThanFn> PageOrdinalMap; |
| 119 |
| 105 // Unit tests. | 120 // Unit tests. |
| 106 friend class ExtensionSortingDefaultOrdinalsBase; | 121 friend class ExtensionSortingDefaultOrdinalsBase; |
| 107 friend class ExtensionSortingGetMinOrMaxAppLaunchOrdinalsOnPage; | 122 friend class ExtensionSortingGetMinOrMaxAppLaunchOrdinalsOnPage; |
| 108 friend class ExtensionSortingInitializeWithNoApps; | 123 friend class ExtensionSortingInitializeWithNoApps; |
| 109 friend class ExtensionSortingPageOrdinalMapping; | 124 friend class ExtensionSortingPageOrdinalMapping; |
| 110 | 125 |
| 111 // An enum used by GetMinOrMaxAppLaunchOrdinalsOnPage to specify which | 126 // An enum used by GetMinOrMaxAppLaunchOrdinalsOnPage to specify which |
| 112 // value should be returned. | 127 // value should be returned. |
| 113 enum AppLaunchOrdinalReturn {MIN_ORDINAL, MAX_ORDINAL}; | 128 enum AppLaunchOrdinalReturn {MIN_ORDINAL, MAX_ORDINAL}; |
| 114 | 129 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 syncer::StringOrdinal* page_ordinal, | 187 syncer::StringOrdinal* page_ordinal, |
| 173 syncer::StringOrdinal* app_launch_ordinal) const; | 188 syncer::StringOrdinal* app_launch_ordinal) const; |
| 174 | 189 |
| 175 // Returns |app_launch_ordinal| if it has no collision in the page specified | 190 // Returns |app_launch_ordinal| if it has no collision in the page specified |
| 176 // by |page_ordinal|. Otherwise, returns an ordinal after |app_launch_ordinal| | 191 // by |page_ordinal|. Otherwise, returns an ordinal after |app_launch_ordinal| |
| 177 // that has no conflict. | 192 // that has no conflict. |
| 178 syncer::StringOrdinal ResolveCollision( | 193 syncer::StringOrdinal ResolveCollision( |
| 179 const syncer::StringOrdinal& page_ordinal, | 194 const syncer::StringOrdinal& page_ordinal, |
| 180 const syncer::StringOrdinal& app_launch_ordinal) const; | 195 const syncer::StringOrdinal& app_launch_ordinal) const; |
| 181 | 196 |
| 197 // Returns the number of items in |m| visible on the new tab page. |
| 198 size_t CountItemsVisibleOnNtp(const AppLaunchOrdinalMap& m) const; |
| 199 |
| 182 ExtensionScopedPrefs* extension_scoped_prefs_; // Weak, owns this instance. | 200 ExtensionScopedPrefs* extension_scoped_prefs_; // Weak, owns this instance. |
| 183 PrefService* pref_service_; // Weak. | 201 PrefService* pref_service_; // Weak. |
| 184 ExtensionServiceInterface* extension_service_; // Weak. | 202 ExtensionServiceInterface* extension_service_; // Weak. |
| 185 | 203 |
| 186 // A map of all the StringOrdinal page ordinals mapping to the collections of | 204 // A map of all the StringOrdinal page ordinals mapping to the collections of |
| 187 // app launch ordinals that exist on that page. This is used for mapping | 205 // app launch ordinals that exist on that page. This is used for mapping |
| 188 // StringOrdinals to their Integer equivalent as well as quick lookup of the | 206 // StringOrdinals to their Integer equivalent as well as quick lookup of the |
| 189 // any collision of on the NTP (icons with the same page and same app launch | 207 // any collision of on the NTP (icons with the same page and same app launch |
| 190 // ordinals). The possiblity of collisions means that a multimap must be used | 208 // ordinals). The possiblity of collisions means that a multimap must be used |
| 191 // (although the collisions must all be resolved once all the syncing is | 209 // (although the collisions must all be resolved once all the syncing is |
| 192 // done). | 210 // done). |
| 193 // The StringOrdinal is the app launch ordinal and the string is the extension | |
| 194 // id. | |
| 195 typedef std::multimap< | |
| 196 syncer::StringOrdinal, std::string, | |
| 197 syncer::StringOrdinal::LessThanFn> AppLaunchOrdinalMap; | |
| 198 // The StringOrdinal is the page ordinal and the AppLaunchOrdinalMap is the | |
| 199 // contents of that page. | |
| 200 typedef std::map< | |
| 201 syncer::StringOrdinal, AppLaunchOrdinalMap, | |
| 202 syncer::StringOrdinal::LessThanFn> PageOrdinalMap; | |
| 203 PageOrdinalMap ntp_ordinal_map_; | 211 PageOrdinalMap ntp_ordinal_map_; |
| 204 | 212 |
| 205 // Defines the default ordinals. | 213 // Defines the default ordinals. |
| 206 AppOrdinalsMap default_ordinals_; | 214 AppOrdinalsMap default_ordinals_; |
| 207 | 215 |
| 216 // The set of extensions that don't appear in the new tab page. |
| 217 std::set<std::string> ntp_hidden_extensions_; |
| 218 |
| 208 DISALLOW_COPY_AND_ASSIGN(ExtensionSorting); | 219 DISALLOW_COPY_AND_ASSIGN(ExtensionSorting); |
| 209 }; | 220 }; |
| 210 | 221 |
| 211 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SORTING_H_ | 222 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SORTING_H_ |
| OLD | NEW |