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 #ifndef COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_INTERNALS_UTIL_H_
6 #define COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_INTERNALS_UTIL_H_
11 #include "base/memory/scoped_ptr.h"
12 #include "base/values.h"
14 namespace signin_internals_util
{
16 // Preference prefixes for signin and token values.
17 extern const char kSigninPrefPrefix
[];
18 extern const char kTokenPrefPrefix
[];
20 // The length of strings returned by GetTruncatedHash() below.
21 const size_t kTruncateTokenStringLength
= 6;
23 // Helper enums to access fields from SigninStatus (declared below).
25 SIGNIN_FIELDS_BEGIN
= 0,
26 UNTIMED_FIELDS_BEGIN
= SIGNIN_FIELDS_BEGIN
29 enum UntimedSigninStatusField
{
30 ACCOUNT_ID
= UNTIMED_FIELDS_BEGIN
,
37 UNTIMED_FIELDS_COUNT
= UNTIMED_FIELDS_END
- UNTIMED_FIELDS_BEGIN
,
38 TIMED_FIELDS_BEGIN
= UNTIMED_FIELDS_END
41 enum TimedSigninStatusField
{
42 AUTHENTICATION_RESULT_RECEIVED
= TIMED_FIELDS_BEGIN
,
43 REFRESH_TOKEN_RECEIVED
,
50 TIMED_FIELDS_COUNT
= TIMED_FIELDS_END
- TIMED_FIELDS_BEGIN
,
51 SIGNIN_FIELDS_END
= TIMED_FIELDS_END
,
52 SIGNIN_FIELDS_COUNT
= SIGNIN_FIELDS_END
- SIGNIN_FIELDS_BEGIN
55 // Returns the root preference path for the service. The path should be
56 // qualified with one of .value, .status or .time to get the respective
57 // full preference path names.
58 std::string
TokenPrefPath(const std::string
& service_name
);
60 // Returns the name of a SigninStatus field.
61 std::string
SigninStatusFieldToString(UntimedSigninStatusField field
);
62 std::string
SigninStatusFieldToString(TimedSigninStatusField field
);
64 // An Observer class for authentication and token diagnostic information.
65 class SigninDiagnosticsObserver
{
67 // Credentials and signin related changes.
68 virtual void NotifySigninValueChanged(const TimedSigninStatusField
& field
,
69 const std::string
& value
) {}
70 // OAuth tokens related changes.
71 virtual void NotifyTokenReceivedSuccess(const std::string
& token_name
,
72 const std::string
& token
,
74 virtual void NotifyTokenReceivedFailure(const std::string
& token_name
,
75 const std::string
& error
) {}
76 virtual void NotifyClearStoredToken(const std::string
& token_name
) {}};
78 // Gets the first 6 hex characters of the SHA256 hash of the passed in string.
79 // These are enough to perform equality checks across a single users tokens,
80 // while preventing outsiders from reverse-engineering the actual token from
81 // the displayed value.
82 // Note that for readability (in about:signin-internals), an empty string
83 // is not hashed, but simply returned as an empty string.
84 std::string
GetTruncatedHash(const std::string
& str
);
86 } // namespace signin_internals_util
88 #endif // COMPONENTS_SIGNIN_CORE_BROWSER_SIGNIN_INTERNALS_UTIL_H_