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"
11 RegistrationInfo::RegistrationInfo() {
14 RegistrationInfo::~RegistrationInfo() {
17 std::string
RegistrationInfo::SerializeAsString() const {
18 if (sender_ids
.empty() || registration_id
.empty())
22 // sender1,sender2,...=reg_id
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
);
34 DCHECK(registration_id
.find('=') == std::string::npos
);
36 value
+= registration_id
;
40 bool RegistrationInfo::ParseFromString(const std::string
& value
) {
44 size_t pos
= value
.find('=');
45 if (pos
== std::string::npos
)
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()) {
55 registration_id
.clear();