#include "components/feed/core/v2/feed_store.h"
#include <string_view>
#include <utility>
#include "base/containers/flat_set.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/notreached.h"
#include "base/strings/strcat.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/task/thread_pool.h"
#include "components/feed/core/proto/v2/store.pb.h"
#include "components/feed/core/v2/feedstore_util.h"
#include "components/feed/core/v2/protocol_translator.h"
#include "components/feed/core/v2/public/stream_type.h"
#include "components/leveldb_proto/public/proto_database_provider.h"
namespace feed {
namespace {
constexpr char kLocalActionPrefix[] = …;
constexpr char kMetadataKey[] = …;
constexpr char kSubscribedFeedsKey[] = …;
constexpr char kRecommendedIndexKey[] = …;
constexpr char kPendingWebFeedOperationPrefix[] = …;
constexpr char kStreamDataPrefix[] = …;
constexpr char kkSingleWebFeedStreamDataPrefix[] = …;
leveldb::ReadOptions CreateReadOptions() { … }
#define CONTENT_ID_STRING_PARTS(content_id) …
std::string StreamDataKey(const std::string_view stream_key) { … }
std::string StreamDataKey(const StreamType& stream_type) { … }
std::string ContentKey(const std::string_view stream_type,
const feedwire::ContentId& content_id) { … }
std::string ContentKey(const StreamType& stream_type,
const feedwire::ContentId& content_id) { … }
std::string SharedStateKey(const std::string_view stream_type,
const feedwire::ContentId& content_id) { … }
std::string SharedStateKey(const StreamType& stream_type,
const feedwire::ContentId& content_id) { … }
std::string LocalActionKey(int64_t id) { … }
std::string LocalActionKey(const LocalActionId& id) { … }
std::string DocViewKey(const feedstore::DocView& doc_view) { … }
bool IsAnyStreamRecordKey(const std::string& key) { … }
class StreamKeyMatcher { … };
class StreamPrefixMatcher { … };
bool IsLocalActionKey(const std::string& key) { … }
std::string KeyForRecord(const feedstore::Record& record) { … }
bool FilterByKey(const base::flat_set<std::string>& key_set,
const std::string& key) { … }
feedstore::Record MakeRecord(feedstore::Content content) { … }
feedstore::Record MakeRecord(
feedstore::StreamStructureSet stream_structure_set) { … }
feedstore::Record MakeRecord(feedstore::StreamSharedState shared_state) { … }
feedstore::Record MakeRecord(feedstore::StreamData stream_data) { … }
feedstore::Record MakeRecord(feedstore::StoredAction action) { … }
feedstore::Record MakeRecord(feedstore::Metadata metadata) { … }
feedstore::Record MakeRecord(feedstore::RecommendedWebFeedIndex index) { … }
feedstore::Record MakeRecord(
feedstore::SubscribedWebFeeds subscribed_web_feeds) { … }
feedstore::Record MakeRecord(feedstore::WebFeedInfo web_feed_info) { … }
feedstore::Record MakeRecord(feedstore::PendingWebFeedOperation operation) { … }
feedstore::Record MakeRecord(feedstore::DocView doc_view) { … }
template <typename T>
std::pair<std::string, feedstore::Record> MakeKeyAndRecord(T record_data) { … }
std::unique_ptr<std::vector<std::pair<std::string, feedstore::Record>>>
MakeUpdatesForStreamModelUpdateRequest(
int32_t structure_set_sequence_number,
const StreamType& stream_type,
std::unique_ptr<StreamModelUpdateRequest> update_request) { … }
void SortActions(std::vector<feedstore::StoredAction>* actions) { … }
base::OnceCallback<void(bool)> DropBoolParam(base::OnceClosure callback) { … }
}
FeedStore::LoadStreamResult::LoadStreamResult() = default;
FeedStore::LoadStreamResult::~LoadStreamResult() = default;
FeedStore::LoadStreamResult::LoadStreamResult(LoadStreamResult&&) = default;
FeedStore::LoadStreamResult& FeedStore::LoadStreamResult::operator=(
LoadStreamResult&&) = default;
FeedStore::StartupData::StartupData() = default;
FeedStore::StartupData::StartupData(StartupData&&) = default;
FeedStore::StartupData::~StartupData() = default;
FeedStore::StartupData& FeedStore::StartupData::operator=(StartupData&&) =
default;
FeedStore::WebFeedStartupData::WebFeedStartupData() = default;
FeedStore::WebFeedStartupData::WebFeedStartupData(WebFeedStartupData&&) =
default;
FeedStore::WebFeedStartupData::~WebFeedStartupData() = default;
FeedStore::WebFeedStartupData& FeedStore::WebFeedStartupData::operator=(
WebFeedStartupData&&) = default;
FeedStore::FeedStore(
std::unique_ptr<leveldb_proto::ProtoDatabase<feedstore::Record>> database)
: … { … }
FeedStore::~FeedStore() = default;
void FeedStore::Initialize(base::OnceClosure initialize_complete) { … }
void FeedStore::OnDatabaseInitialized(leveldb_proto::Enums::InitStatus status) { … }
bool FeedStore::IsInitialized() const { … }
bool FeedStore::IsInitializedForTesting() const { … }
void FeedStore::ReadSingle(
const std::string& key,
base::OnceCallback<void(bool, std::unique_ptr<feedstore::Record>)>
callback) { … }
void FeedStore::ReadMany(
const base::flat_set<std::string>& key_set,
base::OnceCallback<
void(bool, std::unique_ptr<std::vector<feedstore::Record>>)> callback) { … }
void FeedStore::ClearAll(base::OnceCallback<void(bool)> callback) { … }
void FeedStore::LoadStream(
const StreamType& stream_type,
base::OnceCallback<void(LoadStreamResult)> callback) { … }
void FeedStore::OnLoadStreamFinished(
const StreamType& stream_type,
base::OnceCallback<void(LoadStreamResult)> callback,
bool success,
std::unique_ptr<std::vector<feedstore::Record>> records) { … }
void FeedStore::OverwriteStream(
const StreamType& stream_type,
std::unique_ptr<StreamModelUpdateRequest> update_request,
base::OnceCallback<void(bool)> callback) { … }
void FeedStore::UpdateFullStreamData(
const StreamType& stream_type,
std::unique_ptr<std::vector<std::pair<std::string, feedstore::Record>>>
updates,
base::OnceCallback<void(bool)> callback) { … }
void FeedStore::SaveStreamUpdate(
const StreamType& stream_type,
int32_t structure_set_sequence_number,
std::unique_ptr<StreamModelUpdateRequest> update_request,
base::OnceCallback<void(bool)> callback) { … }
void FeedStore::ClearStreamData(const StreamType& stream_type,
base::OnceCallback<void(bool)> callback) { … }
void FeedStore::ClearAllStreamData(StreamKind stream_kind,
base::OnceCallback<void(bool)> callback) { … }
void FeedStore::OnSaveStreamEntriesUpdated(
base::OnceCallback<void(bool)> complete_callback,
bool ok) { … }
void FeedStore::WriteOperations(
const StreamType& stream_type,
int32_t sequence_number,
std::vector<feedstore::DataOperation> operations) { … }
void FeedStore::ReadContent(
const StreamType& stream_type,
std::vector<feedwire::ContentId> content_ids,
std::vector<feedwire::ContentId> shared_state_ids,
base::OnceCallback<void(std::vector<feedstore::Content>,
std::vector<feedstore::StreamSharedState>)>
content_callback) { … }
void FeedStore::OnReadContentFinished(
base::OnceCallback<void(std::vector<feedstore::Content>,
std::vector<feedstore::StreamSharedState>)>
callback,
bool success,
std::unique_ptr<std::vector<feedstore::Record>> records) { … }
void FeedStore::ReadActions(
base::OnceCallback<void(std::vector<feedstore::StoredAction>)> callback) { … }
void FeedStore::OnReadActionsFinished(
base::OnceCallback<void(std::vector<feedstore::StoredAction>)> callback,
bool success,
std::unique_ptr<std::vector<feedstore::Record>> records) { … }
void FeedStore::WriteActions(std::vector<feedstore::StoredAction> actions,
base::OnceCallback<void(bool)> callback) { … }
void FeedStore::UpdateActions(
std::vector<feedstore::StoredAction> actions_to_update,
std::vector<LocalActionId> ids_to_remove,
base::OnceCallback<void(bool)> callback) { … }
void FeedStore::RemoveActions(std::vector<LocalActionId> ids,
base::OnceCallback<void(bool)> callback) { … }
void FeedStore::Write(std::vector<feedstore::Record> records,
base::OnceCallback<void(bool)> callback) { … }
void FeedStore::OnWriteFinished(base::OnceCallback<void(bool)> callback,
bool success) { … }
void FeedStore::ReadMetadata(
base::OnceCallback<void(std::unique_ptr<feedstore::Metadata>)> callback) { … }
void FeedStore::ReadWebFeedStartupData(
base::OnceCallback<void(WebFeedStartupData)> callback) { … }
void FeedStore::OnReadWebFeedStartupDataFinished(
base::OnceCallback<void(WebFeedStartupData)> callback,
bool read_ok,
std::unique_ptr<std::vector<feedstore::Record>> records) { … }
void FeedStore::ReadStartupData(
base::OnceCallback<void(StartupData)> callback) { … }
void FeedStore::OnReadStartupDataFinished(
base::OnceCallback<void(StartupData)> callback,
bool read_ok,
std::unique_ptr<std::vector<feedstore::Record>> records) { … }
void FeedStore::WriteRecommendedFeeds(
feedstore::RecommendedWebFeedIndex index,
std::vector<feedstore::WebFeedInfo> web_feed_info,
base::OnceClosure callback) { … }
void FeedStore::WriteSubscribedFeeds(feedstore::SubscribedWebFeeds index,
base::OnceClosure callback) { … }
void FeedStore::OnReadMetadataFinished(
base::OnceCallback<void(std::unique_ptr<feedstore::Metadata>)> callback,
bool read_ok,
std::unique_ptr<feedstore::Record> record) { … }
void FeedStore::WriteMetadata(feedstore::Metadata metadata,
base::OnceCallback<void(bool)> callback) { … }
void FeedStore::UpgradeFromStreamSchemaV0(
feedstore::Metadata metadata,
base::OnceCallback<void(feedstore::Metadata)> callback) { … }
void FeedStore::ReadRecommendedWebFeedInfo(
const std::string& web_feed_id,
base::OnceCallback<void(std::unique_ptr<feedstore::WebFeedInfo>)>
callback) { … }
void FeedStore::ReadRecommendedWebFeedInfoFinished(
base::OnceCallback<void(std::unique_ptr<feedstore::WebFeedInfo>)> callback,
bool read_ok,
std::unique_ptr<feedstore::Record> record) { … }
void FeedStore::WritePendingWebFeedOperation(
feedstore::PendingWebFeedOperation operation) { … }
void FeedStore::RemovePendingWebFeedOperation(int64_t operation_id) { … }
void FeedStore::WriteDocView(feedstore::DocView doc_view) { … }
void FeedStore::RemoveDocViews(std::vector<feedstore::DocView> doc_views) { … }
void FeedStore::ReadDocViews(
base::OnceCallback<void(std::vector<feedstore::DocView>)> callback) { … }
}