Commit f5e550c6 authored by Natalie Chouinard's avatar Natalie Chouinard Committed by Commit Bot

[Chromeshine] Switch to multiple ProtoDatabases.

Now that the binary size is less significantly impacted by introducing
additional ProtoDatabase instances (crrev.com/c/1419199), switch to
using a unique ProtoDatabase for each proto message type.

Bug: 921133
Change-Id: Ieae1fc5ba98c574c8e4f9a2587bffa4333fa80df
Reviewed-on: https://chromium-review.googlesource.com/c/1471266
Commit-Queue: Natalie Chouinard <chouinard@chromium.org>
Reviewed-by: default avatarPatrick Noland <pnoland@chromium.org>
Cr-Commit-Position: refs/heads/master@{#631968}
parent 6bb633f7
......@@ -19,6 +19,8 @@
namespace usage_stats {
using leveldb_proto::ProtoDatabase;
// Stores website events, suspensions and token to fully-qualified domain name
// (FQDN) mappings in LevelDB.
class UsageStatsDatabase {
......@@ -36,14 +38,14 @@ class UsageStatsDatabase {
using StatusCallback = base::OnceCallback<void(Error)>;
using UsageStatMap = std::map<std::string, UsageStat>;
// Initializes the database with user |profile|.
explicit UsageStatsDatabase(Profile* profile);
// Initializes the database with a |ProtoDatabase|. Useful for testing.
explicit UsageStatsDatabase(
std::unique_ptr<leveldb_proto::ProtoDatabase<UsageStat>> proto_db);
std::unique_ptr<ProtoDatabase<WebsiteEvent>> website_event_db,
std::unique_ptr<ProtoDatabase<Suspension>> suspension_db,
std::unique_ptr<ProtoDatabase<TokenMapping>> token_mapping_db);
~UsageStatsDatabase();
......@@ -84,29 +86,31 @@ class UsageStatsDatabase {
void OnLoadEntriesForGetAllEvents(
EventsCallback callback,
bool isSuccess,
std::unique_ptr<std::vector<UsageStat>> stats);
std::unique_ptr<std::vector<WebsiteEvent>> stats);
void OnLoadEntriesForQueryEventsInRange(
EventsCallback callback,
bool isSuccess,
std::unique_ptr<UsageStatMap> stat_map);
std::unique_ptr<std::map<std::string, WebsiteEvent>> event_map);
void OnLoadEntriesForDeleteEventsInRange(
StatusCallback callback,
bool isSuccess,
std::unique_ptr<UsageStatMap> stat_map);
std::unique_ptr<std::map<std::string, WebsiteEvent>> event_map);
void OnLoadEntriesForGetAllSuspensions(
SuspensionsCallback callback,
bool isSuccess,
std::unique_ptr<std::vector<UsageStat>> stats);
std::unique_ptr<std::vector<Suspension>> suspensions);
void OnLoadEntriesForGetAllTokenMappings(
TokenMappingsCallback callback,
bool isSuccess,
std::unique_ptr<std::vector<UsageStat>> stats);
std::unique_ptr<std::vector<TokenMapping>> mappings);
std::unique_ptr<leveldb_proto::ProtoDatabase<UsageStat>> proto_db_;
std::unique_ptr<ProtoDatabase<WebsiteEvent>> website_event_db_;
std::unique_ptr<ProtoDatabase<Suspension>> suspension_db_;
std::unique_ptr<ProtoDatabase<TokenMapping>> token_mapping_db_;
base::WeakPtrFactory<UsageStatsDatabase> weak_ptr_factory_;
......
......@@ -42,13 +42,3 @@ message TokenMapping {
message Suspension {
optional string fqdn = 1;
}
// Allows for any one of {WebsiteEvent, Suspension, TokenMapping} to be stored
// in the same proto database.
message UsageStat {
oneof value {
WebsiteEvent website_event = 1;
Suspension suspension = 2;
TokenMapping token_mapping = 3;
}
}
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