Commit 3ec8c055 authored by Patrick Noland's avatar Patrick Noland Committed by Commit Bot

[EoC] Check confidence on cached results

Bug: 849456
Change-Id: I296348c5fd7e4bb99c1c88694d05f80245d7d8fa
Reviewed-on: https://chromium-review.googlesource.com/1087685Reviewed-by: default avatarFilip Gorski <fgorski@chromium.org>
Commit-Queue: Patrick Noland <pnoland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564676}
parent b5a6dce0
......@@ -64,6 +64,8 @@ void ContextualContentSuggestionsService::FetchContextualSuggestionClusters(
url, std::move(callback), metrics_callback);
contextual_suggestions_fetcher_->FetchContextualSuggestionsClusters(
url, std::move(internal_callback), metrics_callback);
} else if (result.peek_conditions.confidence < kMinimumConfidence) {
BelowConfidenceThresholdFetchDone(std::move(callback), metrics_callback);
} else {
std::move(callback).Run(result);
}
......@@ -90,9 +92,7 @@ void ContextualContentSuggestionsService::FetchDone(
}
if (result.peek_conditions.confidence < kMinimumConfidence) {
metrics_callback.Run(contextual_suggestions::FETCH_BELOW_THRESHOLD);
std::move(callback).Run(
ContextualSuggestionsResult("", {}, PeekConditions()));
BelowConfidenceThresholdFetchDone(std::move(callback), metrics_callback);
return;
}
......@@ -107,4 +107,12 @@ ContextualContentSuggestionsService::CreateProxy() {
this, reporter_provider_->CreateReporter());
}
void ContextualContentSuggestionsService::BelowConfidenceThresholdFetchDone(
FetchClustersCallback callback,
ReportFetchMetricsCallback metrics_callback) {
metrics_callback.Run(contextual_suggestions::FETCH_BELOW_THRESHOLD);
std::move(callback).Run(
ContextualSuggestionsResult("", {}, PeekConditions()));
}
} // namespace contextual_suggestions
......@@ -68,6 +68,9 @@ class ContextualContentSuggestionsService : public KeyedService {
std::unique_ptr<ContextualContentSuggestionsServiceProxy> CreateProxy();
private:
void BelowConfidenceThresholdFetchDone(
FetchClustersCallback callback,
ReportFetchMetricsCallback metrics_callback);
// Cache for images of contextual suggestions, needed by CachedImageFetcher.
std::unique_ptr<ntp_snippets::RemoteSuggestionsDatabase>
contextual_suggestions_database_;
......
......@@ -279,4 +279,37 @@ TEST_F(ContextualContentSuggestionsServiceTest, ShouldEvictOldCachedResults) {
EXPECT_EQ(mock_callback.response_clusters.size(), 0u);
}
TEST_F(ContextualContentSuggestionsServiceTest,
ShouldNotReturnCachedLowConfidenceResults) {
MockClustersCallback mock_callback;
MockClustersCallback mock_callback2;
std::vector<Cluster> clusters;
GURL context_url("http://www.from.url");
clusters.emplace_back(ClusterBuilder("Title")
.AddSuggestion(SuggestionBuilder(context_url)
.Title("Title1")
.PublisherName("from.url")
.Snippet("Summary")
.ImageId("abc")
.Build())
.Build());
PeekConditions peek_conditions;
peek_conditions.confidence = 0;
fetcher()->SetFakeResponse(clusters, peek_conditions);
source()->FetchContextualSuggestionClusters(
context_url, mock_callback.ToOnceCallback(), base::DoNothing());
base::RunLoop().RunUntilIdle();
EXPECT_TRUE(mock_callback.has_run);
ExpectResponsesMatch(mock_callback, ContextualSuggestionsResult());
// The cached result we get back should be empty, since its confidence is
// below the threshold.
source()->FetchContextualSuggestionClusters(
context_url, mock_callback2.ToOnceCallback(), base::DoNothing());
EXPECT_TRUE(mock_callback2.has_run);
ExpectResponsesMatch(mock_callback2, ContextualSuggestionsResult());
}
} // namespace contextual_suggestions
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