Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / extensions / browser / app_sorting.h
blob39d50dcd16c45c4393ac9dfc054a9b498d88a7d9
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef EXTENSIONS_BROWSER_APP_SORTING_H_
6 #define EXTENSIONS_BROWSER_APP_SORTING_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "extensions/common/extension.h"
12 #include "sync/api/string_ordinal.h"
14 class ExtensionSyncService;
16 namespace extensions {
18 class ExtensionScopedPrefs;
20 // An interface that provides a fixed ordering for a set of apps.
21 class AppSorting {
22 public:
23 AppSorting() {}
24 virtual ~AppSorting() {}
26 // Sets the object used to look up preferences. Ownership remains with the
27 // caller.
28 virtual void SetExtensionScopedPrefs(ExtensionScopedPrefs* prefs) = 0;
30 // Sets up the ExtensionSyncService to inform of changes that require syncing.
31 virtual void SetExtensionSyncService(
32 ExtensionSyncService* extension_sync_service) = 0;
34 // Properly initializes internal values that require |extension_ids|.
35 virtual void Initialize(const extensions::ExtensionIdList& extension_ids) = 0;
37 // Resolves any conflicts the might be created as a result of syncing that
38 // results in two icons having the same page and app launch ordinal. After
39 // this is called it is guaranteed that there are no collisions of NTP icons.
40 virtual void FixNTPOrdinalCollisions() = 0;
42 // This ensures that the extension has valid ordinals, and if it doesn't then
43 // properly initialize them. |suggested_page| will be used if it is valid and
44 // the extension has no valid user-set page ordinal.
45 virtual void EnsureValidOrdinals(
46 const std::string& extension_id,
47 const syncer::StringOrdinal& suggested_page) = 0;
49 // Updates the app launcher value for the moved extension so that it is now
50 // located after the given predecessor and before the successor.
51 // Empty strings are used to indicate no successor or predecessor.
52 virtual void OnExtensionMoved(const std::string& moved_extension_id,
53 const std::string& predecessor_extension_id,
54 const std::string& successor_extension_id) = 0;
56 // Get the application launch ordinal for an app with |extension_id|. This
57 // determines the order in which the app appears on the page it's on in the
58 // New Tab Page (Note that you can compare app launch ordinals only if the
59 // apps are on the same page). A string value close to |a*| generally
60 // indicates top left. If the extension has no launch ordinal, an invalid
61 // StringOrdinal is returned.
62 virtual syncer::StringOrdinal GetAppLaunchOrdinal(
63 const std::string& extension_id) const = 0;
65 // Sets a specific launch ordinal for an app with |extension_id|.
66 virtual void SetAppLaunchOrdinal(
67 const std::string& extension_id,
68 const syncer::StringOrdinal& new_app_launch_ordinal) = 0;
70 // Returns a StringOrdinal that is lower than any app launch ordinal for the
71 // given page.
72 virtual syncer::StringOrdinal CreateFirstAppLaunchOrdinal(
73 const syncer::StringOrdinal& page_ordinal) const = 0;
75 // Returns a StringOrdinal that is higher than any app launch ordinal for the
76 // given page.
77 virtual syncer::StringOrdinal CreateNextAppLaunchOrdinal(
78 const syncer::StringOrdinal& page_ordinal) const = 0;
80 // Returns a StringOrdinal that is lower than any existing page ordinal.
81 virtual syncer::StringOrdinal CreateFirstAppPageOrdinal() const = 0;
83 // Gets the page a new app should install to, which is the earliest non-full
84 // page. The returned ordinal may correspond to a page that doesn't yet exist
85 // if all pages are full.
86 virtual syncer::StringOrdinal GetNaturalAppPageOrdinal() const = 0;
88 // Get the page ordinal for an app with |extension_id|. This determines
89 // which page an app will appear on in page-based NTPs. If the app has no
90 // page specified, an invalid StringOrdinal is returned.
91 virtual syncer::StringOrdinal GetPageOrdinal(
92 const std::string& extension_id) const = 0;
94 // Sets a specific page ordinal for an app with |extension_id|.
95 virtual void SetPageOrdinal(
96 const std::string& extension_id,
97 const syncer::StringOrdinal& new_page_ordinal) = 0;
99 // Removes the ordinal values for an app.
100 virtual void ClearOrdinals(const std::string& extension_id) = 0;
102 // Convert the page StringOrdinal value to its integer equivalent. This takes
103 // O(# of apps) worst-case.
104 virtual int PageStringOrdinalAsInteger(
105 const syncer::StringOrdinal& page_ordinal) const = 0;
107 // Converts the page index integer to its StringOrdinal equivalent. This takes
108 // O(# of apps) worst-case.
109 virtual syncer::StringOrdinal PageIntegerAsStringOrdinal(
110 size_t page_index) = 0;
112 // Hides an extension from the new tab page, or makes a previously hidden
113 // extension visible.
114 virtual void SetExtensionVisible(const std::string& extension_id,
115 bool visible) = 0;
117 private:
118 DISALLOW_COPY_AND_ASSIGN(AppSorting);
121 } // namespace extensions
123 #endif // EXTENSIONS_BROWSER_APP_SORTING_H_