| OLD | NEW |
| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 PushMessagingAppIdentifier app_identifier(app_id, origin, | 69 PushMessagingAppIdentifier app_identifier(app_id, origin, |
| 70 service_worker_registration_id); | 70 service_worker_registration_id); |
| 71 app_identifier.DCheckValid(); | 71 app_identifier.DCheckValid(); |
| 72 return app_identifier; | 72 return app_identifier; |
| 73 } | 73 } |
| 74 | 74 |
| 75 // static | 75 // static |
| 76 PushMessagingAppIdentifier PushMessagingAppIdentifier::FindByAppId( | 76 PushMessagingAppIdentifier PushMessagingAppIdentifier::FindByAppId( |
| 77 Profile* profile, const std::string& app_id) { | 77 Profile* profile, const std::string& app_id) { |
| 78 // Check case of app_id hasn't been mangled (crbug.com/461867). | 78 if (!StartsWithASCII(app_id, kPushMessagingAppIdentifierPrefix, |
| 79 false /* case_sensitive */)) { |
| 80 return PushMessagingAppIdentifier(); |
| 81 } |
| 82 |
| 83 // Since we now know this is a Push Messaging app_id, check the case hasn't |
| 84 // been mangled (crbug.com/461867). |
| 85 DCHECK_EQ(kPushMessagingAppIdentifierPrefix, app_id.substr(0, kPrefixLength)); |
| 79 DCHECK_GE(app_id.size(), kPrefixLength + kGuidLength); | 86 DCHECK_GE(app_id.size(), kPrefixLength + kGuidLength); |
| 80 DCHECK_EQ(kPushMessagingAppIdentifierPrefix, app_id.substr(0, kPrefixLength)); | |
| 81 DCHECK_EQ(app_id.substr(app_id.size() - kGuidLength), | 87 DCHECK_EQ(app_id.substr(app_id.size() - kGuidLength), |
| 82 StringToUpperASCII(app_id.substr(app_id.size() - kGuidLength))); | 88 StringToUpperASCII(app_id.substr(app_id.size() - kGuidLength))); |
| 83 | 89 |
| 84 const base::DictionaryValue* map = | 90 const base::DictionaryValue* map = |
| 85 profile->GetPrefs()->GetDictionary(prefs::kPushMessagingAppIdentifierMap); | 91 profile->GetPrefs()->GetDictionary(prefs::kPushMessagingAppIdentifierMap); |
| 86 | 92 |
| 87 std::string map_value; | 93 std::string map_value; |
| 88 if (!map->GetStringWithoutPathExpansion(app_id, &map_value)) | 94 if (!map->GetStringWithoutPathExpansion(app_id, &map_value)) |
| 89 return PushMessagingAppIdentifier(); | 95 return PushMessagingAppIdentifier(); |
| 90 | 96 |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 const size_t suffix_length = 1 /* kSeparator */ + kGuidLength; | 199 const size_t suffix_length = 1 /* kSeparator */ + kGuidLength; |
| 194 DCHECK(app_id_.size() > kPrefixLength + suffix_length); | 200 DCHECK(app_id_.size() > kPrefixLength + suffix_length); |
| 195 DCHECK_EQ(origin_, GURL(app_id_.substr( | 201 DCHECK_EQ(origin_, GURL(app_id_.substr( |
| 196 kPrefixLength, app_id_.size() - kPrefixLength - suffix_length))); | 202 kPrefixLength, app_id_.size() - kPrefixLength - suffix_length))); |
| 197 DCHECK_EQ(std::string(1, kSeparator), | 203 DCHECK_EQ(std::string(1, kSeparator), |
| 198 app_id_.substr(app_id_.size() - suffix_length, 1)); | 204 app_id_.substr(app_id_.size() - suffix_length, 1)); |
| 199 } | 205 } |
| 200 // GUID | 206 // GUID |
| 201 DCHECK(base::IsValidGUID(app_id_.substr(app_id_.size() - kGuidLength))); | 207 DCHECK(base::IsValidGUID(app_id_.substr(app_id_.size() - kGuidLength))); |
| 202 } | 208 } |
| OLD | NEW |