#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "chrome/browser/extensions/chrome_app_sorting.h"
#include <algorithm>
#include <memory>
#include <optional>
#include <utility>
#include <vector>
#include "base/feature_list.h"
#include "base/task/sequenced_task_runner.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "chrome/browser/extensions/extension_sync_service.h"
#include "chrome/browser/extensions/install_tracker.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_sync_bridge.h"
#include "chrome/common/chrome_features.h"
#include "chrome/common/extensions/extension_constants.h"
#include "components/app_constants/constants.h"
#include "components/webapps/common/web_app_id.h"
#include "extensions/browser/extension_prefs.h"
#include "extensions/browser/extension_system.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/manifest_handlers/app_display_info.h"
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chrome/browser/ash/extensions/default_app_order.h"
#endif
namespace extensions {
namespace {
template <typename Multimap, typename Key, typename Value>
bool DoesMultimapContainKeyAndValue(const Multimap& map,
const Key& key,
const Value& value) { … }
const size_t kNaturalAppPageSize = …;
const char kPrefAppLaunchIndexDeprecated[] = …;
const char kPrefAppLaunchOrdinal[] = …;
const char kPrefPageIndexDeprecated[] = …;
const char kPrefPageOrdinal[] = …;
}
ChromeAppSorting::AppOrdinals::AppOrdinals() = default;
ChromeAppSorting::AppOrdinals::AppOrdinals(const AppOrdinals& other) = default;
ChromeAppSorting::AppOrdinals::~AppOrdinals() = default;
ChromeAppSorting::ChromeAppSorting(content::BrowserContext* browser_context)
: … { … }
ChromeAppSorting::~ChromeAppSorting() { … }
void ChromeAppSorting::CreateOrdinalsIfNecessary(size_t minimum_size) { … }
void ChromeAppSorting::MigrateAppIndex(const ExtensionIdList& extension_ids) { … }
void ChromeAppSorting::InitializePageOrdinalMapFromWebApps() { … }
void ChromeAppSorting::FixNTPOrdinalCollisions() { … }
void ChromeAppSorting::EnsureValidOrdinals(
const ExtensionId& extension_id,
const syncer::StringOrdinal& suggested_page) { … }
bool ChromeAppSorting::GetDefaultOrdinals(
const ExtensionId& extension_id,
syncer::StringOrdinal* page_ordinal,
syncer::StringOrdinal* app_launch_ordinal) { … }
void ChromeAppSorting::OnExtensionMoved(
const ExtensionId& moved_extension_id,
const ExtensionId& predecessor_extension_id,
const ExtensionId& successor_extension_id) { … }
syncer::StringOrdinal ChromeAppSorting::GetAppLaunchOrdinal(
const ExtensionId& extension_id) const { … }
void ChromeAppSorting::SetAppLaunchOrdinal(
const ExtensionId& extension_id,
const syncer::StringOrdinal& new_app_launch_ordinal) { … }
syncer::StringOrdinal ChromeAppSorting::CreateFirstAppLaunchOrdinal(
const syncer::StringOrdinal& page_ordinal) const { … }
syncer::StringOrdinal ChromeAppSorting::CreateNextAppLaunchOrdinal(
const syncer::StringOrdinal& page_ordinal) const { … }
syncer::StringOrdinal ChromeAppSorting::CreateFirstAppPageOrdinal() const { … }
syncer::StringOrdinal ChromeAppSorting::GetNaturalAppPageOrdinal() const { … }
syncer::StringOrdinal ChromeAppSorting::GetPageOrdinal(
const ExtensionId& extension_id) const { … }
void ChromeAppSorting::SetPageOrdinal(
const ExtensionId& extension_id,
const syncer::StringOrdinal& new_page_ordinal) { … }
void ChromeAppSorting::ClearOrdinals(const ExtensionId& extension_id) { … }
int ChromeAppSorting::PageStringOrdinalAsInteger(
const syncer::StringOrdinal& page_ordinal) const { … }
syncer::StringOrdinal ChromeAppSorting::PageIntegerAsStringOrdinal(
size_t page_index) { … }
void ChromeAppSorting::SetExtensionVisible(const ExtensionId& extension_id,
bool visible) { … }
void ChromeAppSorting::OnWebAppInstalled(const webapps::AppId& app_id) { … }
void ChromeAppSorting::OnWebAppInstallManagerDestroyed() { … }
void ChromeAppSorting::OnWebAppsWillBeUpdatedFromSync(
const std::vector<const web_app::WebApp*>& updated_apps_state) { … }
void ChromeAppSorting::OnAppRegistrarDestroyed() { … }
syncer::StringOrdinal ChromeAppSorting::GetMinOrMaxAppLaunchOrdinalsOnPage(
const syncer::StringOrdinal& target_page_ordinal,
AppLaunchOrdinalReturn return_type) const { … }
void ChromeAppSorting::InitializePageOrdinalMap(
const ExtensionIdList& extension_ids) { … }
void ChromeAppSorting::AddOrdinalMapping(
const ExtensionId& extension_id,
const syncer::StringOrdinal& page_ordinal,
const syncer::StringOrdinal& app_launch_ordinal) { … }
void ChromeAppSorting::RemoveOrdinalMapping(
const ExtensionId& extension_id,
const syncer::StringOrdinal& page_ordinal,
const syncer::StringOrdinal& app_launch_ordinal) { … }
void ChromeAppSorting::SyncIfNeeded(const ExtensionId& extension_id) { … }
void ChromeAppSorting::CreateDefaultOrdinals() { … }
syncer::StringOrdinal ChromeAppSorting::ResolveCollision(
const syncer::StringOrdinal& page_ordinal,
const syncer::StringOrdinal& app_launch_ordinal) const { … }
size_t ChromeAppSorting::CountItemsVisibleOnNtp(
const AppLaunchOrdinalMap& m) const { … }
void ChromeAppSorting::OnExtensionLoaded(
content::BrowserContext* browser_context,
const Extension* extension) { … }
}