Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / extensions / browser / app_sorting.h
blob3ab4c80c51d1f17ebc406ef7c04dea37e53a736f
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 namespace extensions {
16 class ExtensionScopedPrefs;
18 // An interface that provides a fixed ordering for a set of apps.
19 class AppSorting {
20 public:
21 AppSorting() {}
22 virtual ~AppSorting() {}
24 // Sets the object used to look up preferences. Ownership remains with the
25 // caller.
26 virtual void SetExtensionScopedPrefs(ExtensionScopedPrefs* prefs) = 0;
28 // CHECKs that SetExtensionScopedPrefs has been called with a non-null object.
29 // TODO(mgiuca): Added this to try and diagnose http://crbug.com/476648.
30 // Remove it after the investigation is concluded.
31 virtual void CheckExtensionScopedPrefs() const = 0;
33 // Properly initializes internal values that require |extension_ids|.
34 // SetExtensionScopedPrefs must have been called prior to this.
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_