Commit 34d4f83b authored by Michael Crouse's avatar Michael Crouse Committed by Commit Bot

Rename HintUpdateData to StoreUpdateData.

This change renames the HintUpdateData to StoreUpdateData to prepare
to add model and host model features into the store for the
optimization guide.

Future changes will add factory methods to support other objects to be
stored in the store used by the optimization guide.

Bug: 1001194
Change-Id: Idb6702ad84cbd374ed50e62c6aa904c681941df3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1873914
Commit-Queue: Michael Crouse <mcrouse@chromium.org>
Reviewed-by: default avatarDoug Arnett <dougarnett@chromium.org>
Reviewed-by: default avatarSophie Chang <sophiechang@chromium.org>
Cr-Commit-Position: refs/heads/master@{#708628}
parent b6024bb5
......@@ -231,14 +231,14 @@ void OptimizationGuideHintsManager::OnHintsComponentAvailable(
return;
}
std::unique_ptr<optimization_guide::HintUpdateData> update_data =
std::unique_ptr<optimization_guide::StoreUpdateData> update_data =
hint_cache_->MaybeCreateUpdateDataForComponentHints(info.version);
// Processes the hints from the newly available component on a background
// thread, providing a HintUpdateData for component update from the hint
// thread, providing a StoreUpdateData for component update from the hint
// cache, so that each hint within the component can be moved into it. In the
// case where the component's version is not newer than the hint cache store's
// component version, HintUpdateData will be a nullptr and hint
// component version, StoreUpdateData will be a nullptr and hint
// processing will be skipped. After PreviewsHints::Create() returns the newly
// created PreviewsHints, it is initialized in UpdateHints() on the UI thread.
base::PostTaskAndReplyWithResult(
......@@ -258,12 +258,12 @@ void OptimizationGuideHintsManager::OnHintsComponentAvailable(
}
}
std::unique_ptr<optimization_guide::HintUpdateData>
std::unique_ptr<optimization_guide::StoreUpdateData>
OptimizationGuideHintsManager::ProcessHintsComponent(
const optimization_guide::HintsComponentInfo& info,
const base::flat_set<optimization_guide::proto::OptimizationType>&
registered_optimization_types,
std::unique_ptr<optimization_guide::HintUpdateData> update_data) {
std::unique_ptr<optimization_guide::StoreUpdateData> update_data) {
DCHECK(background_task_runner_->RunsTasksInCurrentSequence());
optimization_guide::ProcessHintsComponentResult out_result;
......@@ -355,14 +355,14 @@ void OptimizationGuideHintsManager::OnHintCacheInitialized() {
std::unique_ptr<optimization_guide::proto::Configuration> manual_config =
optimization_guide::switches::ParseComponentConfigFromCommandLine();
if (manual_config) {
std::unique_ptr<optimization_guide::HintUpdateData> hint_update_data =
std::unique_ptr<optimization_guide::StoreUpdateData> update_data =
hint_cache_->MaybeCreateUpdateDataForComponentHints(
base::Version(kManualConfigComponentVersion));
optimization_guide::ProcessHints(manual_config->mutable_hints(),
hint_update_data.get());
update_data.get());
// Allow |UpdateComponentHints| to block startup so that the first
// navigation gets the hints when a command line hint proto is provided.
UpdateComponentHints(base::DoNothing(), std::move(hint_update_data));
UpdateComponentHints(base::DoNothing(), std::move(update_data));
}
// Register as an observer regardless of hint proto override usage. This is
......@@ -372,16 +372,16 @@ void OptimizationGuideHintsManager::OnHintCacheInitialized() {
void OptimizationGuideHintsManager::UpdateComponentHints(
base::OnceClosure update_closure,
std::unique_ptr<optimization_guide::HintUpdateData> hint_update_data) {
std::unique_ptr<optimization_guide::StoreUpdateData> update_data) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
// If we get here, the hints have been processed correctly.
pref_service_->ClearPref(
optimization_guide::prefs::kPendingHintsProcessingVersion);
if (hint_update_data) {
if (update_data) {
hint_cache_->UpdateComponentHints(
std::move(hint_update_data),
std::move(update_data),
base::BindOnce(&OptimizationGuideHintsManager::OnComponentHintsUpdated,
ui_weak_ptr_factory_.GetWeakPtr(),
std::move(update_closure),
......
......@@ -44,7 +44,6 @@ class SharedURLLoaderFactory;
namespace optimization_guide {
class HintCache;
class HintUpdateData;
class HintsFetcher;
enum class OptimizationGuideDecision;
class OptimizationFilter;
......@@ -53,6 +52,7 @@ class OptimizationGuideService;
enum class OptimizationTarget;
enum class OptimizationTargetDecision;
enum class OptimizationTypeDecision;
class StoreUpdateData;
class TopHostProvider;
} // namespace optimization_guide
......@@ -156,11 +156,11 @@ class OptimizationGuideHintsManager
//
// Should always be called on the thread that belongs to
// |background_task_runner_|.
std::unique_ptr<optimization_guide::HintUpdateData> ProcessHintsComponent(
std::unique_ptr<optimization_guide::StoreUpdateData> ProcessHintsComponent(
const optimization_guide::HintsComponentInfo& info,
const base::flat_set<optimization_guide::proto::OptimizationType>&
registered_optimization_types,
std::unique_ptr<optimization_guide::HintUpdateData> update_data);
std::unique_ptr<optimization_guide::StoreUpdateData> update_data);
// Processes the optimization filters contained in the hints component.
//
......@@ -180,7 +180,7 @@ class OptimizationGuideHintsManager
// Updates the cache with the latest hints sent by the Component Updater.
void UpdateComponentHints(
base::OnceClosure update_closure,
std::unique_ptr<optimization_guide::HintUpdateData> hint_update_data);
std::unique_ptr<optimization_guide::StoreUpdateData> update_data);
// Called when the hints have been fully updated with the latest hints from
// the Component Updater. This is used as a signal during tests.
......
......@@ -14,8 +14,6 @@ static_library("optimization_guide") {
"hint_cache.h",
"hint_cache_store.cc",
"hint_cache_store.h",
"hint_update_data.cc",
"hint_update_data.h",
"hints_component_info.h",
"hints_component_util.cc",
"hints_component_util.h",
......@@ -38,6 +36,8 @@ static_library("optimization_guide") {
"optimization_guide_service_observer.h",
"optimization_guide_switches.cc",
"optimization_guide_switches.h",
"store_update_data.cc",
"store_update_data.h",
"top_host_provider.h",
"url_pattern_with_wildcards.cc",
"url_pattern_with_wildcards.h",
......@@ -85,7 +85,6 @@ source_set("unit_tests") {
"command_line_top_host_provider_unittest.cc",
"hint_cache_store_unittest.cc",
"hint_cache_unittest.cc",
"hint_update_data_unittest.cc",
"hints_component_util_unittest.cc",
"hints_fetcher_unittest.cc",
"hints_processing_util_unittest.cc",
......@@ -93,6 +92,7 @@ source_set("unit_tests") {
"optimization_guide_features_unittest.cc",
"optimization_guide_service_unittest.cc",
"optimization_guide_switches_unittest.cc",
"store_update_data_unittest.cc",
"url_pattern_with_wildcards_unittest.cc",
]
......
......@@ -7,9 +7,9 @@
#include <algorithm>
#include "base/bind.h"
#include "components/optimization_guide/hint_update_data.h"
#include "components/optimization_guide/hints_processing_util.h"
#include "components/optimization_guide/optimization_guide_features.h"
#include "components/optimization_guide/store_update_data.h"
#include "url/gurl.h"
namespace optimization_guide {
......@@ -43,14 +43,14 @@ void HintCache::Initialize(bool purge_existing_data,
std::move(callback)));
}
std::unique_ptr<HintUpdateData>
std::unique_ptr<StoreUpdateData>
HintCache::MaybeCreateUpdateDataForComponentHints(
const base::Version& version) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
return hint_store_->MaybeCreateUpdateDataForComponentHints(version);
}
std::unique_ptr<HintUpdateData> HintCache::CreateUpdateDataForFetchedHints(
std::unique_ptr<StoreUpdateData> HintCache::CreateUpdateDataForFetchedHints(
base::Time update_time,
base::Time expiry_time) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......@@ -58,7 +58,7 @@ std::unique_ptr<HintUpdateData> HintCache::CreateUpdateDataForFetchedHints(
}
void HintCache::UpdateComponentHints(
std::unique_ptr<HintUpdateData> component_data,
std::unique_ptr<StoreUpdateData> component_data,
base::OnceClosure callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(component_data);
......@@ -82,7 +82,7 @@ void HintCache::UpdateFetchedHints(
} else {
expiry_time += features::StoredFetchedHintsFreshnessDuration();
}
std::unique_ptr<HintUpdateData> fetched_hints_update_data =
std::unique_ptr<StoreUpdateData> fetched_hints_update_data =
CreateUpdateDataForFetchedHints(update_time, expiry_time);
ProcessHints(get_hints_response.get()->mutable_hints(),
fetched_hints_update_data.get());
......
......@@ -16,7 +16,7 @@
#include "components/optimization_guide/proto/hints.pb.h"
namespace optimization_guide {
class HintUpdateData;
class StoreUpdateData;
using HintLoadedCallback = base::OnceCallback<void(const proto::Hint*)>;
......@@ -42,13 +42,13 @@ class HintCache {
// pre-existing data and begin in a clean state.
void Initialize(bool purge_existing_data, base::OnceClosure callback);
// Returns a HintUpdateData. During component processing, hints from the
// component are moved into the HintUpdateData. After component
// Returns a StoreUpdateData. During component processing, hints from the
// component are moved into the StoreUpdateData. After component
// processing completes, the component update data is provided to the backing
// store in UpdateComponentHints() and used to update its component hints. In
// the case the provided component version is not newer than the store's
// version, nullptr will be returned by the call.
std::unique_ptr<HintUpdateData> MaybeCreateUpdateDataForComponentHints(
std::unique_ptr<StoreUpdateData> MaybeCreateUpdateDataForComponentHints(
const base::Version& version) const;
// Returns an UpdateData created by the store to hold updates for fetched
......@@ -59,13 +59,13 @@ class HintCache {
// created update data will be scheduled to be updated. |expiry_time|
// specifies when the hints within the created update data will be expired
// from the store.
std::unique_ptr<HintUpdateData> CreateUpdateDataForFetchedHints(
std::unique_ptr<StoreUpdateData> CreateUpdateDataForFetchedHints(
base::Time update_time,
base::Time expiry_time) const;
// Updates the store's component data using the provided HintUpdateData
// Updates the store's component data using the provided StoreUpdateData
// and asynchronously runs the provided callback after the update finishes.
void UpdateComponentHints(std::unique_ptr<HintUpdateData> component_data,
void UpdateComponentHints(std::unique_ptr<StoreUpdateData> component_data,
base::OnceClosure callback);
// Process |get_hints_response| to be stored in the hint cache store.
......
......@@ -138,7 +138,7 @@ void HintCacheStore::Initialize(bool purge_existing_data,
purge_existing_data, std::move(callback)));
}
std::unique_ptr<HintUpdateData>
std::unique_ptr<StoreUpdateData>
HintCacheStore::MaybeCreateUpdateDataForComponentHints(
const base::Version& version) const {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......@@ -154,24 +154,25 @@ HintCacheStore::MaybeCreateUpdateDataForComponentHints(
return nullptr;
}
// Create and return a HintUpdateData object. This object has
// Create and return a StoreUpdateData object. This object has
// hints from the component moved into it and organizes them in a format
// usable by the store; the object will returned to the store in
// StoreComponentHints().
return HintUpdateData::CreateComponentHintUpdateData(version);
return StoreUpdateData::CreateComponentStoreUpdateData(version);
}
std::unique_ptr<HintUpdateData> HintCacheStore::CreateUpdateDataForFetchedHints(
base::Time update_time,
base::Time expiry_time) const {
// Create and returns a HintUpdateData object. This object has has hints
std::unique_ptr<StoreUpdateData>
HintCacheStore::CreateUpdateDataForFetchedHints(base::Time update_time,
base::Time expiry_time) const {
// Create and returns a StoreUpdateData object. This object has has hints
// from the GetHintsResponse moved into and organizes them in a format
// usable by the store. The object will be store with UpdateFetchedData().
return HintUpdateData::CreateFetchedHintUpdateData(update_time, expiry_time);
return StoreUpdateData::CreateFetchedStoreUpdateData(update_time,
expiry_time);
}
void HintCacheStore::UpdateComponentHints(
std::unique_ptr<HintUpdateData> component_data,
std::unique_ptr<StoreUpdateData> component_data,
base::OnceClosure callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(component_data);
......@@ -229,7 +230,7 @@ void HintCacheStore::UpdateComponentHints(
}
void HintCacheStore::UpdateFetchedHints(
std::unique_ptr<HintUpdateData> fetched_hints_data,
std::unique_ptr<StoreUpdateData> fetched_hints_data,
base::OnceClosure callback) {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
DCHECK(fetched_hints_data);
......
......@@ -18,7 +18,7 @@
#include "base/version.h"
#include "components/leveldb_proto/public/proto_database.h"
#include "components/leveldb_proto/public/proto_database_provider.h"
#include "components/optimization_guide/hint_update_data.h"
#include "components/optimization_guide/store_update_data.h"
namespace base {
class SequencedTaskRunner;
......@@ -97,15 +97,15 @@ class HintCacheStore {
// When initialization completes, the provided callback is run asynchronously.
void Initialize(bool purge_existing_data, base::OnceClosure callback);
// Creates and returns a HintUpdateData object for component hints. This
// Creates and returns a StoreUpdateData object for component hints. This
// object is used to collect hints within a component in a format usable on a
// background thread and is later returned to the store in
// UpdateComponentHints(). The HintUpdateData object is only created when the
// UpdateComponentHints(). The StoreUpdateData object is only created when the
// provided component version is newer than the store's version, indicating
// fresh hints. If the component's version is not newer than the store's
// version, then no HintUpdateData is created and nullptr is returned. This
// version, then no StoreUpdateData is created and nullptr is returned. This
// prevents unnecessary processing of the component's hints by the caller.
std::unique_ptr<HintUpdateData> MaybeCreateUpdateDataForComponentHints(
std::unique_ptr<StoreUpdateData> MaybeCreateUpdateDataForComponentHints(
const base::Version& version) const;
// Creates and returns a HintsUpdateData object for Fetched Hints.
......@@ -114,7 +114,7 @@ class HintCacheStore {
// hints have been successfully fetched from the remote Optimization Guide
// Service so the store can expire old hints, remove hints specified by the
// server, and store the fresh hints.
std::unique_ptr<HintUpdateData> CreateUpdateDataForFetchedHints(
std::unique_ptr<StoreUpdateData> CreateUpdateDataForFetchedHints(
base::Time update_time,
base::Time expiry_time) const;
......@@ -122,13 +122,13 @@ class HintCacheStore {
// this is called, all pre-existing component hints within the store is purged
// and only the new hints are retained. After the store is fully updated with
// the new component hints, the callback is run asynchronously.
void UpdateComponentHints(std::unique_ptr<HintUpdateData> component_data,
void UpdateComponentHints(std::unique_ptr<StoreUpdateData> component_data,
base::OnceClosure callback);
// Updates the fetched hints contained in the store, including the
// metadata entry. The callback is run asynchronously after the database
// stores the hints.
void UpdateFetchedHints(std::unique_ptr<HintUpdateData> fetched_hints_data,
void UpdateFetchedHints(std::unique_ptr<StoreUpdateData> fetched_hints_data,
base::OnceClosure callback);
// Removes fetched hint store entries from |this|. |hint_entry_keys_| is
......@@ -160,7 +160,7 @@ class HintCacheStore {
private:
friend class HintCacheStoreTest;
friend class HintUpdateData;
friend class StoreUpdateData;
using EntryKeyPrefix = std::string;
using EntryKeySet = base::flat_set<EntryKey>;
......
......@@ -77,7 +77,7 @@ class HintCacheTest : public ProtoDatabaseProviderTestBase {
// Updates the cache with |component_data| and waits for callback indicating
// that the update is complete.
void UpdateComponentHints(std::unique_ptr<HintUpdateData> component_data) {
void UpdateComponentHints(std::unique_ptr<StoreUpdateData> component_data) {
are_component_hints_updated_ = false;
hint_cache_->UpdateComponentHints(
std::move(component_data),
......@@ -147,7 +147,7 @@ TEST_F(HintCacheTest, ComponentUpdate) {
CreateAndInitializeHintCache(kMemoryCacheSize);
base::Version version("2.0.0");
std::unique_ptr<HintUpdateData> update_data =
std::unique_ptr<StoreUpdateData> update_data =
hint_cache()->MaybeCreateUpdateDataForComponentHints(version);
ASSERT_TRUE(update_data);
......@@ -182,7 +182,7 @@ TEST_F(HintCacheTest, ComponentUpdateWithSameVersionIgnored) {
CreateAndInitializeHintCache(kMemoryCacheSize);
base::Version version("2.0.0");
std::unique_ptr<HintUpdateData> update_data =
std::unique_ptr<StoreUpdateData> update_data =
hint_cache()->MaybeCreateUpdateDataForComponentHints(version);
ASSERT_TRUE(update_data);
......@@ -198,7 +198,7 @@ TEST_F(HintCacheTest, ComponentUpdateWithEarlierVersionIgnored) {
base::Version version_1("1.0.0");
base::Version version_2("2.0.0");
std::unique_ptr<HintUpdateData> update_data =
std::unique_ptr<StoreUpdateData> update_data =
hint_cache()->MaybeCreateUpdateDataForComponentHints(version_2);
ASSERT_TRUE(update_data);
......@@ -214,7 +214,7 @@ TEST_F(HintCacheTest, ComponentUpdateWithLaterVersionProcessed) {
base::Version version_1("1.0.0");
base::Version version_2("2.0.0");
std::unique_ptr<HintUpdateData> update_data_1 =
std::unique_ptr<StoreUpdateData> update_data_1 =
hint_cache()->MaybeCreateUpdateDataForComponentHints(version_1);
ASSERT_TRUE(update_data_1);
......@@ -243,7 +243,7 @@ TEST_F(HintCacheTest, ComponentUpdateWithLaterVersionProcessed) {
EXPECT_TRUE(hint_cache()->HasHint("host.subdomain.domain.org"));
EXPECT_TRUE(hint_cache()->HasHint("subhost.host.subdomain.domain.org"));
std::unique_ptr<HintUpdateData> update_data_2 =
std::unique_ptr<StoreUpdateData> update_data_2 =
hint_cache()->MaybeCreateUpdateDataForComponentHints(version_2);
ASSERT_TRUE(update_data_2);
......@@ -284,7 +284,7 @@ TEST_F(HintCacheTest, ComponentHintsAvailableAfterRestart) {
base::Version version("2.0.0");
std::unique_ptr<HintUpdateData> update_data =
std::unique_ptr<StoreUpdateData> update_data =
hint_cache()->MaybeCreateUpdateDataForComponentHints(version);
if (i == 0) {
ASSERT_TRUE(update_data);
......@@ -329,7 +329,7 @@ TEST_F(HintCacheTest, ComponentHintsUpdatableAfterRestartWithPurge) {
base::Version version("2.0.0");
std::unique_ptr<HintUpdateData> update_data =
std::unique_ptr<StoreUpdateData> update_data =
hint_cache()->MaybeCreateUpdateDataForComponentHints(version);
ASSERT_TRUE(update_data);
......@@ -370,7 +370,7 @@ TEST_F(HintCacheTest, ComponentHintsNotRetainedAfterRestartWithPurge) {
base::Version version("2.0.0");
std::unique_ptr<HintUpdateData> update_data =
std::unique_ptr<StoreUpdateData> update_data =
hint_cache()->MaybeCreateUpdateDataForComponentHints(version);
if (i == 0) {
ASSERT_TRUE(update_data);
......@@ -416,7 +416,7 @@ TEST_F(HintCacheTest, TestMemoryCacheLeastRecentlyUsedPurge) {
CreateAndInitializeHintCache(kMemoryCacheSize);
base::Version version("1.0.0");
std::unique_ptr<HintUpdateData> update_data =
std::unique_ptr<StoreUpdateData> update_data =
hint_cache()->MaybeCreateUpdateDataForComponentHints(version);
ASSERT_TRUE(update_data);
......@@ -456,7 +456,7 @@ TEST_F(HintCacheTest, TestHostNotInCache) {
CreateAndInitializeHintCache(kMemoryCacheSize);
base::Version version("1.0.0");
std::unique_ptr<HintUpdateData> update_data =
std::unique_ptr<StoreUpdateData> update_data =
hint_cache()->MaybeCreateUpdateDataForComponentHints(version);
ASSERT_TRUE(update_data);
......@@ -477,7 +477,7 @@ TEST_F(HintCacheTest, TestMemoryCacheLoadCallback) {
CreateAndInitializeHintCache(kMemoryCacheSize);
base::Version version("1.0.0");
std::unique_ptr<HintUpdateData> update_data =
std::unique_ptr<StoreUpdateData> update_data =
hint_cache()->MaybeCreateUpdateDataForComponentHints(version);
ASSERT_TRUE(update_data);
......
......@@ -9,8 +9,8 @@
#include "base/containers/flat_set.h"
#include "base/metrics/field_trial_params.h"
#include "base/strings/stringprintf.h"
#include "components/optimization_guide/hint_update_data.h"
#include "components/optimization_guide/optimization_guide_features.h"
#include "components/optimization_guide/store_update_data.h"
#include "components/optimization_guide/url_pattern_with_wildcards.h"
#include "url/gurl.h"
......@@ -86,9 +86,9 @@ std::string HashHostForDictionary(const std::string& host) {
}
bool ProcessHints(google::protobuf::RepeatedPtrField<proto::Hint>* hints,
optimization_guide::HintUpdateData* hint_update_data) {
optimization_guide::StoreUpdateData* update_data) {
// If there's no update data, then there's nothing to do.
if (!hint_update_data)
if (!update_data)
return false;
base::flat_set<std::string> seen_host_suffixes;
......@@ -126,7 +126,7 @@ bool ProcessHints(google::protobuf::RepeatedPtrField<proto::Hint>* hints,
// data.
// WARNING: Do not use |hint| after this call. Its contents will no
// longer be valid.
hint_update_data->MoveHintIntoUpdateData(std::move(hint));
update_data->MoveHintIntoUpdateData(std::move(hint));
did_process_hints = true;
}
}
......
......@@ -13,7 +13,7 @@
class GURL;
namespace optimization_guide {
class HintUpdateData;
class StoreUpdateData;
// Returns the string representation of the optimization type.
std::string GetStringNameForOptimizationType(
......@@ -42,11 +42,11 @@ const proto::PageHint* FindPageHintForURL(const GURL& gurl,
std::string HashHostForDictionary(const std::string& host);
// Verifies and processes |hints| and places the ones it supports into
// |hint_update_data|.
// |update_data|.
//
// Returns true if there was at least one hint moved into |hint_update_data|.
// Returns true if there was at least one hint moved into |update_data|.
bool ProcessHints(google::protobuf::RepeatedPtrField<proto::Hint>* hints,
HintUpdateData* hint_update_data);
StoreUpdateData* update_data);
// Converts |proto_ect| into a net::EffectiveConnectionType.
net::EffectiveConnectionType ConvertProtoEffectiveConnectionType(
......
......@@ -4,9 +4,9 @@
#include "components/optimization_guide/hints_processing_util.h"
#include "components/optimization_guide/hint_update_data.h"
#include "components/optimization_guide/proto/hint_cache.pb.h"
#include "components/optimization_guide/proto/hints.pb.h"
#include "components/optimization_guide/store_update_data.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
......@@ -79,8 +79,8 @@ TEST(HintsProcessingUtilTest, ProcessHintsWithNoPageHintsAndUpdateData) {
google::protobuf::RepeatedPtrField<proto::Hint> hints;
*(hints.Add()) = hint;
std::unique_ptr<HintUpdateData> update_data =
HintUpdateData::CreateComponentHintUpdateData(base::Version("1.0.0"));
std::unique_ptr<StoreUpdateData> update_data =
StoreUpdateData::CreateComponentStoreUpdateData(base::Version("1.0.0"));
EXPECT_FALSE(ProcessHints(&hints, update_data.get()));
// Verify there is 1 store entries: 1 for the metadata entry.
EXPECT_EQ(1ul, update_data->TakeUpdateEntries()->size());
......@@ -107,8 +107,8 @@ TEST(HintsProcessingUtilTest, ProcessHintsWithPageHintsAndUpdateData) {
no_page_hints_hint.set_key_representation(proto::HOST_SUFFIX);
*(hints.Add()) = no_page_hints_hint;
std::unique_ptr<HintUpdateData> update_data =
HintUpdateData::CreateComponentHintUpdateData(base::Version("1.0.0"));
std::unique_ptr<StoreUpdateData> update_data =
StoreUpdateData::CreateComponentStoreUpdateData(base::Version("1.0.0"));
EXPECT_TRUE(ProcessHints(&hints, update_data.get()));
// Verify there are 2 store entries: 1 for the metadata entry plus
// the 1 added hint entries.
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/optimization_guide/hint_update_data.h"
#include "components/optimization_guide/store_update_data.h"
#include "components/optimization_guide/hint_cache_store.h"
#include "components/optimization_guide/proto/hint_cache.pb.h"
......@@ -11,28 +11,30 @@
namespace optimization_guide {
// static
std::unique_ptr<HintUpdateData> HintUpdateData::CreateComponentHintUpdateData(
std::unique_ptr<StoreUpdateData>
StoreUpdateData::CreateComponentStoreUpdateData(
const base::Version& component_version) {
std::unique_ptr<HintUpdateData> update_data(new HintUpdateData(
std::unique_ptr<StoreUpdateData> update_data(new StoreUpdateData(
base::Optional<base::Version>(component_version),
base::Optional<base::Time>(), base::Optional<base::Time>()));
return update_data;
}
// static
std::unique_ptr<HintUpdateData> HintUpdateData::CreateFetchedHintUpdateData(
std::unique_ptr<StoreUpdateData> StoreUpdateData::CreateFetchedStoreUpdateData(
base::Time fetch_update_time,
base::Time expiry_time) {
std::unique_ptr<HintUpdateData> update_data(
new HintUpdateData(base::Optional<base::Version>(),
base::Optional<base::Time>(fetch_update_time),
base::Optional<base::Time>(expiry_time)));
std::unique_ptr<StoreUpdateData> update_data(
new StoreUpdateData(base::Optional<base::Version>(),
base::Optional<base::Time>(fetch_update_time),
base::Optional<base::Time>(expiry_time)));
return update_data;
}
HintUpdateData::HintUpdateData(base::Optional<base::Version> component_version,
base::Optional<base::Time> fetch_update_time,
base::Optional<base::Time> expiry_time)
StoreUpdateData::StoreUpdateData(
base::Optional<base::Version> component_version,
base::Optional<base::Time> fetch_update_time,
base::Optional<base::Time> expiry_time)
: component_version_(component_version),
fetch_update_time_(fetch_update_time),
expiry_time_(expiry_time),
......@@ -72,9 +74,9 @@ HintUpdateData::HintUpdateData(base::Optional<base::Version> component_version,
DETACH_FROM_SEQUENCE(sequence_checker_);
}
HintUpdateData::~HintUpdateData() {}
StoreUpdateData::~StoreUpdateData() {}
void HintUpdateData::MoveHintIntoUpdateData(proto::Hint&& hint) {
void StoreUpdateData::MoveHintIntoUpdateData(proto::Hint&& hint) {
// All future modifications must be made by the same thread. Note, |this| may
// have been constructed on another thread.
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
......@@ -98,7 +100,7 @@ void HintUpdateData::MoveHintIntoUpdateData(proto::Hint&& hint) {
std::move(entry_proto));
}
std::unique_ptr<EntryVector> HintUpdateData::TakeUpdateEntries() {
std::unique_ptr<EntryVector> StoreUpdateData::TakeUpdateEntries() {
// TakeUpdateEntries is not be sequence checked as it only gives up ownership
// of the entries_to_save_ and does not modify any state.
DCHECK(entries_to_save_);
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_OPTIMIZATION_GUIDE_HINT_UPDATE_DATA_H_
#define COMPONENTS_OPTIMIZATION_GUIDE_HINT_UPDATE_DATA_H_
#ifndef COMPONENTS_OPTIMIZATION_GUIDE_STORE_UPDATE_DATA_H_
#define COMPONENTS_OPTIMIZATION_GUIDE_STORE_UPDATE_DATA_H_
#include <string>
......@@ -24,16 +24,16 @@ using EntryVector =
leveldb_proto::ProtoDatabase<proto::StoreEntry>::KeyEntryVector;
// Holds hint data for updating the HintCacheStore.
class HintUpdateData {
class StoreUpdateData {
public:
~HintUpdateData();
~StoreUpdateData();
// Creates an update data object for a component hint update.
static std::unique_ptr<HintUpdateData> CreateComponentHintUpdateData(
static std::unique_ptr<StoreUpdateData> CreateComponentStoreUpdateData(
const base::Version& component_version);
// Creates an update data object for a fetched hint update.
static std::unique_ptr<HintUpdateData> CreateFetchedHintUpdateData(
static std::unique_ptr<StoreUpdateData> CreateFetchedStoreUpdateData(
base::Time fetch_update_time,
base::Time expiry_time);
......@@ -58,9 +58,9 @@ class HintUpdateData {
std::unique_ptr<EntryVector> TakeUpdateEntries();
private:
HintUpdateData(base::Optional<base::Version> component_version,
base::Optional<base::Time> fetch_update_time,
base::Optional<base::Time> expiry_time);
StoreUpdateData(base::Optional<base::Version> component_version,
base::Optional<base::Time> fetch_update_time,
base::Optional<base::Time> expiry_time);
// The component version of the update data for a component update.
base::Optional<base::Version> component_version_;
......@@ -80,9 +80,9 @@ class HintUpdateData {
SEQUENCE_CHECKER(sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(HintUpdateData);
DISALLOW_COPY_AND_ASSIGN(StoreUpdateData);
};
} // namespace optimization_guide
#endif // COMPONENTS_OPTIMIZATION_GUIDE_HINT_UPDATE_DATA_H_
#endif // COMPONENTS_OPTIMIZATION_GUIDE_STORE_UPDATE_DATA_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/optimization_guide/hint_update_data.h"
#include "components/optimization_guide/store_update_data.h"
#include <string>
#include <vector>
......@@ -19,7 +19,7 @@ namespace optimization_guide {
namespace {
TEST(HintUpdateDataTest, BuildComponentHintUpdateData) {
TEST(StoreUpdateDataTest, BuildComponentStoreUpdateData) {
// Verify creating a Component Hint update package.
base::Version v1("1.2.3.4");
proto::Hint hint1;
......@@ -33,8 +33,8 @@ TEST(HintUpdateDataTest, BuildComponentHintUpdateData) {
proto::PageHint* page_hint2 = hint2.add_page_hints();
page_hint2->set_page_pattern("slowpagealso");
std::unique_ptr<HintUpdateData> component_update =
HintUpdateData::CreateComponentHintUpdateData(v1);
std::unique_ptr<StoreUpdateData> component_update =
StoreUpdateData::CreateComponentStoreUpdateData(v1);
component_update->MoveHintIntoUpdateData(std::move(hint1));
component_update->MoveHintIntoUpdateData(std::move(hint2));
EXPECT_TRUE(component_update->component_version().has_value());
......@@ -45,7 +45,7 @@ TEST(HintUpdateDataTest, BuildComponentHintUpdateData) {
EXPECT_EQ(3ul, component_update->TakeUpdateEntries()->size());
}
TEST(HintUpdateDataTest, BuildFetchUpdateData) {
TEST(StoreUpdateDataTest, BuildFetchUpdateData) {
// Verify creating a Fetched Hint update package.
base::Time update_time = base::Time::Now();
proto::Hint hint1;
......@@ -54,8 +54,8 @@ TEST(HintUpdateDataTest, BuildFetchUpdateData) {
proto::PageHint* page_hint1 = hint1.add_page_hints();
page_hint1->set_page_pattern("slowpage");
std::unique_ptr<HintUpdateData> fetch_update =
HintUpdateData::CreateFetchedHintUpdateData(
std::unique_ptr<StoreUpdateData> fetch_update =
StoreUpdateData::CreateFetchedStoreUpdateData(
update_time, update_time + optimization_guide::features::
StoredFetchedHintsFreshnessDuration());
fetch_update->MoveHintIntoUpdateData(std::move(hint1));
......
......@@ -14,10 +14,10 @@
#include "base/optional.h"
#include "base/strings/stringprintf.h"
#include "components/optimization_guide/bloom_filter.h"
#include "components/optimization_guide/hint_update_data.h"
#include "components/optimization_guide/hints_component_info.h"
#include "components/optimization_guide/hints_component_util.h"
#include "components/optimization_guide/hints_processing_util.h"
#include "components/optimization_guide/store_update_data.h"
#include "components/previews/core/previews_features.h"
#include "url/gurl.h"
......@@ -126,7 +126,7 @@ bool IsEnabledOptimizationType(
} // namespace
PreviewsHints::PreviewsHints(
std::unique_ptr<optimization_guide::HintUpdateData> component_update_data)
std::unique_ptr<optimization_guide::StoreUpdateData> component_update_data)
: hint_cache_(nullptr),
component_update_data_(std::move(component_update_data)) {
DETACH_FROM_SEQUENCE(sequence_checker_);
......@@ -139,7 +139,8 @@ PreviewsHints::~PreviewsHints() {
// static
std::unique_ptr<PreviewsHints> PreviewsHints::CreateFromHintsComponent(
const optimization_guide::HintsComponentInfo& info,
std::unique_ptr<optimization_guide::HintUpdateData> component_update_data) {
std::unique_ptr<optimization_guide::StoreUpdateData>
component_update_data) {
optimization_guide::ProcessHintsComponentResult result;
std::unique_ptr<optimization_guide::proto::Configuration> config =
ProcessHintsComponent(info, &result);
......@@ -167,7 +168,8 @@ std::unique_ptr<PreviewsHints> PreviewsHints::CreateFromHintsComponent(
// static
std::unique_ptr<PreviewsHints> PreviewsHints::CreateFromHintsConfiguration(
std::unique_ptr<optimization_guide::proto::Configuration> config,
std::unique_ptr<optimization_guide::HintUpdateData> component_update_data) {
std::unique_ptr<optimization_guide::StoreUpdateData>
component_update_data) {
optimization_guide::ProcessHintsComponentResult process_hints_result =
optimization_guide::ProcessHintsComponentResult::kSkippedProcessingHints;
if (component_update_data) {
......
......@@ -39,7 +39,7 @@ class PreviewsHints {
// processing.
static std::unique_ptr<PreviewsHints> CreateFromHintsComponent(
const optimization_guide::HintsComponentInfo& info,
std::unique_ptr<optimization_guide::HintUpdateData>
std::unique_ptr<optimization_guide::StoreUpdateData>
component_update_data);
// Creates a Hints instance from the provided hints configuration. This must
......@@ -47,7 +47,7 @@ class PreviewsHints {
// amount of processing.
static std::unique_ptr<PreviewsHints> CreateFromHintsConfiguration(
std::unique_ptr<optimization_guide::proto::Configuration> config,
std::unique_ptr<optimization_guide::HintUpdateData>
std::unique_ptr<optimization_guide::StoreUpdateData>
component_update_data);
// Set |hint_cache_| and updates the hint cache's component data if
......@@ -93,8 +93,8 @@ class PreviewsHints {
friend class PreviewsHintsTest;
// Constructs PreviewsHints with |component_update_data|. This
// HintUpdateData is later moved into the HintCache during Initialize().
PreviewsHints(std::unique_ptr<optimization_guide::HintUpdateData>
// StoreUpdateData is later moved into the HintCache during Initialize().
PreviewsHints(std::unique_ptr<optimization_guide::StoreUpdateData>
component_update_data);
// Parses optimization filters from |config| and populates corresponding
......@@ -106,10 +106,10 @@ class PreviewsHints {
// guide, which is guaranteed to outlive PreviewsHints.
optimization_guide::HintCache* hint_cache_;
// HintUpdateData provided by the HintCache and populated during
// StoreUpdateData provided by the HintCache and populated during
// PreviewsHints::Create(). |component_update_data_| is set during
// construction and moved into the HintCache during Initialize().
std::unique_ptr<optimization_guide::HintUpdateData> component_update_data_;
std::unique_ptr<optimization_guide::StoreUpdateData> component_update_data_;
// Blacklist of host suffixes for LITE_PAGE_REDIRECT Previews.
std::unique_ptr<optimization_guide::OptimizationFilter>
......
......@@ -18,12 +18,12 @@
#include "components/optimization_guide/bloom_filter.h"
#include "components/optimization_guide/hint_cache.h"
#include "components/optimization_guide/hint_cache_store.h"
#include "components/optimization_guide/hint_update_data.h"
#include "components/optimization_guide/hints_component_info.h"
#include "components/optimization_guide/hints_component_util.h"
#include "components/optimization_guide/optimization_guide_features.h"
#include "components/optimization_guide/proto/hints.pb.h"
#include "components/optimization_guide/proto_database_provider_test_base.h"
#include "components/optimization_guide/store_update_data.h"
#include "components/previews/core/previews_features.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "url/gurl.h"
......
......@@ -243,10 +243,10 @@ void PreviewsOptimizationGuideImpl::OnHintsComponentAvailable(
}
// Create PreviewsHints from the newly available component on a background
// thread, providing a HintUpdateData for component update from the hint
// thread, providing a StoreUpdateData for component update from the hint
// cache, so that each hint within the component can be moved into it. In the
// case where the component's version is not newer than the hint cache store's
// component version, HintUpdateData will be a nullptr and hint
// component version, StoreUpdateData will be a nullptr and hint
// processing will be skipped. After PreviewsHints::Create() returns the newly
// created PreviewsHints, it is initialized in UpdateHints() on the UI thread.
base::PostTaskAndReplyWithResult(
......
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