#include "chrome/browser/ui/tabs/saved_tab_groups/saved_tab_group_keyed_service.h"
#include <memory>
#include <optional>
#include "base/check_op.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/location.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "base/notreached.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "base/uuid.h"
#include "chrome/browser/bookmarks/url_and_id.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync/data_type_store_service_factory.h"
#include "chrome/browser/sync/device_info_sync_service_factory.h"
#include "chrome/browser/sync/sync_service_factory.h"
#include "chrome/browser/ui/bookmarks/bookmark_utils_desktop.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/saved_tab_groups/saved_tab_group_model_listener.h"
#include "chrome/browser/ui/tabs/saved_tab_groups/saved_tab_group_pref_names.h"
#include "chrome/browser/ui/tabs/saved_tab_groups/saved_tab_group_utils.h"
#include "chrome/browser/ui/tabs/saved_tab_groups/tab_group_sync_service_proxy.h"
#include "chrome/browser/ui/tabs/tab_group.h"
#include "chrome/browser/ui/tabs/tab_group_model.h"
#include "chrome/common/channel_info.h"
#include "components/data_sharing/public/features.h"
#include "components/saved_tab_groups/features.h"
#include "components/saved_tab_groups/saved_tab_group_model.h"
#include "components/saved_tab_groups/saved_tab_group_sync_bridge.h"
#include "components/saved_tab_groups/saved_tab_group_tab.h"
#include "components/saved_tab_groups/stats.h"
#include "components/saved_tab_groups/sync_data_type_configuration.h"
#include "components/saved_tab_groups/tab_group_sync_bridge_mediator.h"
#include "components/saved_tab_groups/tab_group_sync_metrics_logger.h"
#include "components/saved_tab_groups/tab_group_sync_service.h"
#include "components/saved_tab_groups/types.h"
#include "components/sync/base/data_type.h"
#include "components/sync/base/report_unrecoverable_error.h"
#include "components/sync/model/client_tag_based_data_type_processor.h"
#include "components/sync/model/data_type_local_change_processor.h"
#include "components/sync/model/data_type_store_service.h"
#include "components/sync/service/sync_service.h"
#include "components/sync/service/sync_user_settings.h"
#include "components/sync_device_info/device_info_sync_service.h"
#include "components/sync_device_info/device_info_tracker.h"
#include "components/tab_groups/tab_group_id.h"
#include "components/tab_groups/tab_group_visual_data.h"
#include "content/public/browser/web_contents.h"
namespace tab_groups {
namespace {
class ScopedLocalObservationPauserImpl : public ScopedLocalObservationPauser { … };
ScopedLocalObservationPauserImpl::ScopedLocalObservationPauserImpl(
SavedTabGroupModelListener* listener)
: … { … }
ScopedLocalObservationPauserImpl::~ScopedLocalObservationPauserImpl() { … }
constexpr base::TimeDelta kDelayBeforeMetricsLogged = …;
std::unique_ptr<syncer::DataTypeLocalChangeProcessor>
CreateSavedTabGroupChangeProcessor() { … }
std::unique_ptr<syncer::DataTypeLocalChangeProcessor>
CreateSharedTabGroupDataChangeProcessor() { … }
std::unique_ptr<SyncDataTypeConfiguration>
MaybeCreateSyncConfigurationForSharedTabGroupData(
syncer::OnceDataTypeStoreFactory store_factory) { … }
}
SavedTabGroupKeyedService::SavedTabGroupKeyedService(
Profile* profile,
syncer::DeviceInfoTracker* device_info_tracker)
: … { … }
SavedTabGroupKeyedService::~SavedTabGroupKeyedService() { … }
syncer::OnceDataTypeStoreFactory SavedTabGroupKeyedService::GetStoreFactory() { … }
base::WeakPtr<syncer::DataTypeControllerDelegate>
SavedTabGroupKeyedService::GetSavedTabGroupControllerDelegate() { … }
base::WeakPtr<syncer::DataTypeControllerDelegate>
SavedTabGroupKeyedService::GetSharedTabGroupControllerDelegate() { … }
void SavedTabGroupKeyedService::ConnectRestoredGroupToSaveId(
const base::Uuid& saved_guid,
const TabGroupId local_group_id) { … }
void SavedTabGroupKeyedService::SaveRestoredGroup(SavedTabGroup group) { … }
void SavedTabGroupKeyedService::UpdateAttributions(
const LocalTabGroupID& group_id,
const std::optional<LocalTabID>& tab_id) { … }
std::optional<std::string> SavedTabGroupKeyedService::GetLocalCacheGuid()
const { … }
std::unique_ptr<ScopedLocalObservationPauser>
SavedTabGroupKeyedService::CreateScopedLocalObserverPauser() { … }
void SavedTabGroupKeyedService::OnTabAddedToGroupLocally(
const base::Uuid& group_guid) { … }
void SavedTabGroupKeyedService::OnTabRemovedFromGroupLocally(
const base::Uuid& group_guid,
const base::Uuid& tab_guid) { … }
void SavedTabGroupKeyedService::OnTabNavigatedLocally(
const base::Uuid& group_guid,
const base::Uuid& tab_guid) { … }
void SavedTabGroupKeyedService::OnTabsReorderedLocally(
const base::Uuid& group_guid) { … }
void SavedTabGroupKeyedService::OnTabGroupVisualsChanged(
const base::Uuid& group_guid) { … }
std::optional<TabGroupId> SavedTabGroupKeyedService::OpenSavedTabGroupInBrowser(
Browser* browser,
const base::Uuid saved_group_guid,
OpeningSource opening_source) { … }
TabGroupId SavedTabGroupKeyedService::AddOpenedTabsToGroup(
TabStripModel* const tab_strip_model_for_creation,
const std::map<tabs::TabModel*, base::Uuid>& tab_guid_mapping,
const SavedTabGroup& saved_group) { … }
base::Uuid SavedTabGroupKeyedService::SaveGroup(const TabGroupId& group_id,
bool is_pinned) { … }
void SavedTabGroupKeyedService::UnsaveGroup(const TabGroupId& group_id,
ClosingSource closing_source) { … }
void SavedTabGroupKeyedService::PauseTrackingLocalTabGroup(
const TabGroupId& group_id) { … }
void SavedTabGroupKeyedService::ResumeTrackingLocalTabGroup(
const base::Uuid& saved_group_guid,
const TabGroupId& group_id) { … }
void SavedTabGroupKeyedService::DisconnectLocalTabGroup(
const TabGroupId& group_id) { … }
void SavedTabGroupKeyedService::ConnectLocalTabGroup(
const TabGroupId& local_group_id,
const base::Uuid& saved_guid) { … }
void SavedTabGroupKeyedService::SavedTabGroupModelLoaded() { … }
void SavedTabGroupKeyedService::SavedTabGroupRemovedFromSync(
const SavedTabGroup& removed_group) { … }
void SavedTabGroupKeyedService::SavedTabGroupUpdatedFromSync(
const base::Uuid& group_guid,
const std::optional<base::Uuid>& tab_guid) { … }
void SavedTabGroupKeyedService::AddMissingTabsToOutOfSyncLocalTabGroup(
Browser* browser,
const TabGroup* const tab_group,
const SavedTabGroup* const saved_group) { … }
void SavedTabGroupKeyedService::RemoveExtraTabsFromOutOfSyncLocalTabGroup(
TabStripModel* tab_strip_model,
TabGroup* const tab_group,
const SavedTabGroup* const saved_group) { … }
void SavedTabGroupKeyedService::UpdateWebContentsToMatchSavedTabGroupTabs(
const TabStripModel* const tab_strip_model,
const SavedTabGroup* const saved_group,
const gfx::Range& tab_range) { … }
std::map<tabs::TabModel*, base::Uuid>
SavedTabGroupKeyedService::GetTabToGuidMappingForSavedGroup(
const TabStripModel* const tab_strip_model,
const SavedTabGroup* const saved_group,
const gfx::Range& tab_range) { … }
std::map<tabs::TabModel*, base::Uuid>
SavedTabGroupKeyedService::OpenSavedTabGroupAndGetTabToGuidMapping(
Browser* browser,
const SavedTabGroup* const saved_group) { … }
const TabStripModel* SavedTabGroupKeyedService::GetTabStripModelWithTabGroupId(
const TabGroupId& local_group_id) { … }
void SavedTabGroupKeyedService::UpdateGroupVisualData(
const base::Uuid saved_group_guid,
const TabGroupId group_id) { … }
void SavedTabGroupKeyedService::RecordMetrics() { … }
void SavedTabGroupKeyedService::RecordTabGroupMetrics() { … }
void SavedTabGroupKeyedService::LogEvent(
TabGroupEvent event,
const base::Uuid& group_saved_id,
const std::optional<base::Uuid>& tab_saved_id) { … }
}