Chromium Code Reviews| 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..8aa2a64fe08c7f87c3006917d987aeb1ab661a20 |
| --- /dev/null |
| +++ b/services/authentication/auth_data.cc |
| @@ -0,0 +1,57 @@ |
| +// 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 = ','; |
|
qsr
2016/02/16 14:17:06
Why is it safe? Do we have guarantees that it will
ukode
2016/02/26 21:35:50
Got rid of this completely. Instead using a mojom
|
| + |
| +AuthData::AuthData() = default; |
| + |
| +AuthData::~AuthData() = default; |
| + |
| +// Serializes auth data as a string with auth components delimited by ",". |
| +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; |
| +} |
| + |
| +// Deserializes auth data from an input string with the following pattern: |
| +// "test@gmail.com,Google,RT,1/2345abcedef,profile email" |
| +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 |