Fix infinite recursion on hiding panel when created during fullscreen mode.
[chromium-blink-merge.git] / components / signin / core / browser / signin_internals_util.cc
blobc16f92ad317670968da8c06cd5d065eb44d2e0d9
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.
5 #include "components/signin/core/browser/signin_internals_util.h"
7 #include <sstream>
9 #include "base/logging.h"
10 #include "base/strings/string_number_conversions.h"
11 #include "base/strings/string_util.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "crypto/sha2.h"
14 #include "google_apis/gaia/gaia_constants.h"
16 namespace signin_internals_util {
18 const char kSigninPrefPrefix[] = "google.services.signin.";
19 const char kTokenPrefPrefix[] = "google.services.signin.tokens.";
21 #define ENUM_CASE(x) case x: return (std::string(kSigninPrefPrefix) + #x)
22 std::string SigninStatusFieldToString(UntimedSigninStatusField field) {
23 switch (field) {
24 ENUM_CASE(USERNAME);
25 case UNTIMED_FIELDS_END:
26 NOTREACHED();
27 return std::string();
30 NOTREACHED();
31 return std::string();
34 std::string SigninStatusFieldToString(TimedSigninStatusField field) {
35 switch (field) {
36 ENUM_CASE(SIGNIN_TYPE);
37 ENUM_CASE(CLIENT_LOGIN_STATUS);
38 ENUM_CASE(OAUTH_LOGIN_STATUS);
39 ENUM_CASE(GET_USER_INFO_STATUS);
40 ENUM_CASE(UBER_TOKEN_STATUS);
41 ENUM_CASE(MERGE_SESSION_STATUS);
42 case TIMED_FIELDS_END:
43 NOTREACHED();
44 return std::string();
47 NOTREACHED();
48 return std::string();
51 std::string TokenPrefPath(const std::string& token_name) {
52 return std::string(kTokenPrefPrefix) + token_name;
55 // Gets the first few hex characters of the SHA256 hash of the passed in string.
56 // These are enough to perform equality checks across a single users tokens,
57 // while preventing outsiders from reverse-engineering the actual token from
58 // the displayed value.
59 // Note that for readability (in about:signin-internals), an empty string
60 // is not hashed, but simply returned as an empty string.
61 std::string GetTruncatedHash(const std::string& str) {
62 if (str.empty())
63 return str;
65 // Since each character in the hash string generates two hex charaters
66 // we only need half as many charaters in |hash_val| as hex characters
67 // returned.
68 const int kTruncateSize = kTruncateTokenStringLength / 2;
69 char hash_val[kTruncateSize];
70 crypto::SHA256HashString(str, &hash_val[0], kTruncateSize);
71 return StringToLowerASCII(base::HexEncode(&hash_val[0], kTruncateSize));
74 } // namespace signin_internals_util