Roll src/third_party/WebKit 48e5493c:ad9da0e (svn 202519:202521)
[chromium-blink-merge.git] / extensions / browser / app_sorting.h
blob303fc9ae3b6fa7154894be99d56d79e9b5b172ea
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 // Resolves any conflicts the might be created as a result of syncing that
25 // results in two icons having the same page and app launch ordinal. After
26 // this is called it is guaranteed that there are no collisions of NTP icons.
27 virtual void FixNTPOrdinalCollisions() = 0;
29 // This ensures that the extension has valid ordinals, and if it doesn't then
30 // properly initialize them. |suggested_page| will be used if it is valid and
31 // the extension has no valid user-set page ordinal.
32 virtual void EnsureValidOrdinals(
33 const std::string& extension_id,
34 const syncer::StringOrdinal& suggested_page) = 0;
36 // Updates the app launcher value for the moved extension so that it is now
37 // located after the given predecessor and before the successor.
38 // Empty strings are used to indicate no successor or predecessor.
39 virtual void OnExtensionMoved(const std::string& moved_extension_id,
40 const std::string& predecessor_extension_id,
41 const std::string& successor_extension_id) = 0;
43 // Get the application launch ordinal for an app with |extension_id|. This
44 // determines the order in which the app appears on the page it's on in the
45 // New Tab Page (Note that you can compare app launch ordinals only if the
46 // apps are on the same page). A string value close to |a*| generally
47 // indicates top left. If the extension has no launch ordinal, an invalid
48 // StringOrdinal is returned.
49 virtual syncer::StringOrdinal GetAppLaunchOrdinal(
50 const std::string& extension_id) const = 0;
52 // Sets a specific launch ordinal for an app with |extension_id|.
53 virtual void SetAppLaunchOrdinal(
54 const std::string& extension_id,
55 const syncer::StringOrdinal& new_app_launch_ordinal) = 0;
57 // Returns a StringOrdinal that is lower than any app launch ordinal for the
58 // given page.
59 virtual syncer::StringOrdinal CreateFirstAppLaunchOrdinal(
60 const syncer::StringOrdinal& page_ordinal) const = 0;
62 // Returns a StringOrdinal that is higher than any app launch ordinal for the
63 // given page.
64 virtual syncer::StringOrdinal CreateNextAppLaunchOrdinal(
65 const syncer::StringOrdinal& page_ordinal) const = 0;
67 // Returns a StringOrdinal that is lower than any existing page ordinal.
68 virtual syncer::StringOrdinal CreateFirstAppPageOrdinal() const = 0;
70 // Gets the page a new app should install to, which is the earliest non-full
71 // page. The returned ordinal may correspond to a page that doesn't yet exist
72 // if all pages are full.
73 virtual syncer::StringOrdinal GetNaturalAppPageOrdinal() const = 0;
75 // Get the page ordinal for an app with |extension_id|. This determines
76 // which page an app will appear on in page-based NTPs. If the app has no
77 // page specified, an invalid StringOrdinal is returned.
78 virtual syncer::StringOrdinal GetPageOrdinal(
79 const std::string& extension_id) const = 0;
81 // Sets a specific page ordinal for an app with |extension_id|.
82 virtual void SetPageOrdinal(
83 const std::string& extension_id,
84 const syncer::StringOrdinal& new_page_ordinal) = 0;
86 // Removes the ordinal values for an app.
87 virtual void ClearOrdinals(const std::string& extension_id) = 0;
89 // Convert the page StringOrdinal value to its integer equivalent. This takes
90 // O(# of apps) worst-case.
91 virtual int PageStringOrdinalAsInteger(
92 const syncer::StringOrdinal& page_ordinal) const = 0;
94 // Converts the page index integer to its StringOrdinal equivalent. This takes
95 // O(# of apps) worst-case.
96 virtual syncer::StringOrdinal PageIntegerAsStringOrdinal(
97 size_t page_index) = 0;
99 // Hides an extension from the new tab page, or makes a previously hidden
100 // extension visible.
101 virtual void SetExtensionVisible(const std::string& extension_id,
102 bool visible) = 0;
104 private:
105 DISALLOW_COPY_AND_ASSIGN(AppSorting);
108 } // namespace extensions
110 #endif // EXTENSIONS_BROWSER_APP_SORTING_H_