[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / google_apis / gcm / engine / registration_info.cc
blob6a41c76e00e2fdeb42f62bcd63b574d848fa942e
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
3 // found in the LICENSE file.
5 #include "google_apis/gcm/engine/registration_info.h"
7 #include "base/strings/string_util.h"
9 namespace gcm {
11 RegistrationInfo::RegistrationInfo() {
14 RegistrationInfo::~RegistrationInfo() {
17 std::string RegistrationInfo::SerializeAsString() const {
18 if (sender_ids.empty() || registration_id.empty())
19 return std::string();
21 // Serialize as:
22 // sender1,sender2,...=reg_id
23 std::string value;
24 for (std::vector<std::string>::const_iterator iter = sender_ids.begin();
25 iter != sender_ids.end(); ++iter) {
26 DCHECK(!iter->empty() &&
27 iter->find(',') == std::string::npos &&
28 iter->find('=') == std::string::npos);
29 if (!value.empty())
30 value += ",";
31 value += *iter;
34 DCHECK(registration_id.find('=') == std::string::npos);
35 value += '=';
36 value += registration_id;
37 return value;
40 bool RegistrationInfo::ParseFromString(const std::string& value) {
41 if (value.empty())
42 return true;
44 size_t pos = value.find('=');
45 if (pos == std::string::npos)
46 return false;
48 std::string senders = value.substr(0, pos);
49 registration_id = value.substr(pos + 1);
51 Tokenize(senders, ",", &sender_ids);
53 if (sender_ids.empty() || registration_id.empty()) {
54 sender_ids.clear();
55 registration_id.clear();
56 return false;
59 return true;
62 } // namespace gcm