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

Unified Diff: google_apis/gcm/engine/registration_info.cc

Issue 207443002: [GCM] Move registration info persistence from extension state store to GCM store (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch to land Created 6 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « google_apis/gcm/engine/registration_info.h ('k') | google_apis/gcm/gcm.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: google_apis/gcm/engine/registration_info.cc
diff --git a/google_apis/gcm/engine/registration_info.cc b/google_apis/gcm/engine/registration_info.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6a41c76e00e2fdeb42f62bcd63b574d848fa942e
--- /dev/null
+++ b/google_apis/gcm/engine/registration_info.cc
@@ -0,0 +1,62 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "google_apis/gcm/engine/registration_info.h"
+
+#include "base/strings/string_util.h"
+
+namespace gcm {
+
+RegistrationInfo::RegistrationInfo() {
+}
+
+RegistrationInfo::~RegistrationInfo() {
+}
+
+std::string RegistrationInfo::SerializeAsString() const {
+ if (sender_ids.empty() || registration_id.empty())
+ return std::string();
+
+ // Serialize as:
+ // sender1,sender2,...=reg_id
+ std::string value;
+ for (std::vector<std::string>::const_iterator iter = sender_ids.begin();
+ iter != sender_ids.end(); ++iter) {
+ DCHECK(!iter->empty() &&
+ iter->find(',') == std::string::npos &&
+ iter->find('=') == std::string::npos);
+ if (!value.empty())
+ value += ",";
+ value += *iter;
+ }
+
+ DCHECK(registration_id.find('=') == std::string::npos);
+ value += '=';
+ value += registration_id;
+ return value;
+}
+
+bool RegistrationInfo::ParseFromString(const std::string& value) {
+ if (value.empty())
+ return true;
+
+ size_t pos = value.find('=');
+ if (pos == std::string::npos)
+ return false;
+
+ std::string senders = value.substr(0, pos);
+ registration_id = value.substr(pos + 1);
+
+ Tokenize(senders, ",", &sender_ids);
+
+ if (sender_ids.empty() || registration_id.empty()) {
+ sender_ids.clear();
+ registration_id.clear();
+ return false;
+ }
+
+ return true;
+}
+
+} // namespace gcm
« no previous file with comments | « google_apis/gcm/engine/registration_info.h ('k') | google_apis/gcm/gcm.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698