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/services/gcm/push_messaging_application_id.h" | 5 #include "chrome/browser/services/gcm/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" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 void PushMessagingApplicationId::PersistToDisk(Profile* profile) const { | 94 void PushMessagingApplicationId::PersistToDisk(Profile* profile) const { |
95 DCHECK(IsValid()); | 95 DCHECK(IsValid()); |
96 | 96 |
97 DictionaryPrefUpdate update(profile->GetPrefs(), | 97 DictionaryPrefUpdate update(profile->GetPrefs(), |
98 prefs::kPushMessagingApplicationIdMap); | 98 prefs::kPushMessagingApplicationIdMap); |
99 base::DictionaryValue* map = update.Get(); | 99 base::DictionaryValue* map = update.Get(); |
100 | 100 |
101 // Delete any stale entry with the same origin and Service Worker | 101 // Delete any stale entry with the same origin and Service Worker |
102 // registration id (hence we ensure there is a 1:1 not 1:many mapping). | 102 // registration id (hence we ensure there is a 1:1 not 1:many mapping). |
103 PushMessagingApplicationId old = Get(profile, origin, | 103 PushMessagingApplicationId old = Get(profile, origin_, |
104 service_worker_registration_id); | 104 service_worker_registration_id_); |
105 if (old.IsValid()) | 105 if (old.IsValid()) |
106 map->RemoveWithoutPathExpansion(old.app_id_guid, nullptr); | 106 map->RemoveWithoutPathExpansion(old.app_id_guid_, nullptr); |
107 | 107 |
108 std::string origin_and_sw_id = origin.spec() + kSeparator + | 108 std::string origin_and_sw_id = origin_.spec() + kSeparator + |
109 base::Int64ToString(service_worker_registration_id); | 109 base::Int64ToString(service_worker_registration_id_); |
110 map->SetStringWithoutPathExpansion(app_id_guid, origin_and_sw_id); | 110 map->SetStringWithoutPathExpansion(app_id_guid_, origin_and_sw_id); |
111 } | 111 } |
112 | 112 |
113 void PushMessagingApplicationId::DeleteFromDisk(Profile* profile) const { | 113 void PushMessagingApplicationId::DeleteFromDisk(Profile* profile) const { |
114 DCHECK(IsValid()); | 114 DCHECK(IsValid()); |
115 | 115 |
116 DictionaryPrefUpdate update(profile->GetPrefs(), | 116 DictionaryPrefUpdate update(profile->GetPrefs(), |
117 prefs::kPushMessagingApplicationIdMap); | 117 prefs::kPushMessagingApplicationIdMap); |
118 base::DictionaryValue* map = update.Get(); | 118 base::DictionaryValue* map = update.Get(); |
119 map->RemoveWithoutPathExpansion(app_id_guid, nullptr); | 119 map->RemoveWithoutPathExpansion(app_id_guid_, nullptr); |
120 } | 120 } |
121 | 121 |
122 PushMessagingApplicationId::PushMessagingApplicationId() | 122 PushMessagingApplicationId::PushMessagingApplicationId() |
123 : origin(GURL::EmptyGURL()), | 123 : origin_(GURL::EmptyGURL()), |
124 service_worker_registration_id(-1) { | 124 service_worker_registration_id_(-1) { |
125 } | 125 } |
126 | 126 |
127 PushMessagingApplicationId::PushMessagingApplicationId( | 127 PushMessagingApplicationId::PushMessagingApplicationId( |
128 const std::string& app_id_guid, | 128 const std::string& app_id_guid, |
129 const GURL& origin, | 129 const GURL& origin, |
130 int64 service_worker_registration_id) | 130 int64 service_worker_registration_id) |
131 : app_id_guid(app_id_guid), | 131 : app_id_guid_(app_id_guid), |
132 origin(origin), | 132 origin_(origin), |
133 service_worker_registration_id(service_worker_registration_id) { | 133 service_worker_registration_id_(service_worker_registration_id) { |
134 } | 134 } |
135 | 135 |
136 PushMessagingApplicationId::~PushMessagingApplicationId() { | 136 PushMessagingApplicationId::~PushMessagingApplicationId() { |
137 } | 137 } |
138 | 138 |
139 bool PushMessagingApplicationId::IsValid() const { | 139 bool PushMessagingApplicationId::IsValid() const { |
140 const size_t prefix_len = strlen(kPushMessagingApplicationIdPrefix); | 140 const size_t prefix_len = strlen(kPushMessagingApplicationIdPrefix); |
141 return origin.is_valid() && origin.GetOrigin() == origin | 141 return origin_.is_valid() && origin_.GetOrigin() == origin_ |
142 && service_worker_registration_id >= 0 | 142 && service_worker_registration_id_ >= 0 |
143 && !app_id_guid.compare(0, prefix_len, kPushMessagingApplicationIdPrefix) | 143 && !app_id_guid_.compare(0, prefix_len, kPushMessagingApplicationIdPrefix) |
144 && base::IsValidGUID(app_id_guid.substr(prefix_len, std::string::npos)); | 144 && base::IsValidGUID(app_id_guid_.substr(prefix_len, std::string::npos)); |
145 } | 145 } |
146 | 146 |
147 } // namespace gcm | 147 } // namespace gcm |
OLD | NEW |