-
-
Save balazs/cb1ceb69c4306a5c0993 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/components/gwclient_driver/push_messaging_registration_info_helper.cc b/components/gwclient_driver/push_messaging_registration_info_helper.cc | |
new file mode 100644 | |
index 0000000..63dbf3d | |
--- /dev/null | |
+++ b/components/gwclient_driver/push_messaging_registration_info_helper.cc | |
@@ -0,0 +1,91 @@ | |
+// TODO: licence | |
+ | |
+#include "components/gwclient_driver/push_messaging_registration_info_helper.h" | |
+ | |
+#include "base/logging.h" | |
+ | |
+// Temporary... | |
+#if !defined(S_NATIVE_SUPPORT) | |
+#define S_NATIVE_SUPPORT 1 | |
+#endif | |
+ | |
+#if defined S_NATIVE_SUPPORT | |
+namespace { | |
+ | |
+const char kSeparator = '%'; | |
+ | |
+std::string EscapeSeparator(const std::string& input) { | |
+ std::string output; | |
+ for (char c : input) { | |
+ output += c; | |
+ if (c == kSeparator) { | |
+ output += c; | |
+ } | |
+ } | |
+ return output; | |
+} | |
+ | |
+std::string UnescapePart(std::string::const_iterator begin, | |
+ std::string::const_iterator end) { | |
+ std::string out; | |
+ for (std::string::const_iterator i = begin; i < end; ++i) { | |
+ if (*i == kSeparator) | |
+ ++i; | |
+ else | |
+ out.append(*i); | |
+ } | |
+ return out; | |
+} | |
+ | |
+// Returns pair of first part and second part unescaped. | |
+std::pair<std::string, std::string> Unescape(const std::string& input) { | |
+// std::string out1; | |
+// std::string second; | |
+ | |
+ size_t size = input.size(); | |
+ for (size_t i = 0; i < size; ++i) { | |
+ if (input[i] == kSeparator) { | |
+// if (i == (size - 1)) { | |
+// // Corner case, second part is empty. | |
+// return std::make_pair(out1, std::string()); | |
+// } | |
+ if (input[i + 1] != kSeparator) { | |
+ return std::make_pair( | |
+ UnescapePart(input.begin(), input.begin() + i), | |
+ UnescapePart(input.begin() + i + 1, input.end())); | |
+ } else { | |
+ ++i; | |
+ } | |
+ } | |
+ | |
+ NOTREACHED(); | |
+ } | |
+} | |
+ | |
+} | |
+#endif // S_NATIVE_SUPPORT | |
+ | |
+std::string& GeneratePersistentDataForRegistration( | |
+ content::PushMessagingService* push_service, | |
+ const std::string& registration_id, | |
+ const GURL& endpoint) { | |
+#if !defined(S_NATIVE_SUPPORT) | |
+ return registration_id; | |
+#else | |
+ return EscapeSeparator(registration_id).append(1, kSeparator) | |
+ .append(EscapeSeparator(endpoint)); | |
+#endif | |
+} | |
+ | |
+RegistrationInfo GetRegistrationInfoFromPersistentData( | |
+ content::PushMessagingService* push_service, | |
+ const std::string& data) { | |
+#if !defined(S_NATIVE_SUPPORT) | |
+ const std::string& registration_id = data; | |
+ const GURL& endpoint = push_service->GetEndpoint(); | |
+ return { registration_id, endpoint }; | |
+#else | |
+ | |
+#endif | |
+} | |
+ | |
diff --git a/components/gwclient_driver/push_messaging_registration_info_helper.h b/components/gwclient_driver/push_messaging_registration_info_helper.h | |
new file mode 100644 | |
index 0000000..708279d | |
--- /dev/null | |
+++ b/components/gwclient_driver/push_messaging_registration_info_helper.h | |
@@ -0,0 +1,26 @@ | |
+// TODO: licence | |
+ | |
+#ifndef COMPONENTS_GWCLIENT_DRIVER_PUSH_MEASSAGING_REGISTRATION_INFO_HELPER_ | |
+#define COMPONENTS_GWCLIENT_DRIVER_PUSH_MEASSAGING_REGISTRATION_INFO_HELPER_ | |
+ | |
+#include "url/gurl.h" | |
+ | |
+namespace content { | |
+class PushMessagingService; | |
+} | |
+ | |
+struct RegistrationInfo { | |
+ std::string registration_id; | |
+ GURL url; | |
+}; | |
+ | |
+std::string& GeneratePersistentDataForRegistration( | |
+ content::PushMessagingService* push_service, | |
+ const std::string& registration_id, | |
+ const GURL& endpoint); | |
+ | |
+RegistrationInfo GetRegistrationInfoFromPersistentData( | |
+ content::PushMessagingService* push_service, | |
+ const std::string& data); | |
+ | |
+#endif // COMPONENTS_GWCLIENT_DRIVER_PUSH_MEASSAGING_REGISTRATION_INFO_HELPER_ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment