Commit 55de4aaa authored by Alexey Baskakov's avatar Alexey Baskakov Committed by Commit Bot

WebApp: Remove redundant app_id from proto values.

1) Update WebAppSpecifics proto to be in sync with WebAppProto,
launch_container field and enum added.

2) WebAppProto::app_id was a redundant value in the dictionary.

app_id is a hash of launch url and it can be inferred from launch_url
field. app_id is the client tag and the storage key.

WebAppSyncBridge::GetClientTag and WebAppSyncBridge::GetStorageKey
will be implemented to return GenerateAppIdFromURL(launch_url).

Bug: 891172
Change-Id: If3abbb96d2bffb368ce37b3d47d0691c3bf11c16
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1792425Reviewed-by: default avatarMarc Treib <treib@chromium.org>
Reviewed-by: default avatarAlan Cutter <alancutter@chromium.org>
Commit-Queue: Alexey Baskakov <loyso@chromium.org>
Cr-Commit-Position: refs/heads/master@{#695858}
parent f265a0c1
...@@ -16,12 +16,6 @@ message WebAppIconInfoProto { ...@@ -16,12 +16,6 @@ message WebAppIconInfoProto {
required int32 size_in_px = 2; required int32 size_in_px = 2;
} }
// TODO(loyso): Move this enum to components/sync/protocol/sync_enums.proto.
enum LaunchContainerProto {
TAB = 1;
WINDOW = 2;
}
// A set to track simultaneous installs and uninstalls from multiple install // A set to track simultaneous installs and uninstalls from multiple install
// sources. // sources.
message SourcesProto { message SourcesProto {
...@@ -32,24 +26,29 @@ message SourcesProto { ...@@ -32,24 +26,29 @@ message SourcesProto {
required bool default = 5; required bool default = 5;
} }
// WebApp class data. // WebApp class data. This should be a superset for WebAppSpecifics in
// This should be a superset for WebAppSpecifics in
// components/sync/protocol/web_app_specifics.proto // components/sync/protocol/web_app_specifics.proto
message WebAppProto { message WebAppProto {
// app_id is the client tag for sync system. // Keep in sync with WebAppSpecifics::LaunchContainer.
required string app_id = 1; enum LaunchContainer {
required string launch_url = 2; TAB = 1;
required string name = 3; WINDOW = 2;
required LaunchContainerProto launch_container = 4; }
optional uint32 theme_color = 5;
// app_id is a hash of launch_url. app_id is the client tag for sync system.
// app_id is the storage key in ModelTypeStore.
required string launch_url = 1;
required string name = 2;
required LaunchContainer launch_container = 3;
optional uint32 theme_color = 4;
// Local data members, not to be synced: // Local data members, not to be synced:
optional string description = 6; optional string description = 5;
optional string scope = 7; optional string scope = 6;
required SourcesProto sources = 8; required SourcesProto sources = 7;
required bool is_locally_installed = 9; required bool is_locally_installed = 8;
// A list of icon infos. // A list of icon infos.
repeated WebAppIconInfoProto icons = 10; repeated WebAppIconInfoProto icons = 9;
} }
...@@ -44,9 +44,9 @@ void WebAppDatabase::WriteWebApps(AppsToWrite apps, ...@@ -44,9 +44,9 @@ void WebAppDatabase::WriteWebApps(AppsToWrite apps,
BeginTransaction(); BeginTransaction();
for (auto* web_app : apps) { for (const WebApp* web_app : apps) {
auto proto = CreateWebAppProto(*web_app); auto proto = CreateWebAppProto(*web_app);
write_batch_->WriteData(proto->app_id(), proto->SerializeAsString()); write_batch_->WriteData(web_app->app_id(), proto->SerializeAsString());
} }
CommitTransaction(std::move(callback)); CommitTransaction(std::move(callback));
...@@ -71,19 +71,21 @@ std::unique_ptr<WebAppProto> WebAppDatabase::CreateWebAppProto( ...@@ -71,19 +71,21 @@ std::unique_ptr<WebAppProto> WebAppDatabase::CreateWebAppProto(
auto proto = std::make_unique<WebAppProto>(); auto proto = std::make_unique<WebAppProto>();
// Required fields: // Required fields:
const GURL launch_url = web_app.launch_url();
DCHECK(!launch_url.is_empty() && launch_url.is_valid());
DCHECK(!web_app.app_id().empty()); DCHECK(!web_app.app_id().empty());
proto->set_app_id(web_app.app_id()); DCHECK_EQ(web_app.app_id(), GenerateAppIdFromURL(launch_url));
DCHECK(!web_app.launch_url().is_empty() && web_app.launch_url().is_valid()); proto->set_launch_url(launch_url.spec());
proto->set_launch_url(web_app.launch_url().spec());
proto->set_name(web_app.name()); proto->set_name(web_app.name());
DCHECK_NE(LaunchContainer::kDefault, web_app.launch_container()); DCHECK_NE(LaunchContainer::kDefault, web_app.launch_container());
proto->set_launch_container(web_app.launch_container() == proto->set_launch_container(web_app.launch_container() ==
LaunchContainer::kWindow LaunchContainer::kWindow
? LaunchContainerProto::WINDOW ? WebAppProto::WINDOW
: LaunchContainerProto::TAB); : WebAppProto::TAB);
DCHECK(web_app.sources_.any()); DCHECK(web_app.sources_.any());
proto->mutable_sources()->set_system(web_app.sources_[Source::kSystem]); proto->mutable_sources()->set_system(web_app.sources_[Source::kSystem]);
...@@ -113,17 +115,20 @@ std::unique_ptr<WebAppProto> WebAppDatabase::CreateWebAppProto( ...@@ -113,17 +115,20 @@ std::unique_ptr<WebAppProto> WebAppDatabase::CreateWebAppProto(
// static // static
std::unique_ptr<WebApp> WebAppDatabase::CreateWebApp(const WebAppProto& proto) { std::unique_ptr<WebApp> WebAppDatabase::CreateWebApp(const WebAppProto& proto) {
auto web_app = std::make_unique<WebApp>(proto.app_id()); // AppId is a hash of launch_url. Read launch_url first:
// Required fields:
GURL launch_url(proto.launch_url()); GURL launch_url(proto.launch_url());
if (launch_url.is_empty() || !launch_url.is_valid()) { if (launch_url.is_empty() || !launch_url.is_valid()) {
DLOG(ERROR) << "WebApp proto launch_url parse error: " DLOG(ERROR) << "WebApp proto launch_url parse error: "
<< launch_url.possibly_invalid_spec(); << launch_url.possibly_invalid_spec();
return nullptr; return nullptr;
} }
const AppId app_id = GenerateAppIdFromURL(launch_url);
auto web_app = std::make_unique<WebApp>(app_id);
web_app->SetLaunchUrl(launch_url); web_app->SetLaunchUrl(launch_url);
// Required fields:
if (!proto.has_sources()) { if (!proto.has_sources()) {
DLOG(ERROR) << "WebApp proto parse error: no sources field"; DLOG(ERROR) << "WebApp proto parse error: no sources field";
return nullptr; return nullptr;
...@@ -151,8 +156,7 @@ std::unique_ptr<WebApp> WebAppDatabase::CreateWebApp(const WebAppProto& proto) { ...@@ -151,8 +156,7 @@ std::unique_ptr<WebApp> WebAppDatabase::CreateWebApp(const WebAppProto& proto) {
DLOG(ERROR) << "WebApp proto parse error: no launch_container field"; DLOG(ERROR) << "WebApp proto parse error: no launch_container field";
return nullptr; return nullptr;
} }
web_app->SetLaunchContainer(proto.launch_container() == web_app->SetLaunchContainer(proto.launch_container() == WebAppProto::WINDOW
LaunchContainerProto::WINDOW
? LaunchContainer::kWindow ? LaunchContainer::kWindow
: LaunchContainer::kTab); : LaunchContainer::kTab);
...@@ -267,12 +271,18 @@ std::unique_ptr<WebApp> WebAppDatabase::ParseWebApp(const AppId& app_id, ...@@ -267,12 +271,18 @@ std::unique_ptr<WebApp> WebAppDatabase::ParseWebApp(const AppId& app_id,
const std::string& value) { const std::string& value) {
WebAppProto proto; WebAppProto proto;
const bool parsed = proto.ParseFromString(value); const bool parsed = proto.ParseFromString(value);
if (!parsed || proto.app_id() != app_id) { if (!parsed) {
DLOG(ERROR) << "WebApps LevelDB parse error (unknown)."; DLOG(ERROR) << "WebApps LevelDB parse error: can't parse proto.";
return nullptr; return nullptr;
} }
return CreateWebApp(proto); auto web_app = CreateWebApp(proto);
if (web_app->app_id() != app_id) {
DLOG(ERROR) << "WebApps LevelDB error: app_id doesn't match storage key";
return nullptr;
}
return web_app;
} }
void WebAppDatabase::BeginTransaction() { void WebAppDatabase::BeginTransaction() {
......
...@@ -537,6 +537,17 @@ const char* ProtoEnumToString( ...@@ -537,6 +537,17 @@ const char* ProtoEnumToString(
return ""; return "";
} }
const char* ProtoEnumToString(
sync_pb::WebAppSpecifics::LaunchContainer launch_container) {
ASSERT_ENUM_BOUNDS(sync_pb::WebAppSpecifics, LaunchContainer, TAB, WINDOW);
switch (launch_container) {
ENUM_CASE(sync_pb::WebAppSpecifics, TAB);
ENUM_CASE(sync_pb::WebAppSpecifics, WINDOW);
}
NOTREACHED();
return "";
}
const char* ProtoEnumToString( const char* ProtoEnumToString(
sync_pb::WifiConfigurationSpecificsData::SecurityType security_type) { sync_pb::WifiConfigurationSpecificsData::SecurityType security_type) {
ASSERT_ENUM_BOUNDS(sync_pb::WifiConfigurationSpecificsData, SecurityType, ASSERT_ENUM_BOUNDS(sync_pb::WifiConfigurationSpecificsData, SecurityType,
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "components/sync/protocol/reading_list_specifics.pb.h" #include "components/sync/protocol/reading_list_specifics.pb.h"
#include "components/sync/protocol/session_specifics.pb.h" #include "components/sync/protocol/session_specifics.pb.h"
#include "components/sync/protocol/sync.pb.h" #include "components/sync/protocol/sync.pb.h"
#include "components/sync/protocol/web_app_specifics.pb.h"
// Keep this file in sync with the .proto files in this directory. // Keep this file in sync with the .proto files in this directory.
// //
...@@ -109,6 +110,9 @@ const char* ProtoEnumToString( ...@@ -109,6 +110,9 @@ const char* ProtoEnumToString(
const char* ProtoEnumToString( const char* ProtoEnumToString(
sync_pb::WalletMetadataSpecifics::Type wallet_metadata_type); sync_pb::WalletMetadataSpecifics::Type wallet_metadata_type);
const char* ProtoEnumToString(
sync_pb::WebAppSpecifics::LaunchContainer launch_container);
const char* ProtoEnumToString( const char* ProtoEnumToString(
sync_pb::WifiConfigurationSpecificsData::SecurityType security_type); sync_pb::WifiConfigurationSpecificsData::SecurityType security_type);
......
...@@ -1123,9 +1123,9 @@ VISIT_PROTO_FIELDS(const sync_pb::WalletSyncFlags& proto) { ...@@ -1123,9 +1123,9 @@ VISIT_PROTO_FIELDS(const sync_pb::WalletSyncFlags& proto) {
} }
VISIT_PROTO_FIELDS(const sync_pb::WebAppSpecifics& proto) { VISIT_PROTO_FIELDS(const sync_pb::WebAppSpecifics& proto) {
VISIT(app_id);
VISIT(launch_url); VISIT(launch_url);
VISIT(name); VISIT(name);
VISIT_ENUM(launch_container);
VISIT(theme_color); VISIT(theme_color);
} }
......
...@@ -14,9 +14,14 @@ package sync_pb; ...@@ -14,9 +14,14 @@ package sync_pb;
// WebApp data. This should be a subset of WebAppProto in // WebApp data. This should be a subset of WebAppProto in
// chrome/browser/web_applications/proto/web_app.proto // chrome/browser/web_applications/proto/web_app.proto
message WebAppSpecifics { message WebAppSpecifics {
// app_id is the client tag for sync system. // Keep in sync with WebAppProto::LaunchContainer.
optional string app_id = 1; enum LaunchContainer {
optional string launch_url = 2; TAB = 1;
optional string name = 3; WINDOW = 2;
}
optional string launch_url = 1;
optional string name = 2;
optional LaunchContainer launch_container = 3;
optional uint32 theme_color = 4; optional uint32 theme_color = 4;
} }
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