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

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 clang Created 8 years, 2 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 AppOrdinals();
118 ~AppOrdinals();
119
120 syncer::StringOrdinal page_ordinal;
121 syncer::StringOrdinal app_launch_ordinal;
122 };
123 typedef std::map<std::string, AppOrdinals> AppOrdinalsMap;
124
112 // This function returns the lowest ordinal on |page_ordinal| if 125 // This function returns the lowest ordinal on |page_ordinal| if
113 // |return_value| == AppLaunchOrdinalReturn::MIN_ORDINAL, otherwise it returns 126 // |return_value| == AppLaunchOrdinalReturn::MIN_ORDINAL, otherwise it returns
114 // the largest ordinal on |page_ordinal|. If there are no apps on the page 127 // 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 128 // then an invalid StringOrdinal is returned. It is an error to call this
116 // function with an invalid |page_ordinal|. 129 // function with an invalid |page_ordinal|.
117 syncer::StringOrdinal GetMinOrMaxAppLaunchOrdinalsOnPage( 130 syncer::StringOrdinal GetMinOrMaxAppLaunchOrdinalsOnPage(
118 const syncer::StringOrdinal& page_ordinal, 131 const syncer::StringOrdinal& page_ordinal,
119 AppLaunchOrdinalReturn return_type) const; 132 AppLaunchOrdinalReturn return_type) const;
120 133
121 // Initialize the |page_ordinal_map_| with the page ordinals used by the 134 // 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 155 // is not matching map, nothing happens. This works with valid and invalid
143 // StringOrdinals. 156 // StringOrdinals.
144 void RemoveOrdinalMapping(const std::string& extension_id, 157 void RemoveOrdinalMapping(const std::string& extension_id,
145 const syncer::StringOrdinal& page_ordinal, 158 const syncer::StringOrdinal& page_ordinal,
146 const syncer::StringOrdinal& app_launch_ordinal); 159 const syncer::StringOrdinal& app_launch_ordinal);
147 160
148 // Syncs the extension if needed. It is an error to call this if the 161 // Syncs the extension if needed. It is an error to call this if the
149 // extension is not an application. 162 // extension is not an application.
150 void SyncIfNeeded(const std::string& extension_id); 163 void SyncIfNeeded(const std::string& extension_id);
151 164
165 // Creates the default ordinals.
166 void CreateDefaultOrdinals();
167
168 // Gets the default ordinals for |extension_id|. Returns false if no default
169 // ordinals for |extension_id| is defined. Otherwise, returns true and
170 // ordinals is updated with corresponding ordinals.
171 bool GetDefaultOrdinals(const std::string& extension_id,
172 syncer::StringOrdinal* page_ordinal,
173 syncer::StringOrdinal* app_launch_ordinal) const;
174
175 // 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|
177 // that has no conflict.
178 syncer::StringOrdinal ResolveCollision(
179 const syncer::StringOrdinal& page_ordinal,
180 const syncer::StringOrdinal& app_launch_ordinal) const;
181
152 ExtensionScopedPrefs* extension_scoped_prefs_; // Weak, owns this instance. 182 ExtensionScopedPrefs* extension_scoped_prefs_; // Weak, owns this instance.
153 PrefService* pref_service_; // Weak. 183 PrefService* pref_service_; // Weak.
154 ExtensionServiceInterface* extension_service_; // Weak. 184 ExtensionServiceInterface* extension_service_; // Weak.
155 185
156 // A map of all the StringOrdinal page ordinals mapping to the collections of 186 // 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 187 // 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 188 // 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 189 // 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 190 // 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 191 // (although the collisions must all be resolved once all the syncing is
162 // done). 192 // done).
163 // The StringOrdinal is the app launch ordinal and the string is the extension 193 // The StringOrdinal is the app launch ordinal and the string is the extension
164 // id. 194 // id.
165 typedef std::multimap< 195 typedef std::multimap<
166 syncer::StringOrdinal, std::string, 196 syncer::StringOrdinal, std::string,
167 syncer::StringOrdinal::LessThanFn> AppLaunchOrdinalMap; 197 syncer::StringOrdinal::LessThanFn> AppLaunchOrdinalMap;
168 // The StringOrdinal is the page ordinal and the AppLaunchOrdinalMap is the 198 // The StringOrdinal is the page ordinal and the AppLaunchOrdinalMap is the
169 // contents of that page. 199 // contents of that page.
170 typedef std::map< 200 typedef std::map<
171 syncer::StringOrdinal, AppLaunchOrdinalMap, 201 syncer::StringOrdinal, AppLaunchOrdinalMap,
172 syncer::StringOrdinal::LessThanFn> PageOrdinalMap; 202 syncer::StringOrdinal::LessThanFn> PageOrdinalMap;
173 PageOrdinalMap ntp_ordinal_map_; 203 PageOrdinalMap ntp_ordinal_map_;
174 204
205 // Defines the default ordinals.
206 AppOrdinalsMap default_ordinals_;
207
175 DISALLOW_COPY_AND_ASSIGN(ExtensionSorting); 208 DISALLOW_COPY_AND_ASSIGN(ExtensionSorting);
176 }; 209 };
177 210
178 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SORTING_H_ 211 #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_SORTING_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_service.cc ('k') | chrome/browser/extensions/extension_sorting.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698