Index: services/authentication/auth_data.cc |
diff --git a/services/authentication/auth_data.cc b/services/authentication/auth_data.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8ae7f9d1dcaafe51ae5ae7a8866e2aeb9427f938 |
--- /dev/null |
+++ b/services/authentication/auth_data.cc |
@@ -0,0 +1,54 @@ |
+// Copyright 2015 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 "services/authentication/auth_data.h" |
+ |
+#include <vector> |
+ |
+#include "base/logging.h" |
+#include "base/strings/string_split.h" |
+ |
+namespace authentication { |
+ |
+const char kAuthDataSeparator = ','; |
+ |
+AuthData::AuthData() = default; |
+ |
+AuthData::~AuthData() = default; |
+ |
+std::string GetAuthDataAsString(const AuthData& auth_data) { |
+ std::string str; |
+ |
+ str += auth_data.username; |
+ str += kAuthDataSeparator + auth_data.auth_provider; |
+ str += kAuthDataSeparator + auth_data.persistent_credential_type; |
+ str += kAuthDataSeparator + auth_data.persistent_credential; |
+ str += kAuthDataSeparator + auth_data.scopes; |
+ |
+ return str; |
+} |
+ |
+AuthData* GetAuthDataFromString(const std::string& auth_str) { |
+ if (auth_str.empty()) { |
+ return nullptr; |
+ } |
+ |
+ std::vector<std::string> auth_components; |
+ base::SplitString(auth_str, kAuthDataSeparator, &auth_components); |
+ if (auth_components.size() != 5) { |
+ LOG(WARNING) << "Unexpected response: " + auth_str; |
+ return nullptr; |
+ } |
+ |
+ AuthData* auth_data = new AuthData(); |
+ auth_data->username = auth_components[0]; |
+ auth_data->auth_provider = auth_components[1]; |
+ auth_data->persistent_credential_type = auth_components[2]; |
+ auth_data->persistent_credential = auth_components[3]; |
+ auth_data->scopes = auth_components[4]; |
+ |
+ return auth_data; |
+} |
+ |
+} // authentication namespace |