OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/signin/token_handle_util.h" | 5 #include "chrome/browser/chromeos/login/signin/token_handle_util.h" |
6 | 6 |
7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 9 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 dict_copy->Remove(kTokenHandleStatusPref, nullptr); | 67 dict_copy->Remove(kTokenHandleStatusPref, nullptr); |
68 user_manager_->UpdateKnownUserPrefs(user_id, *dict_copy.get(), | 68 user_manager_->UpdateKnownUserPrefs(user_id, *dict_copy.get(), |
69 /* replace values */ true); | 69 /* replace values */ true); |
70 } | 70 } |
71 | 71 |
72 void TokenHandleUtil::MarkHandleInvalid(const user_manager::UserID& user_id) { | 72 void TokenHandleUtil::MarkHandleInvalid(const user_manager::UserID& user_id) { |
73 user_manager_->SetKnownUserStringPref(user_id, kTokenHandleStatusPref, | 73 user_manager_->SetKnownUserStringPref(user_id, kTokenHandleStatusPref, |
74 kHandleStatusInvalid); | 74 kHandleStatusInvalid); |
75 } | 75 } |
76 | 76 |
77 void TokenHandleUtil::CheckToken(const user_manager::UserID& user_id, | 77 bool TokenHandleUtil::CheckToken(const user_manager::UserID& user_id, |
78 const TokenValidationCallback& callback) { | 78 const TokenValidationCallback& callback) { |
79 const base::DictionaryValue* dict = nullptr; | 79 const base::DictionaryValue* dict = nullptr; |
80 std::string token; | 80 std::string token; |
81 if (!user_manager_->FindKnownUserPrefs(user_id, &dict)) { | 81 if (!user_manager_->FindKnownUserPrefs(user_id, &dict)) { |
82 callback.Run(user_id, UNKNOWN); | 82 callback.Run(user_id, UNKNOWN); |
83 return; | 83 return true; |
84 } | 84 } |
85 if (!dict->GetString(kTokenHandlePref, &token)) { | 85 if (!dict->GetString(kTokenHandlePref, &token)) { |
86 callback.Run(user_id, UNKNOWN); | 86 callback.Run(user_id, UNKNOWN); |
87 return; | 87 return true; |
88 } | 88 } |
89 | 89 |
90 if (!gaia_client_.get()) { | 90 if (!gaia_client_.get()) { |
91 auto request_context = | 91 auto request_context = |
92 chromeos::ProfileHelper::Get()->GetSigninProfile()->GetRequestContext(); | 92 chromeos::ProfileHelper::Get()->GetSigninProfile()->GetRequestContext(); |
93 gaia_client_.reset(new gaia::GaiaOAuthClient(request_context)); | 93 gaia_client_.reset(new gaia::GaiaOAuthClient(request_context)); |
94 } | 94 } |
| 95 if (validation_delegates_.count(token) != 0) |
| 96 return false; |
95 | 97 |
96 validation_delegates_.set( | 98 validation_delegates_.set( |
97 token, scoped_ptr<TokenDelegate>(new TokenDelegate( | 99 token, scoped_ptr<TokenDelegate>(new TokenDelegate( |
98 weak_factory_.GetWeakPtr(), false /* validate */, user_id, | 100 weak_factory_.GetWeakPtr(), false /* validate */, user_id, |
99 token, callback))); | 101 token, callback))); |
100 gaia_client_->GetTokenHandleInfo(token, kMaxRetries, | 102 gaia_client_->GetTokenHandleInfo(token, kMaxRetries, |
101 validation_delegates_.get(token)); | 103 validation_delegates_.get(token)); |
| 104 return true; |
102 } | 105 } |
103 | 106 |
104 void TokenHandleUtil::StoreTokenHandle(const user_manager::UserID& user_id, | 107 void TokenHandleUtil::StoreTokenHandle(const user_manager::UserID& user_id, |
105 const std::string& handle) { | 108 const std::string& handle) { |
106 user_manager_->SetKnownUserStringPref(user_id, kTokenHandlePref, handle); | 109 user_manager_->SetKnownUserStringPref(user_id, kTokenHandlePref, handle); |
107 user_manager_->SetKnownUserStringPref(user_id, kTokenHandleStatusPref, | 110 user_manager_->SetKnownUserStringPref(user_id, kTokenHandleStatusPref, |
108 kHandleStatusValid); | 111 kHandleStatusValid); |
109 } | 112 } |
110 | 113 |
111 void TokenHandleUtil::OnValidationComplete(const std::string& token) { | 114 void TokenHandleUtil::OnValidationComplete(const std::string& token) { |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 } else { | 187 } else { |
185 if (!token_info->HasKey("error")) { | 188 if (!token_info->HasKey("error")) { |
186 int expires_in = 0; | 189 int expires_in = 0; |
187 if (token_info->GetInteger("expires_in", &expires_in)) | 190 if (token_info->GetInteger("expires_in", &expires_in)) |
188 outcome = (expires_in < 0) ? INVALID : VALID; | 191 outcome = (expires_in < 0) ? INVALID : VALID; |
189 } | 192 } |
190 } | 193 } |
191 callback_.Run(user_id_, outcome); | 194 callback_.Run(user_id_, outcome); |
192 NotifyDone(); | 195 NotifyDone(); |
193 } | 196 } |
OLD | NEW |