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

Side by Side Diff: chrome/browser/extensions/extension_sorting.h

Issue 10969044: cros: Implement default app ordering. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix a typo Created 8 years, 3 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 <string> 9 #include <string>
10 10
(...skipping 19 matching lines...) Expand all
30 // |extension_ids|. 30 // |extension_ids|.
31 void Initialize( 31 void Initialize(
32 const extensions::ExtensionPrefs::ExtensionIds& extension_ids); 32 const extensions::ExtensionPrefs::ExtensionIds& extension_ids);
33 33
34 // Resolves any conflicts the might be created as a result of syncing that 34 // Resolves any conflicts the might be created as a result of syncing that
35 // results in two icons having the same page and app launch ordinal. After 35 // results in two icons having the same page and app launch ordinal. After
36 // this is called it is guaranteed that there are no collisions of NTP icons. 36 // this is called it is guaranteed that there are no collisions of NTP icons.
37 void FixNTPOrdinalCollisions(); 37 void FixNTPOrdinalCollisions();
38 38
39 // This ensures that the extension has valid ordinals, and if it doesn't then 39 // This ensures that the extension has valid ordinals, and if it doesn't then
40 // properly initialize them. 40 // properly initialize them. |suggested_page| will be used if it is valid and
41 void EnsureValidOrdinals(const std::string& extension_id); 41 // the extension has no valid user-set page ordinal.
42 void EnsureValidOrdinals(const std::string& extension_id,
43 const syncer::StringOrdinal& suggested_page);
42 44
43 // Updates the app launcher value for the moved extension so that it is now 45 // Updates the app launcher value for the moved extension so that it is now
44 // located after the given predecessor and before the successor. 46 // located after the given predecessor and before the successor.
45 // Empty strings are used to indicate no successor or predecessor. 47 // Empty strings are used to indicate no successor or predecessor.
46 void OnExtensionMoved(const std::string& moved_extension_id, 48 void OnExtensionMoved(const std::string& moved_extension_id,
47 const std::string& predecessor_extension_id, 49 const std::string& predecessor_extension_id,
48 const std::string& successor_extension_id); 50 const std::string& successor_extension_id);
49 51
50 // Get the application launch ordinal for an app with |extension_id|. This 52 // Get the application launch ordinal for an app with |extension_id|. This
51 // determines the order in which the app appears on the page it's on in the 53 // determines the order in which the app appears on the page it's on in the
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 // O(# of apps) worst-case. 96 // O(# of apps) worst-case.
95 int PageStringOrdinalAsInteger( 97 int PageStringOrdinalAsInteger(
96 const syncer::StringOrdinal& page_ordinal) const; 98 const syncer::StringOrdinal& page_ordinal) const;
97 99
98 // Converts the page index integer to its StringOrdinal equivalent. This takes 100 // Converts the page index integer to its StringOrdinal equivalent. This takes
99 // O(# of apps) worst-case. 101 // O(# of apps) worst-case.
100 syncer::StringOrdinal PageIntegerAsStringOrdinal(size_t page_index); 102 syncer::StringOrdinal PageIntegerAsStringOrdinal(size_t page_index);
101 103
102 private: 104 private:
103 // Unit tests. 105 // Unit tests.
106 friend class ExtensionSortingDefaultOrdinalsBase;
104 friend class ExtensionSortingGetMinOrMaxAppLaunchOrdinalsOnPage; 107 friend class ExtensionSortingGetMinOrMaxAppLaunchOrdinalsOnPage;
105 friend class ExtensionSortingInitializeWithNoApps; 108 friend class ExtensionSortingInitializeWithNoApps;
106 friend class ExtensionSortingPageOrdinalMapping; 109 friend class ExtensionSortingPageOrdinalMapping;
107 110
108 // An enum used by GetMinOrMaxAppLaunchOrdinalsOnPage to specify which 111 // An enum used by GetMinOrMaxAppLaunchOrdinalsOnPage to specify which
109 // value should be returned. 112 // value should be returned.
110 enum AppLaunchOrdinalReturn {MIN_ORDINAL, MAX_ORDINAL}; 113 enum AppLaunchOrdinalReturn {MIN_ORDINAL, MAX_ORDINAL};
111 114
115 // Maps an app id to its ordinals.
116 struct AppOrdinals {
117 syncer::StringOrdinal page_ordinal;
118 syncer::StringOrdinal app_launch_ordinal;
119 };
120 typedef std::map<std::string, AppOrdinals> AppOrdinalsMap;
121
112 // This function returns the lowest ordinal on |page_ordinal| if 122 // This function returns the lowest ordinal on |page_ordinal| if
113 // |return_value| == AppLaunchOrdinalReturn::MIN_ORDINAL, otherwise it returns 123 // |return_value| == AppLaunchOrdinalReturn::MIN_ORDINAL, otherwise it returns
114 // the largest ordinal on |page_ordinal|. If there are no apps on the page 124 // the largest ordinal on |page_ordinal|. If there are no apps on the page
115 // then an invalid StringOrdinal is returned. It is an error to call this 125 // then an invalid StringOrdinal is returned. It is an error to call this
116 // function with an invalid |page_ordinal|. 126 // function with an invalid |page_ordinal|.
117 syncer::StringOrdinal GetMinOrMaxAppLaunchOrdinalsOnPage( 127 syncer::StringOrdinal GetMinOrMaxAppLaunchOrdinalsOnPage(
118 const syncer::StringOrdinal& page_ordinal, 128 const syncer::StringOrdinal& page_ordinal,
119 AppLaunchOrdinalReturn return_type) const; 129 AppLaunchOrdinalReturn return_type) const;
120 130
121 // Initialize the |page_ordinal_map_| with the page ordinals used by the 131 // Initialize the |page_ordinal_map_| with the page ordinals used by the
(...skipping 20 matching lines...) Expand all
142 // is not matching map, nothing happens. This works with valid and invalid 152 // is not matching map, nothing happens. This works with valid and invalid
143 // StringOrdinals. 153 // StringOrdinals.
144 void RemoveOrdinalMapping(const std::string& extension_id, 154 void RemoveOrdinalMapping(const std::string& extension_id,
145 const syncer::StringOrdinal& page_ordinal, 155 const syncer::StringOrdinal& page_ordinal,
146 const syncer::StringOrdinal& app_launch_ordinal); 156 const syncer::StringOrdinal& app_launch_ordinal);
147 157
148 // Syncs the extension if needed. It is an error to call this if the 158 // Syncs the extension if needed. It is an error to call this if the
149 // extension is not an application. 159 // extension is not an application.
150 void SyncIfNeeded(const std::string& extension_id); 160 void SyncIfNeeded(const std::string& extension_id);
151 161
162 // Creates the default ordinals.
163 void CreateDefaultOrdinals();
164
165 // Gets the default ordinals for |extension_id|. Returns false if no default
166 // ordinals for |extension_id| is defined. Otherwise, returns true and
167 // ordinals is updated with corresponding ordinals.
168 bool GetDefaultOrdinals(const std::string& extension_id,
169 syncer::StringOrdinal* page_ordinal,
170 syncer::StringOrdinal* app_launch_ordinal) const;
171
172 // Returns |app_launch_ordinal| if it has no collision in the page specified
173 // by |page_ordinal|. Otherwise, returns an ordinal after |app_launch_ordinal|
174 // that has no conflict.
175 syncer::StringOrdinal ResolveCollision(
176 const syncer::StringOrdinal& page_ordinal,
177 const syncer::StringOrdinal& app_launch_ordinal) const;
178
152 ExtensionScopedPrefs* extension_scoped_prefs_; // Weak, owns this instance. 179 ExtensionScopedPrefs* extension_scoped_prefs_; // Weak, owns this instance.
153 PrefService* pref_service_; // Weak. 180 PrefService* pref_service_; // Weak.
154 ExtensionServiceInterface* extension_service_; // Weak. 181 ExtensionServiceInterface* extension_service_; // Weak.
155 182
156 // A map of all the StringOrdinal page ordinals mapping to the collections of 183 // A map of all the StringOrdinal page ordinals mapping to the collections of
157 // app launch ordinals that exist on that page. This is used for mapping 184 // app launch ordinals that exist on that page. This is used for mapping
158 // StringOrdinals to their Integer equivalent as well as quick lookup of the 185 // StringOrdinals to their Integer equivalent as well as quick lookup of the
159 // any collision of on the NTP (icons with the same page and same app launch 186 // any collision of on the NTP (icons with the same page and same app launch
160 // ordinals). The possiblity of collisions means that a multimap must be used 187 // ordinals). The possiblity of collisions means that a multimap must be used
161 // (although the collisions must all be resolved once all the syncing is 188 // (although the collisions must all be resolved once all the syncing is
162 // done). 189 // done).
163 // The StringOrdinal is the app launch ordinal and the string is the extension 190 // The StringOrdinal is the app launch ordinal and the string is the extension
164 // id. 191 // id.
165 typedef std::multimap< 192 typedef std::multimap<
166 syncer::StringOrdinal, std::string, 193 syncer::StringOrdinal, std::string,
167 syncer::StringOrdinal::LessThanFn> AppLaunchOrdinalMap; 194 syncer::StringOrdinal::LessThanFn> AppLaunchOrdinalMap;
168 // The StringOrdinal is the page ordinal and the AppLaunchOrdinalMap is the 195 // The StringOrdinal is the page ordinal and the AppLaunchOrdinalMap is the
169 // contents of that page. 196 // contents of that page.
170 typedef std::map< 197 typedef std::map<
171 syncer::StringOrdinal, AppLaunchOrdinalMap, 198 syncer::StringOrdinal, AppLaunchOrdinalMap,
172 syncer::StringOrdinal::LessThanFn> PageOrdinalMap; 199 syncer::StringOrdinal::LessThanFn> PageOrdinalMap;
173 PageOrdinalMap ntp_ordinal_map_; 200 PageOrdinalMap ntp_ordinal_map_;
174 201
202 // Defines the default ordinals.
203 AppOrdinalsMap default_ordinals_;
204
175 DISALLOW_COPY_AND_ASSIGN(ExtensionSorting); 205 DISALLOW_COPY_AND_ASSIGN(ExtensionSorting);
176 }; 206 };
177 207
178 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SORTING_H_ 208 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SORTING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698