| Index: components/gcm_driver/registration_info.cc
|
| diff --git a/components/gcm_driver/registration_info.cc b/components/gcm_driver/registration_info.cc
|
| index c91d1ccfabdaa92ea67262b9d78290566cd37b91..0684c57c36add9e88827f6b5f1cc0a320327b2f9 100644
|
| --- a/components/gcm_driver/registration_info.cc
|
| +++ b/components/gcm_driver/registration_info.cc
|
| @@ -12,9 +12,13 @@
|
| namespace gcm {
|
|
|
| namespace {
|
| -const char kInsanceIDSerializationPrefix[] = "iid-";
|
| -const int kInsanceIDSerializationPrefixLength =
|
| - sizeof(kInsanceIDSerializationPrefix) / sizeof(char) - 1;
|
| +const char kInstanceIDSerializationPrefix[] = "iid-";
|
| +const int kInstanceIDSerializationPrefixLength =
|
| + sizeof(kInstanceIDSerializationPrefix) / sizeof(char) - 1;
|
| +
|
| +const char kInstanceIDUseSubtypePrefix[] = "use_subtype,";
|
| +const int kInstanceIDUseSubtypePrefixLength =
|
| + sizeof(kInstanceIDUseSubtypePrefix) / sizeof(char) - 1;
|
| } // namespace
|
|
|
| // static
|
| @@ -24,7 +28,7 @@ std::unique_ptr<RegistrationInfo> RegistrationInfo::BuildFromString(
|
| std::string* registration_id) {
|
| std::unique_ptr<RegistrationInfo> registration;
|
|
|
| - if (base::StartsWith(serialized_key, kInsanceIDSerializationPrefix,
|
| + if (base::StartsWith(serialized_key, kInstanceIDSerializationPrefix,
|
| base::CompareCase::SENSITIVE))
|
| registration.reset(new InstanceIDTokenInfo);
|
| else
|
| @@ -158,14 +162,15 @@ RegistrationInfo::RegistrationType InstanceIDTokenInfo::GetType() const {
|
| }
|
|
|
| std::string InstanceIDTokenInfo::GetSerializedKey() const {
|
| - DCHECK(authorized_entity.find(',') == std::string::npos &&
|
| + DCHECK(app_id.find(',') == std::string::npos &&
|
| + authorized_entity.find(',') == std::string::npos &&
|
| scope.find(',') == std::string::npos);
|
|
|
| // Multiple registrations are supported for Instance ID. So the key is based
|
| // on the combination of (app_id, authorized_entity, scope).
|
|
|
| // Adds a prefix to differentiate easily with GCM registration key.
|
| - std::string key(kInsanceIDSerializationPrefix);
|
| + std::string key(kInstanceIDSerializationPrefix);
|
| key += app_id;
|
| key += ",";
|
| key += authorized_entity;
|
| @@ -176,7 +181,10 @@ std::string InstanceIDTokenInfo::GetSerializedKey() const {
|
|
|
| std::string InstanceIDTokenInfo::GetSerializedValue(
|
| const std::string& registration_id) const {
|
| - return registration_id;
|
| + DCHECK(!base::StartsWith(registration_id, kInstanceIDUseSubtypePrefix,
|
| + base::CompareCase::SENSITIVE));
|
| + return (use_subtype ? kInstanceIDUseSubtypePrefix : std::string()) +
|
| + registration_id;
|
| }
|
|
|
| bool InstanceIDTokenInfo::Deserialize(
|
| @@ -186,13 +194,13 @@ bool InstanceIDTokenInfo::Deserialize(
|
| if (serialized_key.empty() || serialized_value.empty())
|
| return false;
|
|
|
| - if (!base::StartsWith(serialized_key, kInsanceIDSerializationPrefix,
|
| + if (!base::StartsWith(serialized_key, kInstanceIDSerializationPrefix,
|
| base::CompareCase::SENSITIVE))
|
| return false;
|
|
|
| std::vector<std::string> fields = base::SplitString(
|
| - serialized_key.substr(kInsanceIDSerializationPrefixLength),
|
| - ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
| + serialized_key.substr(kInstanceIDSerializationPrefixLength), ",",
|
| + base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
|
| if (fields.size() != 3 || fields[0].empty() ||
|
| fields[1].empty() || fields[2].empty()) {
|
| return false;
|
| @@ -201,9 +209,14 @@ bool InstanceIDTokenInfo::Deserialize(
|
| authorized_entity = fields[1];
|
| scope = fields[2];
|
|
|
| - // Registration ID is same as the serialized value;
|
| - if (registration_id)
|
| - *registration_id = serialized_value;
|
| + // Serialized value is registration ID, with a prefix if |use_subtype|.
|
| + use_subtype = base::StartsWith(serialized_value, kInstanceIDUseSubtypePrefix,
|
| + base::CompareCase::SENSITIVE);
|
| + if (registration_id) {
|
| + *registration_id =
|
| + use_subtype ? serialized_value.substr(kInstanceIDUseSubtypePrefixLength)
|
| + : serialized_value;
|
| + }
|
|
|
| return true;
|
| }
|
| @@ -214,7 +227,7 @@ bool RegistrationInfoComparer::operator()(
|
| DCHECK(a.get() && b.get());
|
|
|
| // For GCMRegistrationInfo, the comparison is based on app_id only.
|
| - // For InstanceIDTokenInfo, the comparison is bsaed on
|
| + // For InstanceIDTokenInfo, the comparison is based on
|
| // <app_id, authorized_entity, scope>.
|
| if (a->app_id < b->app_id)
|
| return true;
|
|
|