#include "chrome/browser/ui/tabs/recent_tabs_sub_menu_model.h"
#include <stddef.h>
#include <algorithm>
#include <memory>
#include <set>
#include "base/containers/fixed_flat_set.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/memory/raw_ptr.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/notreached.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/utf_string_conversions.h"
#include "build/build_config.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/favicon/favicon_service_factory.h"
#include "chrome/browser/favicon/favicon_utils.h"
#include "chrome/browser/favicon/history_ui_favicon_request_handler_factory.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/search/search.h"
#include "chrome/browser/sessions/session_restore.h"
#include "chrome/browser/sessions/tab_restore_service_factory.h"
#include "chrome/browser/sync/session_sync_service_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_live_tab_context.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_group_theme.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/toolbar/app_menu_model.h"
#include "chrome/browser/ui/ui_features.h"
#include "chrome/grit/generated_resources.h"
#include "components/favicon/core/history_ui_favicon_request_handler.h"
#include "components/favicon_base/favicon_types.h"
#include "components/prefs/scoped_user_pref_update.h"
#include "components/sessions/core/tab_restore_service.h"
#include "components/strings/grit/components_strings.h"
#include "components/sync_sessions/open_tabs_ui_delegate.h"
#include "components/sync_sessions/session_sync_service.h"
#include "components/sync_sessions/synced_session.h"
#include "components/tab_groups/tab_group_id.h"
#include "components/vector_icons/vector_icons.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/image_model.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_features.h"
#include "ui/base/window_open_disposition_utils.h"
#include "ui/color/color_id.h"
#include "ui/color/color_provider.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/favicon_size.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/resources/grit/ui_resources.h"
namespace {
constexpr int kInitialGroupItem = …;
const int kMaxLocalEntries = …;
bool SortSessionsByRecency(const sync_sessions::SyncedSession* s1,
const sync_sessions::SyncedSession* s2) { … }
ui::ImageModel CreateFavicon(const gfx::VectorIcon& icon) { … }
}
struct RecentTabsSubMenuModel::TabItem { … };
struct RecentTabsSubMenuModel::SubMenuItem { … };
RecentTabsSubMenuModel::RecentTabsSubMenuModel(
ui::AcceleratorProvider* accelerator_provider,
Browser* browser)
: … { … }
RecentTabsSubMenuModel::~RecentTabsSubMenuModel() = default;
bool RecentTabsSubMenuModel::IsCommandIdChecked(int command_id) const { … }
bool RecentTabsSubMenuModel::IsCommandIdEnabled(int command_id) const { … }
bool RecentTabsSubMenuModel::GetAcceleratorForCommandId(
int command_id,
ui::Accelerator* accelerator) const { … }
bool RecentTabsSubMenuModel::ExecuteCustomCommand(int command_id,
int event_flags) { … }
void RecentTabsSubMenuModel::ExecuteCommand(int command_id, int event_flags) { … }
int RecentTabsSubMenuModel::GetFirstRecentTabsCommandId() { … }
void RecentTabsSubMenuModel::RegisterLogMenuMetricsCallback(
LogMenuMetricsCallback callback) { … }
void RecentTabsSubMenuModel::Build() { … }
void RecentTabsSubMenuModel::BuildLocalEntries() { … }
void RecentTabsSubMenuModel::BuildTabsFromOtherDevices() { … }
void RecentTabsSubMenuModel::BuildLocalTabItem(
const sessions::tab_restore::Tab& tab,
size_t curr_model_index) { … }
void RecentTabsSubMenuModel::BuildLocalWindowItem(
const sessions::tab_restore::Window& window,
size_t curr_model_index) { … }
void RecentTabsSubMenuModel::BuildLocalGroupItem(
const sessions::tab_restore::Group& group,
size_t curr_model_index) { … }
void RecentTabsSubMenuModel::BuildOtherDevicesTabItem(
SimpleMenuModel* containing_model,
const std::string& session_tag,
const sessions::SessionTab& tab) { … }
std::unique_ptr<ui::SimpleMenuModel>
RecentTabsSubMenuModel::CreateOtherDeviceSubMenu(
const sync_sessions::SyncedSession* session,
const std::vector<const sessions::SessionTab*>& tabs_in_session) { … }
std::unique_ptr<ui::SimpleMenuModel>
RecentTabsSubMenuModel::CreateWindowSubMenuModel(
const sessions::tab_restore::Window& window) { … }
std::unique_ptr<ui::SimpleMenuModel>
RecentTabsSubMenuModel::CreateGroupSubMenuModel(
const sessions::tab_restore::Group& group) { … }
void RecentTabsSubMenuModel::AddGroupItemToModel(
SimpleMenuModel* parent_model,
std::unique_ptr<SimpleMenuModel> group_model,
const sessions::tab_restore::Group& group) { … }
void RecentTabsSubMenuModel::AddTabItemToModel(
const sessions::tab_restore::Tab* tab,
ui::SimpleMenuModel* model,
int command_id) { … }
std::u16string RecentTabsSubMenuModel::GetGroupItemLabel(std::u16string title,
size_t num_tabs) { … }
int RecentTabsSubMenuModel::GetParentCommandId(int command_id) const { … }
void RecentTabsSubMenuModel::AddDeviceFavicon(
SimpleMenuModel* containing_model,
size_t index_in_menu,
syncer::DeviceInfo::FormFactor device_form_factor) { … }
void RecentTabsSubMenuModel::AddTabFavicon(int command_id,
ui::SimpleMenuModel* menu_model,
const GURL& url) { … }
void RecentTabsSubMenuModel::OnFaviconDataAvailable(
int command_id,
ui::SimpleMenuModel* menu_model,
const favicon_base::FaviconImageResult& image_result) { … }
RecentTabsSubMenuModel::TabItems*
RecentTabsSubMenuModel::GetTabVectorForCommandId(int command_id) { … }
void RecentTabsSubMenuModel::ClearLocalEntries() { … }
void RecentTabsSubMenuModel::ClearTabsFromOtherDevices() { … }
sync_sessions::OpenTabsUIDelegate*
RecentTabsSubMenuModel::GetOpenTabsUIDelegate() { … }
void RecentTabsSubMenuModel::TabRestoreServiceChanged(
sessions::TabRestoreService* service) { … }
void RecentTabsSubMenuModel::TabRestoreServiceDestroyed(
sessions::TabRestoreService* service) { … }
void RecentTabsSubMenuModel::OnForeignSessionUpdated() { … }
int RecentTabsSubMenuModel::GetAndIncrementNextMenuID() { … }
bool RecentTabsSubMenuModel::IsCommandType(CommandType command_type,
int command_id) const { … }