66
77#include " base/json/values_util.h"
88#include " base/memory/weak_ptr.h"
9- #include " base/metrics/histogram_macros .h"
9+ #include " base/metrics/histogram_functions .h"
1010#include " base/values.h"
1111#include " chrome/browser/browser_process.h"
1212#include " chrome/browser/profiles/profile.h"
@@ -20,7 +20,6 @@ namespace {
2020const char kTokenHandlePref [] = " PasswordTokenHandle" ;
2121const char kTokenHandleStatusPref [] = " TokenHandleStatus" ;
2222const char kTokenHandleLastCheckedPref [] = " TokenHandleLastChecked" ;
23- const char kTokenHandleRotated [] = " TokenHandleRotated" ;
2423
2524const char kHandleStatusValid [] = " valid" ;
2625const char kHandleStatusInvalid [] = " invalid" ;
@@ -102,15 +101,6 @@ TokenHandleUtil::~TokenHandleUtil() = default;
102101// static
103102bool TokenHandleUtil::HasToken (const AccountId& account_id) {
104103 user_manager::KnownUser known_user (g_browser_process->local_state ());
105- bool token_rotated =
106- known_user.FindBoolPath (account_id, kTokenHandleRotated ).value_or (false );
107- if (!token_rotated && known_user.GetIsEnterpriseManaged (account_id)) {
108- // Ignore not rotated token starting from M94 for enterprise users to avoid
109- // blocking them on the login screen. Rotation started in M91.
110- ClearTokenHandle (account_id);
111- return false ;
112- }
113-
114104 const std::string* token =
115105 known_user.FindStringPath (account_id, kTokenHandlePref );
116106 return token && !token->empty ();
@@ -134,11 +124,7 @@ bool TokenHandleUtil::IsRecentlyChecked(const AccountId& account_id) {
134124
135125// static
136126bool TokenHandleUtil::ShouldObtainHandle (const AccountId& account_id) {
137- user_manager::KnownUser known_user (g_browser_process->local_state ());
138- bool token_rotated =
139- known_user.FindBoolPath (account_id, kTokenHandleRotated ).value_or (false );
140- return !HasToken (account_id) || HasTokenStatusInvalid (account_id) ||
141- !token_rotated;
127+ return !HasToken (account_id) || HasTokenStatusInvalid (account_id);
142128}
143129
144130// static
@@ -186,21 +172,10 @@ void TokenHandleUtil::StoreTokenHandle(const AccountId& account_id,
186172 known_user.SetStringPref (account_id, kTokenHandlePref , handle);
187173 known_user.SetStringPref (account_id, kTokenHandleStatusPref ,
188174 kHandleStatusValid );
189- known_user.SetBooleanPref (account_id, kTokenHandleRotated , true );
190175 known_user.SetPath (account_id, kTokenHandleLastCheckedPref ,
191176 base::TimeToValue (base::Time::Now ()));
192177}
193178
194- // static
195- void TokenHandleUtil::ClearTokenHandle (const AccountId& account_id) {
196- user_manager::KnownUser known_user (g_browser_process->local_state ());
197-
198- known_user.RemovePref (account_id, kTokenHandlePref );
199- known_user.RemovePref (account_id, kTokenHandleStatusPref );
200- known_user.RemovePref (account_id, kTokenHandleRotated );
201- known_user.RemovePref (account_id, kTokenHandleLastCheckedPref );
202- }
203-
204179// static
205180void TokenHandleUtil::SetInvalidTokenForTesting (const char * token) {
206181 g_invalid_token_for_testing = token;
@@ -237,18 +212,27 @@ TokenHandleUtil::TokenDelegate::~TokenDelegate() = default;
237212
238213void TokenHandleUtil::TokenDelegate::OnOAuthError () {
239214 std::move (callback_).Run (account_id_, INVALID);
240- NotifyDone ();
215+ NotifyDone (/* request_completed= */ true );
241216}
242217
243218// Warning: NotifyDone() deletes `this`
244- void TokenHandleUtil::TokenDelegate::NotifyDone () {
219+ void TokenHandleUtil::TokenDelegate::NotifyDone (bool request_completed) {
220+ if (request_completed) {
221+ RecordTokenCheckResponseTime ();
222+ }
245223 if (owner_)
246224 owner_->OnValidationComplete (token_);
247225}
248226
249227void TokenHandleUtil::TokenDelegate::OnNetworkError (int response_code) {
250228 std::move (callback_).Run (account_id_, UNKNOWN);
251- NotifyDone ();
229+ NotifyDone (/* request_completed=*/ response_code != -1 );
230+ }
231+
232+ void TokenHandleUtil::TokenDelegate::RecordTokenCheckResponseTime () {
233+ const base::TimeDelta duration =
234+ base::TimeTicks::Now () - tokeninfo_response_start_time_;
235+ base::UmaHistogramTimes (" Login.TokenCheckResponseTime" , duration);
252236}
253237
254238void TokenHandleUtil::TokenDelegate::OnGetTokenInfoResponse (
@@ -260,11 +244,8 @@ void TokenHandleUtil::TokenDelegate::OnGetTokenInfoResponse(
260244 outcome = (*expires_in < 0 ) ? INVALID : VALID;
261245 }
262246
263- const base::TimeDelta duration =
264- base::TimeTicks::Now () - tokeninfo_response_start_time_;
265- UMA_HISTOGRAM_TIMES (" Login.TokenCheckResponseTime" , duration);
266247 std::move (callback_).Run (account_id_, outcome);
267- NotifyDone ();
248+ NotifyDone (/* request_completed= */ true );
268249}
269250
270251} // namespace ash
0 commit comments