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

Side by Side Diff: google_apis/gcm/engine/registration_info.cc

Issue 1137463003: Support getting and deleting token for Instance ID. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch to land 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
(Empty)
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.
4
5 #include "google_apis/gcm/engine/registration_info.h"
6
7 #include "base/strings/string_util.h"
8
9 namespace gcm {
10
11 RegistrationInfo::RegistrationInfo() {
12 }
13
14 RegistrationInfo::~RegistrationInfo() {
15 }
16
17 std::string RegistrationInfo::SerializeAsString() const {
18 if (sender_ids.empty() || registration_id.empty())
19 return std::string();
20
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;
32 }
33
34 DCHECK(registration_id.find('=') == std::string::npos);
35 value += '=';
36 value += registration_id;
37 return value;
38 }
39
40 bool RegistrationInfo::ParseFromString(const std::string& value) {
41 if (value.empty())
42 return true;
43
44 size_t pos = value.find('=');
45 if (pos == std::string::npos)
46 return false;
47
48 std::string senders = value.substr(0, pos);
49 registration_id = value.substr(pos + 1);
50
51 Tokenize(senders, ",", &sender_ids);
52
53 if (sender_ids.empty() || registration_id.empty()) {
54 sender_ids.clear();
55 registration_id.clear();
56 return false;
57 }
58
59 return true;
60 }
61
62 } // namespace gcm
OLDNEW
« no previous file with comments | « google_apis/gcm/engine/registration_info.h ('k') | google_apis/gcm/engine/registration_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698