• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 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.
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"
11 #include "extensions/common/extension.h"
12 #include "sync/api/string_ordinal.h"
13 
14 class ExtensionSyncService;
15 
16 namespace extensions {
17 
18 class ExtensionScopedPrefs;
19 
20 // An interface that provides a fixed ordering for a set of apps.
21 class AppSorting {
22  public:
AppSorting()23   AppSorting() {}
~AppSorting()24   virtual ~AppSorting() {}
25 
26   // Sets the object used to look up preferences. Ownership remains with the
27   // caller.
28   virtual void SetExtensionScopedPrefs(ExtensionScopedPrefs* prefs) = 0;
29 
30   // Sets up the ExtensionSyncService to inform of changes that require syncing.
31   virtual void SetExtensionSyncService(
32       ExtensionSyncService* extension_sync_service) = 0;
33 
34   // Properly initializes internal values that require |extension_ids|.
35   virtual void Initialize(const extensions::ExtensionIdList& extension_ids) = 0;
36 
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;
41 
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;
48 
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;
55 
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;
64 
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;
69 
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;
74 
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;
79 
80   // Returns a StringOrdinal that is lower than any existing page ordinal.
81   virtual syncer::StringOrdinal CreateFirstAppPageOrdinal() const = 0;
82 
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;
87 
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;
93 
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;
98 
99   // Removes the ordinal values for an app.
100   virtual void ClearOrdinals(const std::string& extension_id) = 0;
101 
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;
106 
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;
111 
112   // Hidden extensions don't appear in the new tab page.
113   virtual void MarkExtensionAsHidden(const std::string& extension_id) = 0;
114 
115  private:
116   DISALLOW_COPY_AND_ASSIGN(AppSorting);
117 };
118 
119 }  // namespace extensions
120 
121 #endif  // EXTENSIONS_BROWSER_APP_SORTING_H_
122