Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(834)

Side by Side Diff: chrome/browser/signin/about_signin_internals.cc

Issue 14888003: [Sync] Log age of auth tokens on authentication failure (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/signin/about_signin_internals.h" 5 #include "chrome/browser/signin/about_signin_internals.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "base/hash.h" 8 #include "base/hash.h"
9 #include "base/i18n/time_formatting.h" 9 #include "base/i18n/time_formatting.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/utf_string_conversions.h" 12 #include "base/utf_string_conversions.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/signin/signin_internals_util.h" 14 #include "chrome/browser/signin/signin_internals_util.h"
15 #include "chrome/browser/signin/signin_manager.h" 15 #include "chrome/browser/signin/signin_manager.h"
16 #include "chrome/browser/signin/token_service.h" 16 #include "chrome/browser/signin/token_service.h"
17 #include "chrome/browser/signin/token_service_factory.h" 17 #include "chrome/browser/signin/token_service_factory.h"
18 #include "chrome/browser/ui/webui/signin_internals_ui.h" 18 #include "chrome/browser/ui/webui/signin_internals_ui.h"
19 #include "google_apis/gaia/gaia_constants.h" 19 #include "google_apis/gaia/gaia_constants.h"
20 20
21 using base::Time;
21 using namespace signin_internals_util; 22 using namespace signin_internals_util;
22 23
23 AboutSigninInternals::AboutSigninInternals() : profile_(NULL) { 24 AboutSigninInternals::AboutSigninInternals() : profile_(NULL) {
24 // Initialize default values for tokens. 25 // Initialize default values for tokens.
25 for (size_t i = 0; i < kNumTokenPrefs; ++i) { 26 for (size_t i = 0; i < kNumTokenPrefs; ++i) {
26 signin_status_.token_info_map.insert(std::pair<std::string, TokenInfo>( 27 signin_status_.token_info_map.insert(std::pair<std::string, TokenInfo>(
27 kTokenPrefsArray[i], 28 kTokenPrefsArray[i],
28 TokenInfo( 29 TokenInfo(std::string(), "Not Loaded", std::string(), 0,
29 std::string(), "Not Loaded", std::string(), kTokenPrefsArray[i]))); 30 kTokenPrefsArray[i])));
30 } 31 }
31 } 32 }
32 33
33 AboutSigninInternals::~AboutSigninInternals() { 34 AboutSigninInternals::~AboutSigninInternals() {
34 } 35 }
35 36
36 void AboutSigninInternals::AddSigninObserver( 37 void AboutSigninInternals::AddSigninObserver(
37 AboutSigninInternals::Observer* observer) { 38 AboutSigninInternals::Observer* observer) {
38 signin_observers_.AddObserver(observer); 39 signin_observers_.AddObserver(observer);
39 } 40 }
(...skipping 19 matching lines...) Expand all
59 NotifyObservers(); 60 NotifyObservers();
60 } 61 }
61 62
62 void AboutSigninInternals::NotifySigninValueChanged( 63 void AboutSigninInternals::NotifySigninValueChanged(
63 const TimedSigninStatusField& field, 64 const TimedSigninStatusField& field,
64 const std::string& value) { 65 const std::string& value) {
65 unsigned int field_index = field - TIMED_FIELDS_BEGIN; 66 unsigned int field_index = field - TIMED_FIELDS_BEGIN;
66 DCHECK(field_index >= 0 && 67 DCHECK(field_index >= 0 &&
67 field_index < signin_status_.timed_signin_fields.size()); 68 field_index < signin_status_.timed_signin_fields.size());
68 69
69 std::string time_as_str = UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime( 70 Time now = Time::NowFromSystemTime();
70 base::Time::NowFromSystemTime())); 71 std::string time_as_str = UTF16ToUTF8(base::TimeFormatFriendlyDate(now));
71 TimedSigninStatusValue timed_value(value, time_as_str); 72 TimedSigninStatusValue timed_value(value, time_as_str);
72 73
73 signin_status_.timed_signin_fields[field_index] = timed_value; 74 signin_status_.timed_signin_fields[field_index] = timed_value;
74 75
75 // Also persist these values in the prefs. 76 // Also persist these values in the prefs.
76 const std::string value_pref = SigninStatusFieldToString(field) + ".value"; 77 const std::string value_pref = SigninStatusFieldToString(field) + ".value";
77 const std::string time_pref = SigninStatusFieldToString(field) + ".time"; 78 const std::string time_pref = SigninStatusFieldToString(field) + ".time";
78 profile_->GetPrefs()->SetString(value_pref.c_str(), value); 79 profile_->GetPrefs()->SetString(value_pref.c_str(), value);
79 profile_->GetPrefs()->SetString(time_pref.c_str(), time_as_str); 80 profile_->GetPrefs()->SetString(time_pref.c_str(), time_as_str);
80 81
81 NotifyObservers(); 82 NotifyObservers();
82 } 83 }
83 84
84 void AboutSigninInternals::RefreshSigninPrefs() { 85 void AboutSigninInternals::RefreshSigninPrefs() {
85 // Return if no profile exists. Can occur in unit tests. 86 // Return if no profile exists. Can occur in unit tests.
86 if (!profile_) 87 if (!profile_)
87 return; 88 return;
(...skipping 16 matching lines...) Expand all
104 pref_service->GetString(time_pref.c_str())); 105 pref_service->GetString(time_pref.c_str()));
105 signin_status_.timed_signin_fields[i - TIMED_FIELDS_BEGIN] = value; 106 signin_status_.timed_signin_fields[i - TIMED_FIELDS_BEGIN] = value;
106 } 107 }
107 108
108 // Get status and timestamps for all token services. 109 // Get status and timestamps for all token services.
109 for (size_t i = 0; i < kNumTokenPrefs; i++) { 110 for (size_t i = 0; i < kNumTokenPrefs; i++) {
110 const std::string pref = TokenPrefPath(kTokenPrefsArray[i]); 111 const std::string pref = TokenPrefPath(kTokenPrefsArray[i]);
111 const std::string value = pref + ".value"; 112 const std::string value = pref + ".value";
112 const std::string status = pref + ".status"; 113 const std::string status = pref + ".status";
113 const std::string time = pref + ".time"; 114 const std::string time = pref + ".time";
115 const std::string time_internal = pref + ".time_internal";
114 116
115 TokenInfo token_info(pref_service->GetString(value.c_str()), 117 TokenInfo token_info(pref_service->GetString(value.c_str()),
116 pref_service->GetString(status.c_str()), 118 pref_service->GetString(status.c_str()),
117 pref_service->GetString(time.c_str()), 119 pref_service->GetString(time.c_str()),
120 pref_service->GetInt64(time_internal.c_str()),
118 kTokenPrefsArray[i]); 121 kTokenPrefsArray[i]);
119 122
120 signin_status_.token_info_map[kTokenPrefsArray[i]] = token_info; 123 signin_status_.token_info_map[kTokenPrefsArray[i]] = token_info;
121 } 124 }
122 125
123 NotifyObservers(); 126 NotifyObservers();
124 } 127 }
125 128
126 void AboutSigninInternals::NotifyTokenReceivedSuccess( 129 void AboutSigninInternals::NotifyTokenReceivedSuccess(
127 const std::string& token_name, 130 const std::string& token_name,
128 const std::string& token, 131 const std::string& token,
129 bool update_time) { 132 bool update_time) {
130 // This should have been initialized already. 133 // This should have been initialized already.
131 DCHECK(signin_status_.token_info_map.count(token_name)); 134 DCHECK(signin_status_.token_info_map.count(token_name));
132 135
133 const std::string status_success = "Successful"; 136 const std::string status_success = "Successful";
134 signin_status_.token_info_map[token_name].token = token; 137 signin_status_.token_info_map[token_name].token = token;
135 signin_status_.token_info_map[token_name].status = status_success; 138 signin_status_.token_info_map[token_name].status = status_success;
136 139
137 // Also update preferences. 140 // Also update preferences.
138 const std::string value_pref = TokenPrefPath(token_name) + ".value"; 141 const std::string value_pref = TokenPrefPath(token_name) + ".value";
139 const std::string time_pref = TokenPrefPath(token_name) + ".time"; 142 const std::string time_pref = TokenPrefPath(token_name) + ".time";
143 const std::string time_internal_pref =
144 TokenPrefPath(token_name) + ".time_internal";
140 const std::string status_pref = TokenPrefPath(token_name) + ".status"; 145 const std::string status_pref = TokenPrefPath(token_name) + ".status";
141 profile_->GetPrefs()->SetString(value_pref.c_str(), token); 146 profile_->GetPrefs()->SetString(value_pref.c_str(), token);
142 profile_->GetPrefs()->SetString(status_pref.c_str(), "Successful"); 147 profile_->GetPrefs()->SetString(status_pref.c_str(), "Successful");
143 148
144 // Update timestamp if needed. 149 // Update timestamp if needed.
145 if (update_time) { 150 if (update_time) {
146 const std::string time_as_str = UTF16ToUTF8( 151 Time now = Time::NowFromSystemTime();
147 base::TimeFormatFriendlyDateAndTime(base::Time::NowFromSystemTime())); 152 int64 time_as_int = now.ToInternalValue();
153 const std::string time_as_str =
154 UTF16ToUTF8(base::TimeFormatFriendlyDate(now));
148 signin_status_.token_info_map[token_name].time = time_as_str; 155 signin_status_.token_info_map[token_name].time = time_as_str;
156 signin_status_.token_info_map[token_name].time_internal = time_as_int;
149 profile_->GetPrefs()->SetString(time_pref.c_str(), time_as_str); 157 profile_->GetPrefs()->SetString(time_pref.c_str(), time_as_str);
158 profile_->GetPrefs()->SetInt64(time_internal_pref.c_str(), time_as_int);
150 } 159 }
151 160
152 NotifyObservers(); 161 NotifyObservers();
153 } 162 }
154 163
155 164
156 void AboutSigninInternals::NotifyTokenReceivedFailure( 165 void AboutSigninInternals::NotifyTokenReceivedFailure(
157 const std::string& token_name, 166 const std::string& token_name,
158 const std::string& error) { 167 const std::string& error) {
168 Time now = Time::NowFromSystemTime();
169 int64 time_as_int = now.ToInternalValue();
159 const std::string time_as_str = 170 const std::string time_as_str =
160 UTF16ToUTF8(base::TimeFormatFriendlyDateAndTime( 171 UTF16ToUTF8(base::TimeFormatFriendlyDate(now));
161 base::Time::NowFromSystemTime()));
162 172
163 // This should have been initialized already. 173 // This should have been initialized already.
164 DCHECK(signin_status_.token_info_map.count(token_name)); 174 DCHECK(signin_status_.token_info_map.count(token_name));
165 175
166 signin_status_.token_info_map[token_name].token.clear(); 176 signin_status_.token_info_map[token_name].token.clear();
167 signin_status_.token_info_map[token_name].status = error; 177 signin_status_.token_info_map[token_name].status = error;
168 signin_status_.token_info_map[token_name].time = time_as_str; 178 signin_status_.token_info_map[token_name].time = time_as_str;
179 signin_status_.token_info_map[token_name].time_internal = time_as_int;
169 180
170 // Also update preferences. 181 // Also update preferences.
171 const std::string value_pref = TokenPrefPath(token_name) + ".value"; 182 const std::string value_pref = TokenPrefPath(token_name) + ".value";
172 const std::string time_pref = TokenPrefPath(token_name) + ".time"; 183 const std::string time_pref = TokenPrefPath(token_name) + ".time";
184 const std::string time_internal_pref =
185 TokenPrefPath(token_name) + ".time_internal";
173 const std::string status_pref = TokenPrefPath(token_name) + ".status"; 186 const std::string status_pref = TokenPrefPath(token_name) + ".status";
174 profile_->GetPrefs()->SetString(value_pref.c_str(), std::string()); 187 profile_->GetPrefs()->SetString(value_pref.c_str(), std::string());
175 profile_->GetPrefs()->SetString(time_pref.c_str(), time_as_str); 188 profile_->GetPrefs()->SetString(time_pref.c_str(), time_as_str);
189 profile_->GetPrefs()->SetInt64(time_internal_pref.c_str(), time_as_int);
176 profile_->GetPrefs()->SetString(status_pref.c_str(), error); 190 profile_->GetPrefs()->SetString(status_pref.c_str(), error);
177 191
178 NotifyObservers(); 192 NotifyObservers();
179 } 193 }
180 194
181 // While clearing tokens, we don't update the time or status. 195 // While clearing tokens, we don't update the time or status.
182 void AboutSigninInternals::NotifyClearStoredToken( 196 void AboutSigninInternals::NotifyClearStoredToken(
183 const std::string& token_name) { 197 const std::string& token_name) {
184 // This should have been initialized already. 198 // This should have been initialized already.
185 DCHECK(signin_status_.token_info_map.count(token_name)); 199 DCHECK(signin_status_.token_info_map.count(token_name));
(...skipping 27 matching lines...) Expand all
213 227
214 void AboutSigninInternals::NotifyObservers() { 228 void AboutSigninInternals::NotifyObservers() {
215 FOR_EACH_OBSERVER(AboutSigninInternals::Observer, 229 FOR_EACH_OBSERVER(AboutSigninInternals::Observer,
216 signin_observers_, 230 signin_observers_,
217 OnSigninStateChanged(signin_status_.ToValue())); 231 OnSigninStateChanged(signin_status_.ToValue()));
218 } 232 }
219 233
220 scoped_ptr<DictionaryValue> AboutSigninInternals::GetSigninStatus() { 234 scoped_ptr<DictionaryValue> AboutSigninInternals::GetSigninStatus() {
221 return signin_status_.ToValue().Pass(); 235 return signin_status_.ToValue().Pass();
222 } 236 }
237
238 Time AboutSigninInternals::GetTokenTime(
239 const std::string& token_name) const {
240 TokenInfoMap::const_iterator iter =
241 signin_status_.token_info_map.find(token_name);
242 if (iter == signin_status_.token_info_map.end())
243 return base::Time();
244 return base::Time::FromInternalValue(iter->second.time_internal);
245 }
OLDNEW
« no previous file with comments | « chrome/browser/signin/about_signin_internals.h ('k') | chrome/browser/signin/about_signin_internals_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698