Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(874)

Unified Diff: chrome/browser/push_messaging/push_messaging_app_identifier.cc

Issue 1851423003: Make Web Push use InstanceID tokens instead of GCM registrations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@iid4default
Patch Set: Rebase (main conflics in browsertest and PMMF) Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/push_messaging/push_messaging_app_identifier.cc
diff --git a/chrome/browser/push_messaging/push_messaging_app_identifier.cc b/chrome/browser/push_messaging/push_messaging_app_identifier.cc
index 812f00bf8961dcd47428250ea620cf5ae0290fa1..9c176d14014780ee27a71cd11042fb8d74282670 100644
--- a/chrome/browser/push_messaging/push_messaging_app_identifier.cc
+++ b/chrome/browser/push_messaging/push_messaging_app_identifier.cc
@@ -19,11 +19,13 @@
#include "components/prefs/scoped_user_pref_update.h"
const char kPushMessagingAppIdentifierPrefix[] = "wp:";
+const char kInstanceIDGuidSuffix[] = "-V2";
namespace {
// sizeof is strlen + 1 since it's null-terminated.
const size_t kPrefixLength = sizeof(kPushMessagingAppIdentifierPrefix) - 1;
+const size_t kGuidSuffixLength = sizeof(kInstanceIDGuidSuffix) - 1;
const char kSeparator = '#'; // Ok as only the origin of the url is used.
const size_t kGuidLength = 36; // "%08X-%04X-%04X-%04X-%012llX"
@@ -63,12 +65,21 @@ void PushMessagingAppIdentifier::RegisterProfilePrefs(
}
// static
+bool PushMessagingAppIdentifier::UseInstanceID(const std::string& app_id) {
+ return app_id.length() > kPrefixLength + kGuidLength &&
+ kInstanceIDGuidSuffix == app_id.substr(app_id.size() - 3);
+}
+
+// static
PushMessagingAppIdentifier PushMessagingAppIdentifier::Generate(
const GURL& origin,
int64_t service_worker_registration_id) {
// Use uppercase GUID for consistency with GUIDs Push has already sent to GCM.
// Also allows detecting case mangling; see code commented "crbug.com/461867".
std::string guid = base::ToUpperASCII(base::GenerateGUID());
+ // All new push subscriptions are Instance ID tokens.
+ guid.replace(guid.size() - kGuidSuffixLength, kGuidSuffixLength,
+ kInstanceIDGuidSuffix);
CHECK(!guid.empty());
std::string app_id =
kPushMessagingAppIdentifierPrefix + origin.spec() + kSeparator + guid;
@@ -204,6 +215,7 @@ void PushMessagingAppIdentifier::DCheckValid() const {
// "wp:"
DCHECK_EQ(kPushMessagingAppIdentifierPrefix,
app_id_.substr(0, kPrefixLength));
+
// Optional (origin.spec() + '#')
if (app_id_.size() != kPrefixLength + kGuidLength) {
const size_t suffix_length = 1 /* kSeparator */ + kGuidLength;
@@ -214,6 +226,16 @@ void PushMessagingAppIdentifier::DCheckValid() const {
DCHECK_EQ(std::string(1, kSeparator),
app_id_.substr(app_id_.size() - suffix_length, 1));
}
- // GUID
- DCHECK(base::IsValidGUID(app_id_.substr(app_id_.size() - kGuidLength)));
+
+ // GUID, optionally with last few chars replaced with kInstanceIDGuidSuffix.
+ DCHECK(base::IsValidGUID(
+ app_id_.substr(app_id_.size() - kGuidLength,
+ kGuidLength - kGuidSuffixLength) +
+ // It's ok for it to end with kInstanceIDGuidSuffix; if so, pass
+ // arbitrary hex of the same length so that IsValidGUID passes.
+ (kInstanceIDGuidSuffix ==
+ app_id_.substr(app_id_.size() - kGuidSuffixLength)
+ ? std::string(kGuidSuffixLength, 'C') // arbitrary hex
+ : app_id_.substr(app_id_.size() - kGuidSuffixLength) // real suffix
+ )));
Peter Beverloo 2016/06/02 15:53:17 This is a ten line DCHECK containing significant l
johnme 2016/06/07 14:16:42 Done.
}

Powered by Google App Engine
This is Rietveld 408576698