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