| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/chromeos/login/saml/saml_offline_signin_limiter.h" | 5 #include "chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/location.h" | 11 #include "base/location.h" |
| 12 #include "base/logging.h" | 12 #include "base/logging.h" |
| 13 #include "base/prefs/pref_service.h" | 13 #include "base/prefs/pref_service.h" |
| 14 #include "base/time/clock.h" | 14 #include "base/time/clock.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "chrome/browser/chromeos/login/users/user.h" | |
| 17 #include "chrome/browser/chromeos/login/users/user_manager.h" | 16 #include "chrome/browser/chromeos/login/users/user_manager.h" |
| 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 21 #include "components/pref_registry/pref_registry_syncable.h" | 20 #include "components/pref_registry/pref_registry_syncable.h" |
| 21 #include "components/user_manager/user.h" |
| 22 | 22 |
| 23 namespace chromeos { | 23 namespace chromeos { |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 const int kDefaultSAMLOfflineSigninTimeLimit = 14 * 24 * 60 * 60; // 14 days. | 27 const int kDefaultSAMLOfflineSigninTimeLimit = 14 * 24 * 60 * 60; // 14 days. |
| 28 | 28 |
| 29 } // namespace | 29 } // namespace |
| 30 | 30 |
| 31 // static | 31 // static |
| 32 void SAMLOfflineSigninLimiter::RegisterProfilePrefs( | 32 void SAMLOfflineSigninLimiter::RegisterProfilePrefs( |
| 33 user_prefs::PrefRegistrySyncable* registry) { | 33 user_prefs::PrefRegistrySyncable* registry) { |
| 34 registry->RegisterIntegerPref( | 34 registry->RegisterIntegerPref( |
| 35 prefs::kSAMLOfflineSigninTimeLimit, | 35 prefs::kSAMLOfflineSigninTimeLimit, |
| 36 kDefaultSAMLOfflineSigninTimeLimit, | 36 kDefaultSAMLOfflineSigninTimeLimit, |
| 37 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 37 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 38 registry->RegisterInt64Pref( | 38 registry->RegisterInt64Pref( |
| 39 prefs::kSAMLLastGAIASignInTime, | 39 prefs::kSAMLLastGAIASignInTime, |
| 40 0, | 40 0, |
| 41 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 41 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 42 } | 42 } |
| 43 | 43 |
| 44 void SAMLOfflineSigninLimiter::SignedIn(UserContext::AuthFlow auth_flow) { | 44 void SAMLOfflineSigninLimiter::SignedIn(UserContext::AuthFlow auth_flow) { |
| 45 PrefService* prefs = profile_->GetPrefs(); | 45 PrefService* prefs = profile_->GetPrefs(); |
| 46 const User* user = ProfileHelper::Get()->GetUserByProfile(profile_); | 46 const user_manager::User* user = |
| 47 ProfileHelper::Get()->GetUserByProfile(profile_); |
| 47 if (!user) { | 48 if (!user) { |
| 48 NOTREACHED(); | 49 NOTREACHED(); |
| 49 return; | 50 return; |
| 50 } | 51 } |
| 51 const std::string& user_id = user->email(); | 52 const std::string& user_id = user->email(); |
| 52 | 53 |
| 53 if (auth_flow == UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML) { | 54 if (auth_flow == UserContext::AUTH_FLOW_GAIA_WITHOUT_SAML) { |
| 54 // The user went through online authentication and GAIA did not redirect to | 55 // The user went through online authentication and GAIA did not redirect to |
| 55 // a SAML IdP. No limit applies in this case. Clear the time of last login | 56 // a SAML IdP. No limit applies in this case. Clear the time of last login |
| 56 // with SAML and the flag enforcing online login, then return. | 57 // with SAML and the flag enforcing online login, then return. |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 offline_signin_limit_timer_.reset( | 134 offline_signin_limit_timer_.reset( |
| 134 new base::OneShotTimer<SAMLOfflineSigninLimiter>); | 135 new base::OneShotTimer<SAMLOfflineSigninLimiter>); |
| 135 offline_signin_limit_timer_->Start( | 136 offline_signin_limit_timer_->Start( |
| 136 FROM_HERE, | 137 FROM_HERE, |
| 137 offline_signin_time_limit - time_since_last_gaia_signin, | 138 offline_signin_time_limit - time_since_last_gaia_signin, |
| 138 this, | 139 this, |
| 139 &SAMLOfflineSigninLimiter::ForceOnlineLogin); | 140 &SAMLOfflineSigninLimiter::ForceOnlineLogin); |
| 140 } | 141 } |
| 141 | 142 |
| 142 void SAMLOfflineSigninLimiter::ForceOnlineLogin() { | 143 void SAMLOfflineSigninLimiter::ForceOnlineLogin() { |
| 143 User* user = ProfileHelper::Get()->GetUserByProfile(profile_); | 144 user_manager::User* user = ProfileHelper::Get()->GetUserByProfile(profile_); |
| 144 if (!user) { | 145 if (!user) { |
| 145 NOTREACHED(); | 146 NOTREACHED(); |
| 146 return; | 147 return; |
| 147 } | 148 } |
| 148 | 149 |
| 149 UserManager::Get()->SaveForceOnlineSignin(user->email(), true); | 150 UserManager::Get()->SaveForceOnlineSignin(user->email(), true); |
| 150 offline_signin_limit_timer_.reset(); | 151 offline_signin_limit_timer_.reset(); |
| 151 } | 152 } |
| 152 | 153 |
| 153 } // namespace chromeos | 154 } // namespace chromeos |
| OLD | NEW |