Chromium Code Reviews| Index: chrome/browser/ui/app_list/app_list_extension_sorting.h |
| diff --git a/chrome/browser/ui/app_list/app_list_extension_sorting.h b/chrome/browser/ui/app_list/app_list_extension_sorting.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..55a85b7e0551f7aee870084c56c0fde052b11e01 |
| --- /dev/null |
| +++ b/chrome/browser/ui/app_list/app_list_extension_sorting.h |
| @@ -0,0 +1,109 @@ |
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CHROME_BROWSER_UI_APP_LIST_APP_LIST_EXTENSION_SORTING_H_ |
| +#define CHROME_BROWSER_UI_APP_LIST_APP_LIST_EXTENSION_SORTING_H_ |
| + |
| +#include <map> |
| +#include <set> |
| +#include <string> |
| + |
| +#include "chrome/common/extensions/extension.h" |
| +#include "sync/api/string_ordinal.h" |
| + |
| +class ExtensionScopedPrefs; |
| +class ExtensionServiceInterface; |
| +class PrefService; |
| + |
| +// The order of apps in the app list. This class defines the order by assigning |
| +// each app a single string ordinal. This class works on an in-memory map of |
| +// ordinals which it uses to resolve conflicts generated by sync and which it |
| +// commits to prefs for persistence. The information represented in the in- |
| +// memory map and prefs should always match once Initialize() is called. |
| +class AppListExtensionSorting { |
| + public: |
| + explicit AppListExtensionSorting( |
| + ExtensionScopedPrefs* extension_scoped_prefs); |
| + ~AppListExtensionSorting(); |
| + // Set the ExtensionService to syncs order changes. |
| + void SetExtensionService(ExtensionServiceInterface* extension_service); |
| + |
| + // Initialize internal data structures that require |extension_ids|. After |
| + // this is called, the prefs and our internal data structures should always |
| + // reflect the same data. |
|
koz (OOO until 15th September)
2013/07/08 01:02:24
Could you elaborate more on what |extension_ids| i
calamity
2013/07/11 03:31:00
It has all installed apps but I think component ap
koz (OOO until 15th September)
2013/07/12 00:46:29
I meant to elaborate in the comment :-) The correc
calamity
2013/07/15 07:02:32
Done.
|
| + void Initialize(const extensions::ExtensionIdList& extension_ids); |
| + |
| + syncer::StringOrdinal GetAppListOrdinalFromPrefs( |
| + const std::string& extension_id); |
| + |
| + // Processes extensions sync data by setting the ordinal for the given |
| + // |extension_id| as |ordinal|. This can result in ordinal collisions so |
| + // FixSyncCollisions() should be called after all extensions are synced. |
| + // There should not be an existing ordinal for |extension_id|. |
| + void UpdateAppListOrdinalFromSync(const std::string& extension_id, |
| + const syncer::StringOrdinal& ordinal); |
| + |
| + // Resolves any conflicts that might be created as a result result of calls to |
| + // SetAppListOrdinalForSync() that results in two extensions having the same |
| + // position in the order. After this is called, it is guaranteed that there |
| + // will be no collisions. |
| + void FixSyncCollisions(); |
| + |
| + // Add an extension so that it precedes all other extensions in the order. |
| + void InsertAtFront(const std::string& extension_id); |
| + |
| + // Add an extension so that all other extensions precede it in the order. |
| + void InsertAtBack(const std::string& extension_id); |
| + |
| + // Updates the moved extension in the order so that it is now located after |
| + // the given predecessor and before the successor. Empty strings are used to |
| + // indicate no successor or predecessor. |
| + void OnExtensionMoved(const std::string& moved_extension_id, |
| + const std::string& predecessor_extension_id, |
| + const std::string& successor_extension_id); |
| + |
| + // Removes an app from the order. Does nothing if |extension_id| is not in |
| + // the order. |
| + void Erase(const std::string& extension_id); |
| + |
| + // Returns true if |extension1| appears before |extension2| in the order. |
| + bool ExtensionPrecedes(const std::string& extension_id1, |
| + const std::string& extension_id2); |
| + |
| + // Returns true if |extension_id| is in the order. |
| + bool Contains(const std::string& extension_id); |
| + |
| + private: |
| + typedef std::set<std::string> ExtensionIdSet; |
| + typedef std::map<syncer::StringOrdinal, ExtensionIdSet, |
| + syncer::StringOrdinal::LessThanFn> AppListOrdinalMap; |
| + |
| + // Sets the ordinal for the extension to the ordinal found in prefs. Adds the |
| + // extension id to |uninitialized_extensions| if no ordinal is found in the |
| + // prefs. |
| + void InitializeOrdinalForExtension( |
| + const std::string extension_id, |
| + std::vector<std::string>& uninitialized_extensions); |
|
koz (OOO until 15th September)
2013/07/08 01:02:24
nit: newline after this line
calamity
2013/07/11 03:31:00
Done.
|
| + // Sets the ordinal for any extension in |uninitialized_extensions| which has |
| + // a default order defined. |
| + void InitializeWithDefaultOrdinals( |
| + const std::vector<std::string>& uninitialized_extensions); |
| + |
| + void SetAppListOrdinal(const std::string& extension_id, |
| + const syncer::StringOrdinal& ordinal); |
| + void EraseAppListOrdinal(const std::string& extension_id); |
| + void UpdatePrefs(const std::string& extension_id, |
| + const syncer::StringOrdinal& ordinal); |
| + void UpdatePrefsAndSync(const std::string& extension_id, |
| + const syncer::StringOrdinal& ordinal); |
| + |
| + extensions::ExtensionIdList default_initialized_extensions_; |
| + AppListOrdinalMap app_list_ordinal_map_; |
| + ExtensionScopedPrefs* extension_scoped_prefs_; // Weak, owns this instance. |
| + ExtensionServiceInterface* extension_service_; // Weak. |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AppListExtensionSorting); |
| +}; |
| + |
| +#endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_EXTENSION_SORTING_H_ |