1 // Copyright (c) 2012 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. 4 5 #ifndef CHROME_BROWSER_SIGNIN_SIGNIN_INTERNALS_UTIL_H_ 6 #define CHROME_BROWSER_SIGNIN_SIGNIN_INTERNALS_UTIL_H_ 7 8 #include <map> 9 #include <string> 10 11 #include "base/memory/scoped_ptr.h" 12 #include "base/values.h" 13 14 namespace signin_internals_util { 15 16 // Preference prefixes for signin and token values. 17 extern const char kSigninPrefPrefix[]; 18 extern const char kTokenPrefPrefix[]; 19 20 // The following tokens are not under the purview of TokenService. 21 extern const char kOperationsBaseToken[]; 22 extern const char kUserPolicySigninServiceToken[]; 23 extern const char kProfileDownloaderToken[]; 24 extern const char kObfuscatedGaiaIdFetcherToken[]; 25 extern const char kOAuth2MintTokenFlowToken[]; 26 extern const char* kTokenPrefsArray[]; 27 extern const size_t kNumTokenPrefs; 28 29 // Helper enums to access fields from SigninStatus (declared below). 30 enum { 31 SIGNIN_FIELDS_BEGIN = 0, 32 UNTIMED_FIELDS_BEGIN = SIGNIN_FIELDS_BEGIN 33 }; 34 35 enum UntimedSigninStatusField { 36 USERNAME = UNTIMED_FIELDS_BEGIN, 37 SID, 38 LSID, 39 UNTIMED_FIELDS_END 40 }; 41 42 enum { 43 UNTIMED_FIELDS_COUNT = UNTIMED_FIELDS_END - UNTIMED_FIELDS_BEGIN, 44 TIMED_FIELDS_BEGIN = UNTIMED_FIELDS_END 45 }; 46 47 enum TimedSigninStatusField { 48 SIGNIN_TYPE = TIMED_FIELDS_BEGIN, 49 CLIENT_LOGIN_STATUS, 50 OAUTH_LOGIN_STATUS, 51 GET_USER_INFO_STATUS, 52 TIMED_FIELDS_END 53 }; 54 55 enum { 56 TIMED_FIELDS_COUNT = TIMED_FIELDS_END - TIMED_FIELDS_BEGIN, 57 SIGNIN_FIELDS_END = TIMED_FIELDS_END, 58 SIGNIN_FIELDS_COUNT = SIGNIN_FIELDS_END - SIGNIN_FIELDS_BEGIN 59 }; 60 61 // Encapsulates diagnostic information about tokens for different services. 62 // Note that although SigninStatus contains a map of service names to token 63 // values, we replicate the service name within this struct for a cleaner 64 // serialization (with ToValue()). 65 struct TokenInfo { 66 std::string token; // The actual token. 67 std::string status; // Status of the last token fetch. 68 std::string time; // Timestamp of the last token fetch 69 int64 time_internal; // Same as |time|, but in base::Time internal format. 70 std::string service; // The service that this token is for. 71 72 TokenInfo(const std::string& token, 73 const std::string& status, 74 const std::string& time, 75 const int64& time_internal, 76 const std::string& service); 77 TokenInfo(); 78 ~TokenInfo(); 79 80 DictionaryValue* ToValue(); 81 }; 82 83 // Associates a service name with its token information. 84 typedef std::map<std::string, TokenInfo> TokenInfoMap; 85 86 // Returns the root preference path for the service. The path should be 87 // qualified with one of .value, .status or .time to get the respective 88 // full preference path names. 89 std::string TokenPrefPath(const std::string& service_name); 90 91 // Many values in SigninStatus are also associated with a timestamp. 92 // This makes it easier to keep values and their associated times together. 93 typedef std::pair<std::string, std::string> TimedSigninStatusValue; 94 95 // Returns the name of a SigninStatus field. 96 std::string SigninStatusFieldToString(UntimedSigninStatusField field); 97 std::string SigninStatusFieldToString(TimedSigninStatusField field); 98 99 // Encapsulates both authentication and token related information. Used 100 // by SigninInternals to maintain information that needs to be shown in 101 // the about:signin-internals page. 102 struct SigninStatus { 103 std::vector<std::string> untimed_signin_fields; 104 std::vector<TimedSigninStatusValue> timed_signin_fields; 105 TokenInfoMap token_info_map; 106 107 SigninStatus(); 108 ~SigninStatus(); 109 110 // Returns a dictionary with the following form: 111 // { "signin_info" : 112 // [ {"title": "Basic Information", 113 // "data": [List of {"label" : "foo-field", "value" : "foo"} elems] 114 // }, 115 // { "title": "Detailed Information", 116 // "data": [List of {"label" : "foo-field", "value" : "foo"} elems] 117 // }], 118 // "token_info" : 119 // [ List of {"name": "foo-name", "token" : "foo-token", 120 // "status": "foo_stat", "time" : "foo_time"} elems] 121 // } 122 scoped_ptr<DictionaryValue> ToValue(); 123 }; 124 125 // An Observer class for authentication and token diagnostic information. 126 class SigninDiagnosticsObserver { 127 public: 128 // Credentials and signin related changes. 129 virtual void NotifySigninValueChanged(const UntimedSigninStatusField& field, 130 const std::string& value) {} 131 virtual void NotifySigninValueChanged(const TimedSigninStatusField& field, 132 const std::string& value) {} 133 134 // Tokens and service related changes. 135 virtual void NotifyTokenReceivedSuccess(const std::string& token_name, 136 const std::string& token, 137 bool update_time) {} 138 virtual void NotifyTokenReceivedFailure(const std::string& token_name, 139 const std::string& error) {} 140 virtual void NotifyClearStoredToken(const std::string& token_name) {} 141 142 }; 143 144 } // namespace signin_internals_util 145 146 #endif // CHROME_BROWSER_SIGNIN_SIGNIN_INTERNALS_UTIL_H_ 147