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

Side by Side Diff: chrome/browser/chromeos/login/signin/token_handle_util.cc

Issue 1128923006: Do not invalidate OAuth token status user when token handle is invalid. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
OLDNEW
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"
11 #include "components/user_manager/user_id.h" 11 #include "components/user_manager/user_id.h"
12 #include "components/user_manager/user_manager.h" 12 #include "components/user_manager/user_manager.h"
13 #include "google_apis/gaia/gaia_oauth_client.h" 13 #include "google_apis/gaia/gaia_oauth_client.h"
14 14
15 namespace { 15 namespace {
16 16
17 const char kTokenHandlePref[] = "PasswordTokenHandle"; 17 const char kTokenHandlePref[] = "PasswordTokenHandle";
18 const char kTokenHandleStatusPref[] = "TokenHandleStatus";
19
20 const char kHandleStatusValid[] = "valid";
Nikita (slow) 2015/05/12 17:45:57 Should set valid status when token is stored.
21 const char kHandleStatusInvalid[] = "invalid";
22 const char* kDefaultHandleStatus = kHandleStatusValid;
23
18 static const int kMaxRetries = 3; 24 static const int kMaxRetries = 3;
19 } 25
26 } // namespace
20 27
21 TokenHandleUtil::TokenHandleUtil(user_manager::UserManager* user_manager) 28 TokenHandleUtil::TokenHandleUtil(user_manager::UserManager* user_manager)
22 : user_manager_(user_manager), weak_factory_(this) { 29 : user_manager_(user_manager), weak_factory_(this) {
23 } 30 }
24 31
25 TokenHandleUtil::~TokenHandleUtil() { 32 TokenHandleUtil::~TokenHandleUtil() {
26 weak_factory_.InvalidateWeakPtrs(); 33 weak_factory_.InvalidateWeakPtrs();
27 gaia_client_.reset(); 34 gaia_client_.reset();
28 } 35 }
29 36
30 bool TokenHandleUtil::HasToken(const user_manager::UserID& user_id) { 37 bool TokenHandleUtil::HasToken(const user_manager::UserID& user_id) {
31 const base::DictionaryValue* dict = nullptr; 38 const base::DictionaryValue* dict = nullptr;
32 std::string token; 39 std::string token;
33 if (!user_manager_->FindKnownUserPrefs(user_id, &dict)) 40 if (!user_manager_->FindKnownUserPrefs(user_id, &dict))
34 return false; 41 return false;
35 if (!dict->GetString(kTokenHandlePref, &token)) 42 if (!dict->GetString(kTokenHandlePref, &token))
36 return false; 43 return false;
37 return !token.empty(); 44 return !token.empty();
38 } 45 }
39 46
40 void TokenHandleUtil::DeleteToken(const user_manager::UserID& user_id) { 47 bool TokenHandleUtil::ShouldObtainHandle(const user_manager::UserID& user_id) {
48 const base::DictionaryValue* dict = nullptr;
49 std::string token;
50 if (!user_manager_->FindKnownUserPrefs(user_id, &dict))
51 return true;
52 if (!dict->GetString(kTokenHandlePref, &token))
53 return true;
54 if (token.empty())
55 return true;
56 std::string status(kDefaultHandleStatus);
57 dict->GetString(kTokenHandleStatusPref, &status);
58 return kHandleStatusInvalid == status;
59 }
60
61 void TokenHandleUtil::DeleteHandle(const user_manager::UserID& user_id) {
41 const base::DictionaryValue* dict = nullptr; 62 const base::DictionaryValue* dict = nullptr;
42 if (!user_manager_->FindKnownUserPrefs(user_id, &dict)) 63 if (!user_manager_->FindKnownUserPrefs(user_id, &dict))
43 return; 64 return;
44 scoped_ptr<base::DictionaryValue> dict_copy(dict->DeepCopy()); 65 scoped_ptr<base::DictionaryValue> dict_copy(dict->DeepCopy());
45 if (!dict_copy->Remove(kTokenHandlePref, nullptr)) 66 dict_copy->Remove(kTokenHandlePref, nullptr);
46 return; 67 dict_copy->Remove(kTokenHandleStatusPref, nullptr);
47 user_manager_->UpdateKnownUserPrefs(user_id, *dict_copy.get(), 68 user_manager_->UpdateKnownUserPrefs(user_id, *dict_copy.get(),
48 /* replace values */ true); 69 /* replace values */ true);
49 } 70 }
50 71
72 void TokenHandleUtil::MarkHandleInvalid(const user_manager::UserID& user_id) {
73 user_manager_->SetKnownUserStringPref(user_id, kTokenHandleStatusPref,
74 kHandleStatusInvalid);
75 }
76
51 void TokenHandleUtil::CheckToken(const user_manager::UserID& user_id, 77 void TokenHandleUtil::CheckToken(const user_manager::UserID& user_id,
52 const TokenValidationCallback& callback) { 78 const TokenValidationCallback& callback) {
53 const base::DictionaryValue* dict = nullptr; 79 const base::DictionaryValue* dict = nullptr;
54 std::string token; 80 std::string token;
55 if (!user_manager_->FindKnownUserPrefs(user_id, &dict)) { 81 if (!user_manager_->FindKnownUserPrefs(user_id, &dict)) {
56 callback.Run(user_id, UNKNOWN); 82 callback.Run(user_id, UNKNOWN);
57 return; 83 return;
58 } 84 }
59 if (!dict->GetString(kTokenHandlePref, &token)) { 85 if (!dict->GetString(kTokenHandlePref, &token)) {
60 callback.Run(user_id, UNKNOWN); 86 callback.Run(user_id, UNKNOWN);
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 } else { 182 } else {
157 if (!token_info->HasKey("error")) { 183 if (!token_info->HasKey("error")) {
158 int expires_in = 0; 184 int expires_in = 0;
159 if (token_info->GetInteger("expires_in", &expires_in)) 185 if (token_info->GetInteger("expires_in", &expires_in))
160 outcome = (expires_in < 0) ? INVALID : VALID; 186 outcome = (expires_in < 0) ? INVALID : VALID;
161 } 187 }
162 } 188 }
163 callback_.Run(user_id_, outcome); 189 callback_.Run(user_id_, outcome);
164 NotifyDone(); 190 NotifyDone();
165 } 191 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698