[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 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/basictypes.h" |
[email protected] | 489db084 | 2014-01-22 18:20:03 | [diff] [blame^] | 11 | #include "extensions/browser/extension_prefs.h" |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 12 | #include "extensions/common/extension.h" |
| 13 | #include "sync/api/string_ordinal.h" |
| 14 | |
| 15 | class ExtensionSyncService; |
| 16 | |
| 17 | namespace extensions { |
| 18 | |
[email protected] | da762a8 | 2013-12-07 03:45:58 | [diff] [blame] | 19 | class ExtensionScopedPrefs; |
| 20 | |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 21 | // An interface that provides a fixed ordering for a set of apps. |
| 22 | class AppSorting { |
| 23 | public: |
| 24 | AppSorting() {} |
| 25 | virtual ~AppSorting() {} |
| 26 | |
[email protected] | bf5ee7cc | 2013-11-23 20:48:44 | [diff] [blame] | 27 | // Sets the object used to look up preferences. Ownership remains with the |
| 28 | // caller. |
| 29 | virtual void SetExtensionScopedPrefs(ExtensionScopedPrefs* prefs) = 0; |
| 30 | |
| 31 | // Sets up the ExtensionSyncService to inform of changes that require syncing. |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 32 | virtual void SetExtensionSyncService( |
| 33 | ExtensionSyncService* extension_sync_service) = 0; |
| 34 | |
[email protected] | bf5ee7cc | 2013-11-23 20:48:44 | [diff] [blame] | 35 | // Properly initializes internal values that require |extension_ids|. |
[email protected] | 7447404 | 2013-11-21 12:03:54 | [diff] [blame] | 36 | virtual void Initialize(const extensions::ExtensionIdList& extension_ids) = 0; |
| 37 | |
| 38 | // Resolves any conflicts the might be created as a result of syncing that |
| 39 | // results in two icons having the same page and app launch ordinal. After |
| 40 | // this is called it is guaranteed that there are no collisions of NTP icons. |
| 41 | virtual void FixNTPOrdinalCollisions() = 0; |
| 42 | |
| 43 | // This ensures that the extension has valid ordinals, and if it doesn't then |
| 44 | // properly initialize them. |suggested_page| will be used if it is valid and |
| 45 | // the extension has no valid user-set page ordinal. |
| 46 | virtual void EnsureValidOrdinals( |
| 47 | const std::string& extension_id, |
| 48 | const syncer::StringOrdinal& suggested_page) = 0; |
| 49 | |
| 50 | // Updates the app launcher value for the moved extension so that it is now |
| 51 | // located after the given predecessor and before the successor. |
| 52 | // Empty strings are used to indicate no successor or predecessor. |
| 53 | virtual void OnExtensionMoved(const std::string& moved_extension_id, |
| 54 | const std::string& predecessor_extension_id, |
| 55 | const std::string& successor_extension_id) = 0; |
| 56 | |
| 57 | // Get the application launch ordinal for an app with |extension_id|. This |
| 58 | // determines the order in which the app appears on the page it's on in the |
| 59 | // New Tab Page (Note that you can compare app launch ordinals only if the |
| 60 | // apps are on the same page). A string value close to |a*| generally |
| 61 | // indicates top left. If the extension has no launch ordinal, an invalid |
| 62 | // StringOrdinal is returned. |
| 63 | virtual syncer::StringOrdinal GetAppLaunchOrdinal( |
| 64 | const std::string& extension_id) const = 0; |
| 65 | |
| 66 | // Sets a specific launch ordinal for an app with |extension_id|. |
| 67 | virtual void SetAppLaunchOrdinal( |
| 68 | const std::string& extension_id, |
| 69 | const syncer::StringOrdinal& new_app_launch_ordinal) = 0; |
| 70 | |
| 71 | // Returns a StringOrdinal that is lower than any app launch ordinal for the |
| 72 | // given page. |
| 73 | virtual syncer::StringOrdinal CreateFirstAppLaunchOrdinal( |
| 74 | const syncer::StringOrdinal& page_ordinal) const = 0; |
| 75 | |
| 76 | // Returns a StringOrdinal that is higher than any app launch ordinal for the |
| 77 | // given page. |
| 78 | virtual syncer::StringOrdinal CreateNextAppLaunchOrdinal( |
| 79 | const syncer::StringOrdinal& page_ordinal) const = 0; |
| 80 | |
| 81 | // Returns a StringOrdinal that is lower than any existing page ordinal. |
| 82 | virtual syncer::StringOrdinal CreateFirstAppPageOrdinal() const = 0; |
| 83 | |
| 84 | // Gets the page a new app should install to, which is the earliest non-full |
| 85 | // page. The returned ordinal may correspond to a page that doesn't yet exist |
| 86 | // if all pages are full. |
| 87 | virtual syncer::StringOrdinal GetNaturalAppPageOrdinal() const = 0; |
| 88 | |
| 89 | // Get the page ordinal for an app with |extension_id|. This determines |
| 90 | // which page an app will appear on in page-based NTPs. If the app has no |
| 91 | // page specified, an invalid StringOrdinal is returned. |
| 92 | virtual syncer::StringOrdinal GetPageOrdinal( |
| 93 | const std::string& extension_id) const = 0; |
| 94 | |
| 95 | // Sets a specific page ordinal for an app with |extension_id|. |
| 96 | virtual void SetPageOrdinal( |
| 97 | const std::string& extension_id, |
| 98 | const syncer::StringOrdinal& new_page_ordinal) = 0; |
| 99 | |
| 100 | // Removes the ordinal values for an app. |
| 101 | virtual void ClearOrdinals(const std::string& extension_id) = 0; |
| 102 | |
| 103 | // Convert the page StringOrdinal value to its integer equivalent. This takes |
| 104 | // O(# of apps) worst-case. |
| 105 | virtual int PageStringOrdinalAsInteger( |
| 106 | const syncer::StringOrdinal& page_ordinal) const = 0; |
| 107 | |
| 108 | // Converts the page index integer to its StringOrdinal equivalent. This takes |
| 109 | // O(# of apps) worst-case. |
| 110 | virtual syncer::StringOrdinal PageIntegerAsStringOrdinal( |
| 111 | size_t page_index) = 0; |
| 112 | |
| 113 | // Hidden extensions don't appear in the new tab page. |
| 114 | virtual void MarkExtensionAsHidden(const std::string& extension_id) = 0; |
| 115 | |
| 116 | private: |
| 117 | DISALLOW_COPY_AND_ASSIGN(AppSorting); |
| 118 | }; |
| 119 | |
| 120 | } // namespace extensions |
| 121 | |
| 122 | #endif // EXTENSIONS_BROWSER_APP_SORTING_H_ |