Commit 171855e8 authored by Victor Costan's avatar Victor Costan Committed by Commit Bot

CookieStore: Switch CookieChangeSubscription to proto3.

The change makes all proto fields optional, and slightly simplifies the
decoding logic.

CookieChangeSubscription::Serialize() sets all the proto's fields, so
the change is only relevant for corrupt protos. In this case, proto3
will report default values for missing fields.

The change is compatible with previously written data, as proto2 and
proto3 use the same on-disk format.

Bug: 729800
Change-Id: I06b08ce003b571b716bccd540fa15918ea925bb8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2036393Reviewed-by: default avatarAyu Ishii <ayui@chromium.org>
Commit-Queue: Victor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737905}
parent 50cf1bfe
...@@ -40,9 +40,10 @@ network::mojom::CookieMatchType CookieMatchTypeFromProto( ...@@ -40,9 +40,10 @@ network::mojom::CookieMatchType CookieMatchTypeFromProto(
return network::mojom::CookieMatchType::EQUALS; return network::mojom::CookieMatchType::EQUALS;
case proto::CookieMatchType::STARTS_WITH: case proto::CookieMatchType::STARTS_WITH:
return ::network::mojom::CookieMatchType::STARTS_WITH; return ::network::mojom::CookieMatchType::STARTS_WITH;
default:
// The on-disk value was corrupted.
return network::mojom::CookieMatchType::EQUALS;
} }
NOTREACHED();
return network::mojom::CookieMatchType::EQUALS;
} }
} // namespace } // namespace
...@@ -102,16 +103,13 @@ CookieChangeSubscription::ToMojoVector( ...@@ -102,16 +103,13 @@ CookieChangeSubscription::ToMojoVector(
std::unique_ptr<CookieChangeSubscription> CookieChangeSubscription::Create( std::unique_ptr<CookieChangeSubscription> CookieChangeSubscription::Create(
proto::CookieChangeSubscriptionProto proto, proto::CookieChangeSubscriptionProto proto,
int64_t service_worker_registration_id) { int64_t service_worker_registration_id) {
if (!proto.has_url()) GURL url(proto.url());
return nullptr;
GURL url = GURL(proto.url());
if (!url.is_valid()) if (!url.is_valid())
return nullptr; return nullptr;
std::string name = proto.has_name() ? proto.name() : ""; std::string name = proto.name();
::network::mojom::CookieMatchType match_type = ::network::mojom::CookieMatchType match_type =
proto.has_match_type() ? CookieMatchTypeFromProto(proto.match_type()) CookieMatchTypeFromProto(proto.match_type());
: ::network::mojom::CookieMatchType::EQUALS;
return std::make_unique<CookieChangeSubscription>( return std::make_unique<CookieChangeSubscription>(
std::move(url), std::move(name), match_type, std::move(url), std::move(name), match_type,
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
syntax = "proto2"; syntax = "proto3";
option optimize_for = LITE_RUNTIME; option optimize_for = LITE_RUNTIME;
...@@ -16,9 +16,9 @@ enum CookieMatchType { ...@@ -16,9 +16,9 @@ enum CookieMatchType {
// A single cookie change subscription. // A single cookie change subscription.
message CookieChangeSubscriptionProto { message CookieChangeSubscriptionProto {
required string url = 1; string url = 1;
optional string name = 2; string name = 2;
optional CookieMatchType match_type = 3; CookieMatchType match_type = 3;
} }
// All cookie change subscriptions belonging to a service worker registration. // All cookie change subscriptions belonging to a service worker registration.
......
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