[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame] | 1 | // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef EXTENSIONS_BROWSER_APP_SORTING_H_ |
| 6 | #define EXTENSIONS_BROWSER_APP_SORTING_H_ |
| 7 | |
avi | c9cec10 | 2015-12-23 00:39:26 | [diff] [blame] | 8 | #include <stddef.h> |
| 9 | |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 10 | #include <string> |
| 11 | |
avi | c9cec10 | 2015-12-23 00:39:26 | [diff] [blame] | 12 | #include "base/macros.h" |
Max Bogue | fef332d | 2016-07-28 22:09:09 | [diff] [blame] | 13 | #include "components/sync/api/string_ordinal.h" |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 14 | #include "extensions/common/extension.h" |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 15 | |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 16 | namespace extensions { |
| 17 | |
[email protected] | da762a8 | 2013-12-07 03:45:58 | [diff] [blame] | 18 | class ExtensionScopedPrefs; |
| 19 | |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 20 | // An interface that provides a fixed ordering for a set of apps. |
| 21 | class AppSorting { |
| 22 | public: |
| 23 | AppSorting() {} |
| 24 | virtual ~AppSorting() {} |
| 25 | |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 26 | // Resolves any conflicts the might be created as a result of syncing that |
| 27 | // results in two icons having the same page and app launch ordinal. After |
| 28 | // this is called it is guaranteed that there are no collisions of NTP icons. |
| 29 | virtual void FixNTPOrdinalCollisions() = 0; |
| 30 | |
| 31 | // This ensures that the extension has valid ordinals, and if it doesn't then |
| 32 | // properly initialize them. |suggested_page| will be used if it is valid and |
| 33 | // the extension has no valid user-set page ordinal. |
| 34 | virtual void EnsureValidOrdinals( |
| 35 | const std::string& extension_id, |
| 36 | const syncer::StringOrdinal& suggested_page) = 0; |
| 37 | |
xdai | 8e935ed | 2016-08-03 18:10:24 | [diff] [blame] | 38 | // Gets the default ordinals for |extension_id|. Returns false if no default |
| 39 | // ordinals for |extension_id| is defined. Otherwise, returns true and |
| 40 | // ordinals is updated with corresponding ordinals. |
| 41 | virtual bool GetDefaultOrdinals( |
| 42 | const std::string& extension_id, |
| 43 | syncer::StringOrdinal* page_ordinal, |
| 44 | syncer::StringOrdinal* app_launch_ordinal) = 0; |
| 45 | |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 46 | // Updates the app launcher value for the moved extension so that it is now |
| 47 | // located after the given predecessor and before the successor. |
| 48 | // Empty strings are used to indicate no successor or predecessor. |
| 49 | virtual void OnExtensionMoved(const std::string& moved_extension_id, |
| 50 | const std::string& predecessor_extension_id, |
| 51 | const std::string& successor_extension_id) = 0; |
| 52 | |
| 53 | // Get the application launch ordinal for an app with |extension_id|. This |
| 54 | // determines the order in which the app appears on the page it's on in the |
| 55 | // New Tab Page (Note that you can compare app launch ordinals only if the |
| 56 | // apps are on the same page). A string value close to |a*| generally |
| 57 | // indicates top left. If the extension has no launch ordinal, an invalid |
| 58 | // StringOrdinal is returned. |
| 59 | virtual syncer::StringOrdinal GetAppLaunchOrdinal( |
| 60 | const std::string& extension_id) const = 0; |
| 61 | |
| 62 | // Sets a specific launch ordinal for an app with |extension_id|. |
| 63 | virtual void SetAppLaunchOrdinal( |
| 64 | const std::string& extension_id, |
| 65 | const syncer::StringOrdinal& new_app_launch_ordinal) = 0; |
| 66 | |
| 67 | // Returns a StringOrdinal that is lower than any app launch ordinal for the |
| 68 | // given page. |
| 69 | virtual syncer::StringOrdinal CreateFirstAppLaunchOrdinal( |
| 70 | const syncer::StringOrdinal& page_ordinal) const = 0; |
| 71 | |
| 72 | // Returns a StringOrdinal that is higher than any app launch ordinal for the |
| 73 | // given page. |
| 74 | virtual syncer::StringOrdinal CreateNextAppLaunchOrdinal( |
| 75 | const syncer::StringOrdinal& page_ordinal) const = 0; |
| 76 | |
| 77 | // Returns a StringOrdinal that is lower than any existing page ordinal. |
| 78 | virtual syncer::StringOrdinal CreateFirstAppPageOrdinal() const = 0; |
| 79 | |
| 80 | // Gets the page a new app should install to, which is the earliest non-full |
| 81 | // page. The returned ordinal may correspond to a page that doesn't yet exist |
| 82 | // if all pages are full. |
| 83 | virtual syncer::StringOrdinal GetNaturalAppPageOrdinal() const = 0; |
| 84 | |
| 85 | // Get the page ordinal for an app with |extension_id|. This determines |
| 86 | // which page an app will appear on in page-based NTPs. If the app has no |
| 87 | // page specified, an invalid StringOrdinal is returned. |
| 88 | virtual syncer::StringOrdinal GetPageOrdinal( |
| 89 | const std::string& extension_id) const = 0; |
| 90 | |
| 91 | // Sets a specific page ordinal for an app with |extension_id|. |
| 92 | virtual void SetPageOrdinal( |
| 93 | const std::string& extension_id, |
| 94 | const syncer::StringOrdinal& new_page_ordinal) = 0; |
| 95 | |
| 96 | // Removes the ordinal values for an app. |
| 97 | virtual void ClearOrdinals(const std::string& extension_id) = 0; |
| 98 | |
| 99 | // Convert the page StringOrdinal value to its integer equivalent. This takes |
| 100 | // O(# of apps) worst-case. |
| 101 | virtual int PageStringOrdinalAsInteger( |
| 102 | const syncer::StringOrdinal& page_ordinal) const = 0; |
| 103 | |
| 104 | // Converts the page index integer to its StringOrdinal equivalent. This takes |
| 105 | // O(# of apps) worst-case. |
| 106 | virtual syncer::StringOrdinal PageIntegerAsStringOrdinal( |
| 107 | size_t page_index) = 0; |
| 108 | |
[email protected] | db37832 | 2014-07-21 23:19:34 | [diff] [blame] | 109 | // Hides an extension from the new tab page, or makes a previously hidden |
| 110 | // extension visible. |
| 111 | virtual void SetExtensionVisible(const std::string& extension_id, |
| 112 | bool visible) = 0; |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 113 | |
| 114 | private: |
| 115 | DISALLOW_COPY_AND_ASSIGN(AppSorting); |
| 116 | }; |
| 117 | |
| 118 | } // namespace extensions |
| 119 | |
| 120 | #endif // EXTENSIONS_BROWSER_APP_SORTING_H_ |