1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_VISITED_URL_RANKING_INTERNAL_URL_GROUPING_GROUP_SUGGESTIONS_SERVICE_IMPL_H_
#define COMPONENTS_VISITED_URL_RANKING_INTERNAL_URL_GROUPING_GROUP_SUGGESTIONS_SERVICE_IMPL_H_
#include <memory>
#include "base/containers/flat_map.h"
#include "base/memory/weak_ptr.h"
#include "base/supports_user_data.h"
#include "base/time/clock.h"
#include "components/visited_url_ranking/internal/url_grouping/group_suggestions_manager.h"
#include "components/visited_url_ranking/internal/url_grouping/tab_event_tracker_impl.h"
#include "components/visited_url_ranking/internal/url_grouping/tab_events_visit_transformer.h"
#include "components/visited_url_ranking/public/url_grouping/group_suggestions_service.h"
#include "components/visited_url_ranking/public/url_grouping/tab_event_tracker.h"
#include "components/visited_url_ranking/public/visited_url_ranking_service.h"
class PrefService;
class PrefRegistrySimple;
namespace visited_url_ranking {
class GroupSuggestionsServiceImpl : public GroupSuggestionsService,
public base::SupportsUserData::Data {
public:
GroupSuggestionsServiceImpl(
VisitedURLRankingService* visited_url_ranking_service,
TabEventsVisitTransformer* tab_events_transformer,
PrefService* pref_service);
~GroupSuggestionsServiceImpl() override;
GroupSuggestionsServiceImpl(const GroupSuggestionsServiceImpl&) = delete;
GroupSuggestionsServiceImpl& operator=(const GroupSuggestionsServiceImpl&) =
delete;
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
// GroupSuggestionsService impl:
TabEventTracker* GetTabEventTracker() override;
std::optional<CachedSuggestions> GetCachedSuggestions(
const Scope& scope) override;
void RegisterDelegate(GroupSuggestionsDelegate* delegate,
const Scope& scope) override;
void UnregisterDelegate(GroupSuggestionsDelegate* delegate) override;
void SetConfigForTesting(base::TimeDelta computation_delay) override;
GroupSuggestionsManager* group_suggestions_manager_for_testing() {
return group_suggestions_manager_.get();
}
// Invalidates the cached suggestions.
void InvalidateCache();
private:
void OnNewSuggestionTabEvent();
const raw_ptr<VisitedURLRankingService> visited_url_ranking_service_;
const raw_ptr<TabEventsVisitTransformer> tab_events_transformer_;
std::unique_ptr<GroupSuggestionsManager> group_suggestions_manager_;
std::unique_ptr<TabEventTrackerImpl> tab_tracker_;
base::WeakPtrFactory<GroupSuggestionsServiceImpl> weak_ptr_factory_{this};
};
} // namespace visited_url_ranking
#endif // COMPONENTS_VISITED_URL_RANKING_INTERNAL_URL_GROUPING_GROUP_SUGGESTIONS_SERVICE_IMPL_H_
|