Commit 8a70e468 authored by tby's avatar tby Committed by Commit Bot

[Dolphin] Add access to the underlying FrecencyStore's data structure.

This adds methods that allow the user of a RecurrenceRanker to mutably
access the storage maps of the ranker's FrecencyStore. This is useful
for custom target/condition deletion logic that cannot be efficiently
implemented via RemoveTarget/Condition.

Bug: 921444
Change-Id: If6add2dee46e6cbd2b0a33820a5e613d5fde3d23
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1669010Reviewed-by: default avatarCharles . <charleszhao@chromium.org>
Commit-Queue: Tony Yeoman <tby@chromium.org>
Cr-Commit-Position: refs/heads/master@{#671965}
parent 2ca4ba98
......@@ -52,6 +52,13 @@ class FrecencyStore {
// updated, and none of the scores are below the |min_score_| threshold.
const base::flat_map<std::string, FrecencyStore::ValueData>& GetAll();
// Returns the underlying storage data structure. This does not ensure scores
// are correct, and should not be used for scoring items. However it is
// useful, for example, for implementing custom cleanup logic.
base::flat_map<std::string, FrecencyStore::ValueData>* get_mutable_values() {
return &values_;
}
void ToProto(FrecencyStoreProto* proto) const;
void FromProto(const FrecencyStoreProto& proto);
......
......@@ -18,7 +18,6 @@
#include "base/task_runner_util.h"
#include "base/threading/scoped_blocking_call.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/app_list/search/search_result_ranker/frecency_store.h"
#include "chrome/browser/ui/app_list/search/search_result_ranker/frecency_store.pb.h"
#include "chrome/browser/ui/app_list/search/search_result_ranker/histogram_util.h"
#include "chrome/browser/ui/app_list/search/search_result_ranker/recurrence_predictor.h"
......@@ -284,6 +283,16 @@ std::vector<std::pair<std::string, float>> RecurrenceRanker::RankTopN(
return SortAndTruncateRanks(n, Rank(condition));
}
base::flat_map<std::string, FrecencyStore::ValueData>*
RecurrenceRanker::GetTargetData() {
return targets_->get_mutable_values();
}
base::flat_map<std::string, FrecencyStore::ValueData>*
RecurrenceRanker::GetConditionData() {
return conditions_->get_mutable_values();
}
void RecurrenceRanker::SaveToDisk() {
if (is_ephemeral_user_)
return;
......
......@@ -17,6 +17,7 @@
#include "base/memory/weak_ptr.h"
#include "base/sequenced_task_runner.h"
#include "base/time/time.h"
#include "chrome/browser/ui/app_list/search/search_result_ranker/frecency_store.h"
#include "chrome/browser/ui/app_list/search/search_result_ranker/recurrence_ranker_config.pb.h"
namespace app_list {
......@@ -78,6 +79,12 @@ class RecurrenceRanker {
// after a target or condition is deleted.
void SaveToDisk();
// Return a pointer to the underlying storage of the FrecencyStore for targets
// or conditions. These should not be used under normal use or ranking.
// However, they are useful for custom cleanup logic.
base::flat_map<std::string, FrecencyStore::ValueData>* GetTargetData();
base::flat_map<std::string, FrecencyStore::ValueData>* GetConditionData();
const char* GetPredictorNameForTesting() const;
private:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment