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

Side by Side Diff: components/gcm_driver/registration_info.cc

Issue 1172183002: Move StartsWith[ASCII] to base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@string_util3
Patch Set: merger Created 5 years, 6 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 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_util.h" 7 #include "base/strings/string_util.h"
8 8
9 namespace gcm { 9 namespace gcm {
10 10
11 namespace { 11 namespace {
12 const char kInsanceIDSerializationPrefix[] = "iid-"; 12 const char kInsanceIDSerializationPrefix[] = "iid-";
13 const int kInsanceIDSerializationPrefixLength = 13 const int kInsanceIDSerializationPrefixLength =
14 sizeof(kInsanceIDSerializationPrefix) / sizeof(char) - 1; 14 sizeof(kInsanceIDSerializationPrefix) / sizeof(char) - 1;
15 } // namespace 15 } // namespace
16 16
17 // static 17 // static
18 scoped_ptr<RegistrationInfo> RegistrationInfo::BuildFromString( 18 scoped_ptr<RegistrationInfo> RegistrationInfo::BuildFromString(
19 const std::string& serialzied_key, 19 const std::string& serialzied_key,
20 const std::string& serialzied_value, 20 const std::string& serialzied_value,
21 std::string* registration_id) { 21 std::string* registration_id) {
22 scoped_ptr<RegistrationInfo> registration; 22 scoped_ptr<RegistrationInfo> registration;
23 23
24 if (StartsWithASCII(serialzied_key, kInsanceIDSerializationPrefix, true)) 24 if (base::StartsWithASCII(serialzied_key, kInsanceIDSerializationPrefix,
25 true))
25 registration.reset(new InstanceIDTokenInfo); 26 registration.reset(new InstanceIDTokenInfo);
26 else 27 else
27 registration.reset(new GCMRegistrationInfo); 28 registration.reset(new GCMRegistrationInfo);
28 29
29 if (!registration->Deserialize(serialzied_key, 30 if (!registration->Deserialize(serialzied_key,
30 serialzied_value, 31 serialzied_value,
31 registration_id)) { 32 registration_id)) {
32 registration.reset(); 33 registration.reset();
33 } 34 }
34 return registration.Pass(); 35 return registration.Pass();
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 return registration_id; 176 return registration_id;
176 } 177 }
177 178
178 bool InstanceIDTokenInfo::Deserialize( 179 bool InstanceIDTokenInfo::Deserialize(
179 const std::string& serialized_key, 180 const std::string& serialized_key,
180 const std::string& serialized_value, 181 const std::string& serialized_value,
181 std::string* registration_id) { 182 std::string* registration_id) {
182 if (serialized_key.empty() || serialized_value.empty()) 183 if (serialized_key.empty() || serialized_value.empty())
183 return false; 184 return false;
184 185
185 if (!StartsWithASCII(serialized_key, kInsanceIDSerializationPrefix, true)) 186 if (!base::StartsWithASCII(serialized_key, kInsanceIDSerializationPrefix,
187 true))
186 return false; 188 return false;
187 189
188 std::vector<std::string> fields; 190 std::vector<std::string> fields;
189 Tokenize(serialized_key.substr(kInsanceIDSerializationPrefixLength), 191 Tokenize(serialized_key.substr(kInsanceIDSerializationPrefixLength),
190 ",", 192 ",",
191 &fields); 193 &fields);
192 if (fields.size() != 3 || fields[0].empty() || 194 if (fields.size() != 3 || fields[0].empty() ||
193 fields[1].empty() || fields[2].empty()) { 195 fields[1].empty() || fields[2].empty()) {
194 return false; 196 return false;
195 } 197 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 244
243 bool ExistsGCMRegistrationInMap(const RegistrationInfoMap& map, 245 bool ExistsGCMRegistrationInMap(const RegistrationInfoMap& map,
244 const std::string& app_id) { 246 const std::string& app_id) {
245 scoped_ptr<GCMRegistrationInfo> gcm_registration(new GCMRegistrationInfo); 247 scoped_ptr<GCMRegistrationInfo> gcm_registration(new GCMRegistrationInfo);
246 gcm_registration->app_id = app_id; 248 gcm_registration->app_id = app_id;
247 return map.count( 249 return map.count(
248 make_linked_ptr<RegistrationInfo>(gcm_registration.release())) > 0; 250 make_linked_ptr<RegistrationInfo>(gcm_registration.release())) > 0;
249 } 251 }
250 252
251 } // namespace gcm 253 } // namespace gcm
OLDNEW
« no previous file with comments | « components/favicon/core/favicon_driver_impl.cc ('k') | components/google/core/browser/google_url_tracker.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698