Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(854)

Unified Diff: chrome/browser/ui/app_list/app_list_extension_sorting.h

Issue 17038002: Separate the NTP app ordering from the app list app ordering (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: revert lazy initialzation Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..7814452bfe848073eba4d5b3bdd946da5bd8e08d
--- /dev/null
+++ b/chrome/browser/ui/app_list/app_list_extension_sorting.h
@@ -0,0 +1,127 @@
+// 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 "base/observer_list.h"
+#include "chrome/common/extensions/extension.h"
+#include "sync/api/string_ordinal.h"
+
+class AppListExtensionSortingObserver;
+class ExtensionScopedPrefs;
+class ExtensionServiceInterface;
+class ExtensionSorting;
+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 the |extension_ids| of all
+ // installed extensions. After this is called, the prefs and our internal data
+ // structures should always reflect the same data. |extension_ids| should not
+ // contain the Web Store and Chrome component apps. The order from
+ // |ntp_sorted_extensions| will be used to initialize any uninitalized
+ // extensions.
+ void Initialize(const extensions::ExtensionIdList& extension_ids,
+ const extensions::ExtensionIdList& ntp_sorted_extensions);
+
+ 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);
+
+ void AddObserver(AppListExtensionSortingObserver* observer);
+ void RemoveObserver(AppListExtensionSortingObserver* observer);
+
+ 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. Returns
+ // true if a valid ordinal for the given |extension_id| was found in the
+ // prefs.
+ bool InitializeOrdinalFromPrefs(const std::string& extension_id);
+
+ // Sets the ordinal for any extension in |uninitialized_extensions| which has
+ // an ordinal defined in |ntp_extension_sorting|. Removes initialized
+ // extension ids from |uninitialized_extensions|.
+ void InitializeFromNTPExtensionSorting(
+ const extensions::ExtensionIdList& ntp_sorted_extension_ids,
+ ExtensionIdSet* uninitialized_extensions);
+
+ // Sets the ordinal for any extension in |uninitialized_extensions| which has
+ // a default order defined.
+ void InitializeWithDefaultOrdinals(
+ const ExtensionIdSet& 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);
+
+ extensions::ExtensionIdList default_initialized_extensions_;
koz (OOO until 15th September) 2013/09/04 00:26:05 A comment for this member is still useful :-)
+ // A map of ordinals to the extension ids that have that ordinal. This is used
+ // to resolve ordinal conflicts.
+ AppListOrdinalMap app_list_ordinal_map_;
+ ExtensionScopedPrefs* extension_scoped_prefs_; // Weak, owns this instance.
+ ExtensionServiceInterface* extension_service_; // Weak.
+
+ ObserverList<AppListExtensionSortingObserver, true> observers_;
+
+ DISALLOW_COPY_AND_ASSIGN(AppListExtensionSorting);
+};
+
+#endif // CHROME_BROWSER_UI_APP_LIST_APP_LIST_EXTENSION_SORTING_H_

Powered by Google App Engine
This is Rietveld 408576698