Files.app: Dispatch 'drive-connection-changed' event on initialization of VolumeManag...
[chromium-blink-merge.git] / extensions / browser / app_sorting.h
blobbc6378db30536d1643bbacafee4d06126655efde
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 // CHECKs that SetExtensionScopedPrefs has been called with a non-null object.
31 // TODO(mgiuca): Added this to try and diagnose http://crbug.com/476648.
32 // Remove it after the investigation is concluded.
33 virtual void CheckExtensionScopedPrefs() const = 0;
35 // Sets up the ExtensionSyncService to inform of changes that require syncing.
36 virtual void SetExtensionSyncService(
37 ExtensionSyncService* extension_sync_service) = 0;
39 // Properly initializes internal values that require |extension_ids|.
40 // SetExtensionScopedPrefs must have been called prior to this.
41 virtual void Initialize(const extensions::ExtensionIdList& extension_ids) = 0;
43 // Resolves any conflicts the might be created as a result of syncing that
44 // results in two icons having the same page and app launch ordinal. After
45 // this is called it is guaranteed that there are no collisions of NTP icons.
46 virtual void FixNTPOrdinalCollisions() = 0;
48 // This ensures that the extension has valid ordinals, and if it doesn't then
49 // properly initialize them. |suggested_page| will be used if it is valid and
50 // the extension has no valid user-set page ordinal.
51 virtual void EnsureValidOrdinals(
52 const std::string& extension_id,
53 const syncer::StringOrdinal& suggested_page) = 0;
55 // Updates the app launcher value for the moved extension so that it is now
56 // located after the given predecessor and before the successor.
57 // Empty strings are used to indicate no successor or predecessor.
58 virtual void OnExtensionMoved(const std::string& moved_extension_id,
59 const std::string& predecessor_extension_id,
60 const std::string& successor_extension_id) = 0;
62 // Get the application launch ordinal for an app with |extension_id|. This
63 // determines the order in which the app appears on the page it's on in the
64 // New Tab Page (Note that you can compare app launch ordinals only if the
65 // apps are on the same page). A string value close to |a*| generally
66 // indicates top left. If the extension has no launch ordinal, an invalid
67 // StringOrdinal is returned.
68 virtual syncer::StringOrdinal GetAppLaunchOrdinal(
69 const std::string& extension_id) const = 0;
71 // Sets a specific launch ordinal for an app with |extension_id|.
72 virtual void SetAppLaunchOrdinal(
73 const std::string& extension_id,
74 const syncer::StringOrdinal& new_app_launch_ordinal) = 0;
76 // Returns a StringOrdinal that is lower than any app launch ordinal for the
77 // given page.
78 virtual syncer::StringOrdinal CreateFirstAppLaunchOrdinal(
79 const syncer::StringOrdinal& page_ordinal) const = 0;
81 // Returns a StringOrdinal that is higher than any app launch ordinal for the
82 // given page.
83 virtual syncer::StringOrdinal CreateNextAppLaunchOrdinal(
84 const syncer::StringOrdinal& page_ordinal) const = 0;
86 // Returns a StringOrdinal that is lower than any existing page ordinal.
87 virtual syncer::StringOrdinal CreateFirstAppPageOrdinal() const = 0;
89 // Gets the page a new app should install to, which is the earliest non-full
90 // page. The returned ordinal may correspond to a page that doesn't yet exist
91 // if all pages are full.
92 virtual syncer::StringOrdinal GetNaturalAppPageOrdinal() const = 0;
94 // Get the page ordinal for an app with |extension_id|. This determines
95 // which page an app will appear on in page-based NTPs. If the app has no
96 // page specified, an invalid StringOrdinal is returned.
97 virtual syncer::StringOrdinal GetPageOrdinal(
98 const std::string& extension_id) const = 0;
100 // Sets a specific page ordinal for an app with |extension_id|.
101 virtual void SetPageOrdinal(
102 const std::string& extension_id,
103 const syncer::StringOrdinal& new_page_ordinal) = 0;
105 // Removes the ordinal values for an app.
106 virtual void ClearOrdinals(const std::string& extension_id) = 0;
108 // Convert the page StringOrdinal value to its integer equivalent. This takes
109 // O(# of apps) worst-case.
110 virtual int PageStringOrdinalAsInteger(
111 const syncer::StringOrdinal& page_ordinal) const = 0;
113 // Converts the page index integer to its StringOrdinal equivalent. This takes
114 // O(# of apps) worst-case.
115 virtual syncer::StringOrdinal PageIntegerAsStringOrdinal(
116 size_t page_index) = 0;
118 // Hides an extension from the new tab page, or makes a previously hidden
119 // extension visible.
120 virtual void SetExtensionVisible(const std::string& extension_id,
121 bool visible) = 0;
123 private:
124 DISALLOW_COPY_AND_ASSIGN(AppSorting);
127 } // namespace extensions
129 #endif // EXTENSIONS_BROWSER_APP_SORTING_H_