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

Side by Side Diff: chrome/browser/push_messaging/push_messaging_app_identifier.cc

Issue 2697793004: Push API: Validate storage before returning cached subscriptions (Closed)
Patch Set: Fix include Created 3 years, 8 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h" 5 #include "chrome/browser/push_messaging/push_messaging_app_identifier.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include "base/guid.h" 9 #include "base/guid.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // static 67 // static
68 bool PushMessagingAppIdentifier::UseInstanceID(const std::string& app_id) { 68 bool PushMessagingAppIdentifier::UseInstanceID(const std::string& app_id) {
69 return base::EndsWith(app_id, kInstanceIDGuidSuffix, 69 return base::EndsWith(app_id, kInstanceIDGuidSuffix,
70 base::CompareCase::SENSITIVE); 70 base::CompareCase::SENSITIVE);
71 } 71 }
72 72
73 // static 73 // static
74 PushMessagingAppIdentifier PushMessagingAppIdentifier::Generate( 74 PushMessagingAppIdentifier PushMessagingAppIdentifier::Generate(
75 const GURL& origin, 75 const GURL& origin,
76 int64_t service_worker_registration_id) { 76 int64_t service_worker_registration_id) {
77 // All new push subscriptions use Instance ID tokens.
78 return GenerateInternal(origin, service_worker_registration_id,
79 true /* use_instance_id */);
80 }
81
82 // static
83 PushMessagingAppIdentifier PushMessagingAppIdentifier::LegacyGenerateForTesting(
84 const GURL& origin,
85 int64_t service_worker_registration_id) {
86 return GenerateInternal(origin, service_worker_registration_id,
87 false /* use_instance_id */);
88 }
89
90 // static
91 PushMessagingAppIdentifier PushMessagingAppIdentifier::GenerateInternal(
92 const GURL& origin,
93 int64_t service_worker_registration_id,
94 bool use_instance_id) {
77 // Use uppercase GUID for consistency with GUIDs Push has already sent to GCM. 95 // Use uppercase GUID for consistency with GUIDs Push has already sent to GCM.
78 // Also allows detecting case mangling; see code commented "crbug.com/461867". 96 // Also allows detecting case mangling; see code commented "crbug.com/461867".
79 std::string guid = base::ToUpperASCII(base::GenerateGUID()); 97 std::string guid = base::ToUpperASCII(base::GenerateGUID());
80 // All new push subscriptions are Instance ID tokens. 98 if (use_instance_id) {
81 guid.replace(guid.size() - kGuidSuffixLength, kGuidSuffixLength, 99 guid.replace(guid.size() - kGuidSuffixLength, kGuidSuffixLength,
82 kInstanceIDGuidSuffix); 100 kInstanceIDGuidSuffix);
101 }
83 CHECK(!guid.empty()); 102 CHECK(!guid.empty());
84 std::string app_id = 103 std::string app_id =
85 kPushMessagingAppIdentifierPrefix + origin.spec() + kSeparator + guid; 104 kPushMessagingAppIdentifierPrefix + origin.spec() + kSeparator + guid;
86 105
87 PushMessagingAppIdentifier app_identifier(app_id, origin, 106 PushMessagingAppIdentifier app_identifier(app_id, origin,
88 service_worker_registration_id); 107 service_worker_registration_id);
89 app_identifier.DCheckValid(); 108 app_identifier.DCheckValid();
90 return app_identifier; 109 return app_identifier;
91 } 110 }
92 111
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 if (UseInstanceID(app_id_)) { 262 if (UseInstanceID(app_id_)) {
244 DCHECK(!base::IsValidGUID(guid)); 263 DCHECK(!base::IsValidGUID(guid));
245 264
246 // Replace suffix with valid hex so we can validate the rest of the string. 265 // Replace suffix with valid hex so we can validate the rest of the string.
247 guid = guid.replace(guid.size() - kGuidSuffixLength, kGuidSuffixLength, 266 guid = guid.replace(guid.size() - kGuidSuffixLength, kGuidSuffixLength,
248 kGuidSuffixLength, 'C'); 267 kGuidSuffixLength, 'C');
249 } 268 }
250 DCHECK(base::IsValidGUID(guid)); 269 DCHECK(base::IsValidGUID(guid));
251 #endif // DCHECK_IS_ON() 270 #endif // DCHECK_IS_ON()
252 } 271 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698