| 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_application_id.h" | 5 #include "chrome/browser/push_messaging/push_messaging_application_id.h" |
| 6 | 6 |
| 7 #include "base/guid.h" | 7 #include "base/guid.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "components/pref_registry/pref_registry_syncable.h" | 17 #include "components/pref_registry/pref_registry_syncable.h" |
| 18 | 18 |
| 19 namespace { | 19 namespace { |
| 20 const char kSeparator = '#'; // Ok as only the origin of the url is used. | 20 const char kSeparator = '#'; // Ok as only the origin of the url is used. |
| 21 } // namespace | 21 } // namespace |
| 22 | 22 |
| 23 const char kPushMessagingApplicationIdPrefix[] = "wp:"; | 23 const char kPushMessagingApplicationIdPrefix[] = "wp:"; |
| 24 | 24 |
| 25 // static | 25 // static |
| 26 void PushMessagingApplicationId::RegisterProfilePrefs( | 26 void PushMessagingApplicationId::RegisterProfilePrefs( |
| 27 user_prefs::PrefRegistrySyncable* registry) { | 27 user_prefs::PrefRegistrySyncable* registry) { |
| 28 registry->RegisterDictionaryPref( | 28 registry->RegisterDictionaryPref(prefs::kPushMessagingApplicationIdMap); |
| 29 prefs::kPushMessagingApplicationIdMap, | |
| 30 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | |
| 31 } | 29 } |
| 32 | 30 |
| 33 // static | 31 // static |
| 34 PushMessagingApplicationId PushMessagingApplicationId::Generate( | 32 PushMessagingApplicationId PushMessagingApplicationId::Generate( |
| 35 const GURL& origin, int64 service_worker_registration_id) | 33 const GURL& origin, int64 service_worker_registration_id) |
| 36 { | 34 { |
| 37 // TODO(johnme): Does GenerateGUID produce good enough random numbers? | 35 // TODO(johnme): Does GenerateGUID produce good enough random numbers? |
| 38 std::string guid = base::GenerateGUID(); | 36 std::string guid = base::GenerateGUID(); |
| 39 CHECK(!guid.empty()); | 37 CHECK(!guid.empty()); |
| 40 std::string app_id_guid = | 38 std::string app_id_guid = |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 PushMessagingApplicationId::~PushMessagingApplicationId() { | 157 PushMessagingApplicationId::~PushMessagingApplicationId() { |
| 160 } | 158 } |
| 161 | 159 |
| 162 bool PushMessagingApplicationId::IsValid() const { | 160 bool PushMessagingApplicationId::IsValid() const { |
| 163 const size_t prefix_len = strlen(kPushMessagingApplicationIdPrefix); | 161 const size_t prefix_len = strlen(kPushMessagingApplicationIdPrefix); |
| 164 return origin_.is_valid() && origin_.GetOrigin() == origin_ | 162 return origin_.is_valid() && origin_.GetOrigin() == origin_ |
| 165 && service_worker_registration_id_ >= 0 | 163 && service_worker_registration_id_ >= 0 |
| 166 && !app_id_guid_.compare(0, prefix_len, kPushMessagingApplicationIdPrefix) | 164 && !app_id_guid_.compare(0, prefix_len, kPushMessagingApplicationIdPrefix) |
| 167 && base::IsValidGUID(app_id_guid_.substr(prefix_len, std::string::npos)); | 165 && base::IsValidGUID(app_id_guid_.substr(prefix_len, std::string::npos)); |
| 168 } | 166 } |
| OLD | NEW |