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
|
// 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 CHROME_BROWSER_AUXILIARY_SEARCH_FETCH_AND_RANK_HELPER_H_
#define CHROME_BROWSER_AUXILIARY_SEARCH_FETCH_AND_RANK_HELPER_H_
#include <jni.h>
#include "base/android/scoped_java_ref.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "components/visited_url_ranking/public/visited_url_ranking_service.h"
namespace visited_url_ranking {
class VisitedURLRankingService;
struct URLVisitsMetadata;
struct URLVisitAggregate;
struct FetchOptions;
struct Config;
} // namespace visited_url_ranking
// Class to manage history data fetch and rank flow, containing required
// parameters and states, and to create java objects and run the callback.
class FetchAndRankHelper : public base::RefCounted<FetchAndRankHelper> {
public:
using FetchResultCallback = base::OnceCallback<void(
std::vector<jni_zero::ScopedJavaLocalRef<jobject>>)>;
// The |entries_callback| is called when history data is fetched and ranked.
// It passes a List<AuxiliarySearchDataEntry> to Java.
FetchAndRankHelper(
visited_url_ranking::VisitedURLRankingService* ranking_service,
FetchResultCallback entries_callback,
const std::optional<GURL>& custom_tab_url = std::nullopt,
std::optional<base::Time> begin_time = std::nullopt);
// Starts the service to fetch history data.
void StartFetching();
private:
friend class base::RefCounted<FetchAndRankHelper>;
~FetchAndRankHelper();
// Continuing after StartFetching()'s call to FetchURLVisitAggregates().
void OnFetched(
visited_url_ranking::ResultStatus status,
visited_url_ranking::URLVisitsMetadata url_visits_metadata,
std::vector<visited_url_ranking::URLVisitAggregate> aggregates);
// Continuing after OnFetched()'s call to RankVisitAggregates().
void OnRanked(visited_url_ranking::URLVisitsMetadata url_visits_metadata,
visited_url_ranking::ResultStatus status,
std::vector<visited_url_ranking::URLVisitAggregate> aggregates);
private:
raw_ptr<visited_url_ranking::VisitedURLRankingService> ranking_service_;
FetchResultCallback entries_callback_;
std::optional<GURL> custom_tab_url_;
const visited_url_ranking::FetchOptions fetch_options_;
const visited_url_ranking::Config config_;
};
#endif // CHROME_BROWSER_AUXILIARY_SEARCH_FETCH_AND_RANK_HELPER_H_
|