OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "components/gcm_driver/registration_info.h" | 5 #include "components/gcm_driver/registration_info.h" |
6 | 6 |
7 #include "base/strings/string_split.h" | 7 #include "base/strings/string_split.h" |
8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
9 | 9 |
10 namespace gcm { | 10 namespace gcm { |
11 | 11 |
12 namespace { | 12 namespace { |
13 const char kInsanceIDSerializationPrefix[] = "iid-"; | 13 const char kInsanceIDSerializationPrefix[] = "iid-"; |
14 const int kInsanceIDSerializationPrefixLength = | 14 const int kInsanceIDSerializationPrefixLength = |
15 sizeof(kInsanceIDSerializationPrefix) / sizeof(char) - 1; | 15 sizeof(kInsanceIDSerializationPrefix) / sizeof(char) - 1; |
16 } // namespace | 16 } // namespace |
17 | 17 |
18 // static | 18 // static |
19 scoped_ptr<RegistrationInfo> RegistrationInfo::BuildFromString( | 19 scoped_ptr<RegistrationInfo> RegistrationInfo::BuildFromString( |
20 const std::string& serialzied_key, | 20 const std::string& serialzied_key, |
21 const std::string& serialzied_value, | 21 const std::string& serialzied_value, |
22 std::string* registration_id) { | 22 std::string* registration_id) { |
23 scoped_ptr<RegistrationInfo> registration; | 23 scoped_ptr<RegistrationInfo> registration; |
24 | 24 |
25 if (base::StartsWithASCII(serialzied_key, kInsanceIDSerializationPrefix, | 25 if (base::StartsWith(serialzied_key, kInsanceIDSerializationPrefix, |
26 true)) | 26 base::CompareCase::SENSITIVE)) |
27 registration.reset(new InstanceIDTokenInfo); | 27 registration.reset(new InstanceIDTokenInfo); |
28 else | 28 else |
29 registration.reset(new GCMRegistrationInfo); | 29 registration.reset(new GCMRegistrationInfo); |
30 | 30 |
31 if (!registration->Deserialize(serialzied_key, | 31 if (!registration->Deserialize(serialzied_key, |
32 serialzied_value, | 32 serialzied_value, |
33 registration_id)) { | 33 registration_id)) { |
34 registration.reset(); | 34 registration.reset(); |
35 } | 35 } |
36 return registration.Pass(); | 36 return registration.Pass(); |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 return registration_id; | 177 return registration_id; |
178 } | 178 } |
179 | 179 |
180 bool InstanceIDTokenInfo::Deserialize( | 180 bool InstanceIDTokenInfo::Deserialize( |
181 const std::string& serialized_key, | 181 const std::string& serialized_key, |
182 const std::string& serialized_value, | 182 const std::string& serialized_value, |
183 std::string* registration_id) { | 183 std::string* registration_id) { |
184 if (serialized_key.empty() || serialized_value.empty()) | 184 if (serialized_key.empty() || serialized_value.empty()) |
185 return false; | 185 return false; |
186 | 186 |
187 if (!base::StartsWithASCII(serialized_key, kInsanceIDSerializationPrefix, | 187 if (!base::StartsWith(serialized_key, kInsanceIDSerializationPrefix, |
188 true)) | 188 base::CompareCase::SENSITIVE)) |
189 return false; | 189 return false; |
190 | 190 |
191 std::vector<std::string> fields = base::SplitString( | 191 std::vector<std::string> fields = base::SplitString( |
192 serialized_key.substr(kInsanceIDSerializationPrefixLength), | 192 serialized_key.substr(kInsanceIDSerializationPrefixLength), |
193 ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); | 193 ",", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
194 if (fields.size() != 3 || fields[0].empty() || | 194 if (fields.size() != 3 || fields[0].empty() || |
195 fields[1].empty() || fields[2].empty()) { | 195 fields[1].empty() || fields[2].empty()) { |
196 return false; | 196 return false; |
197 } | 197 } |
198 app_id = fields[0]; | 198 app_id = fields[0]; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 244 |
245 bool ExistsGCMRegistrationInMap(const RegistrationInfoMap& map, | 245 bool ExistsGCMRegistrationInMap(const RegistrationInfoMap& map, |
246 const std::string& app_id) { | 246 const std::string& app_id) { |
247 scoped_ptr<GCMRegistrationInfo> gcm_registration(new GCMRegistrationInfo); | 247 scoped_ptr<GCMRegistrationInfo> gcm_registration(new GCMRegistrationInfo); |
248 gcm_registration->app_id = app_id; | 248 gcm_registration->app_id = app_id; |
249 return map.count( | 249 return map.count( |
250 make_linked_ptr<RegistrationInfo>(gcm_registration.release())) > 0; | 250 make_linked_ptr<RegistrationInfo>(gcm_registration.release())) > 0; |
251 } | 251 } |
252 | 252 |
253 } // namespace gcm | 253 } // namespace gcm |
OLD | NEW |