Chromium Code Reviews| 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 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_TOKEN_HANDLE_UTIL_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_TOKEN_HANDLE_UTIL_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_TOKEN_HANDLE_UTIL_H_ | 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_TOKEN_HANDLE_UTIL_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/containers/scoped_ptr_hash_map.h" | 12 #include "base/containers/scoped_ptr_hash_map.h" |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "components/user_manager/user_id.h" | 15 #include "components/signin/core/account_id/account_id.h" |
| 16 #include "google_apis/gaia/gaia_oauth_client.h" | 16 #include "google_apis/gaia/gaia_oauth_client.h" |
| 17 | 17 |
| 18 class AccountId; | |
| 19 | |
| 18 namespace base { | 20 namespace base { |
| 19 class DictionaryValue; | 21 class DictionaryValue; |
| 20 } | 22 } |
| 21 | 23 |
| 22 namespace user_manager { | 24 namespace user_manager { |
| 23 class UserManager; | 25 class UserManager; |
| 24 } | 26 } |
| 25 | 27 |
| 26 // This class is responsible for operations with External Token Handle. | 28 // This class is responsible for operations with External Token Handle. |
| 27 // Handle is an extra token associated with OAuth refresh token that have | 29 // Handle is an extra token associated with OAuth refresh token that have |
| 28 // exactly same lifetime. It is not secure, and it's only purpose is checking | 30 // exactly same lifetime. It is not secure, and it's only purpose is checking |
| 29 // validity of corresponding refresh token in the insecure environment. | 31 // validity of corresponding refresh token in the insecure environment. |
| 30 class TokenHandleUtil { | 32 class TokenHandleUtil { |
| 31 public: | 33 public: |
| 32 explicit TokenHandleUtil(user_manager::UserManager* user_manager); | 34 explicit TokenHandleUtil(user_manager::UserManager* user_manager); |
| 33 ~TokenHandleUtil(); | 35 ~TokenHandleUtil(); |
| 34 | 36 |
| 35 enum TokenHandleStatus { VALID, INVALID, UNKNOWN }; | 37 enum TokenHandleStatus { VALID, INVALID, UNKNOWN }; |
| 36 | 38 |
| 37 typedef base::Callback<void(const user_manager::UserID&, TokenHandleStatus)> | 39 typedef base::Callback<void(const AccountId&, TokenHandleStatus)> |
|
achuithb
2015/10/28 23:11:45
using
Alexander Alekseev
2015/10/29 02:00:40
Done.
| |
| 38 TokenValidationCallback; | 40 TokenValidationCallback; |
| 39 | 41 |
| 40 // Returns true if UserManager has token handle associated with |user_id|. | 42 // Returns true if UserManager has token handle associated with |account_id|. |
| 41 bool HasToken(const user_manager::UserID& user_id); | 43 bool HasToken(const AccountId& account_id); |
| 42 | 44 |
| 43 // Removes token handle for |user_id| from UserManager storage. | 45 // Removes token handle for |account_id| from UserManager storage. |
| 44 void DeleteHandle(const user_manager::UserID& user_id); | 46 void DeleteHandle(const AccountId& account_id); |
| 45 | 47 |
| 46 // Marks current handle as invalid, new one should be obtained at next sign | 48 // Marks current handle as invalid, new one should be obtained at next sign |
| 47 // in. | 49 // in. |
| 48 void MarkHandleInvalid(const user_manager::UserID& user_id); | 50 void MarkHandleInvalid(const AccountId& account_id); |
| 49 | 51 |
| 50 // Indicates if token handle for |user_id| is missing or marked as invalid. | 52 // Indicates if token handle for |account_id| is missing or marked as invalid. |
| 51 bool ShouldObtainHandle(const user_manager::UserID& user_id); | 53 bool ShouldObtainHandle(const AccountId& account_id); |
| 52 | 54 |
| 53 // Performs token handle check for |user_id|. Will call |callback| with | 55 // Performs token handle check for |account_id|. Will call |callback| with |
| 54 // corresponding result. | 56 // corresponding result. |
| 55 void CheckToken(const user_manager::UserID& user_id, | 57 void CheckToken(const AccountId& account_id, |
| 56 const TokenValidationCallback& callback); | 58 const TokenValidationCallback& callback); |
| 57 | 59 |
| 58 // Given the token |handle| store it for |user_id|. | 60 // Given the token |handle| store it for |account_id|. |
| 59 void StoreTokenHandle(const user_manager::UserID& user_id, | 61 void StoreTokenHandle(const AccountId& account_id, const std::string& handle); |
| 60 const std::string& handle); | |
| 61 | 62 |
| 62 private: | 63 private: |
| 63 // Associates GaiaOAuthClient::Delegate with User ID and Token. | 64 // Associates GaiaOAuthClient::Delegate with User ID and Token. |
| 64 class TokenDelegate : public gaia::GaiaOAuthClient::Delegate { | 65 class TokenDelegate : public gaia::GaiaOAuthClient::Delegate { |
| 65 public: | 66 public: |
| 66 TokenDelegate(const base::WeakPtr<TokenHandleUtil>& owner, | 67 TokenDelegate(const base::WeakPtr<TokenHandleUtil>& owner, |
| 67 const user_manager::UserID& user_id, | 68 const AccountId& account_id, |
| 68 const std::string& token, | 69 const std::string& token, |
| 69 const TokenValidationCallback& callback); | 70 const TokenValidationCallback& callback); |
| 70 ~TokenDelegate() override; | 71 ~TokenDelegate() override; |
| 71 void OnOAuthError() override; | 72 void OnOAuthError() override; |
| 72 void OnNetworkError(int response_code) override; | 73 void OnNetworkError(int response_code) override; |
| 73 void OnGetTokenInfoResponse( | 74 void OnGetTokenInfoResponse( |
| 74 scoped_ptr<base::DictionaryValue> token_info) override; | 75 scoped_ptr<base::DictionaryValue> token_info) override; |
| 75 void NotifyDone(); | 76 void NotifyDone(); |
| 76 | 77 |
| 77 private: | 78 private: |
| 78 base::WeakPtr<TokenHandleUtil> owner_; | 79 base::WeakPtr<TokenHandleUtil> owner_; |
| 79 user_manager::UserID user_id_; | 80 AccountId account_id_; |
| 80 std::string token_; | 81 std::string token_; |
| 81 base::TimeTicks tokeninfo_response_start_time_; | 82 base::TimeTicks tokeninfo_response_start_time_; |
| 82 TokenValidationCallback callback_; | 83 TokenValidationCallback callback_; |
| 83 | 84 |
| 84 DISALLOW_COPY_AND_ASSIGN(TokenDelegate); | 85 DISALLOW_COPY_AND_ASSIGN(TokenDelegate); |
| 85 }; | 86 }; |
| 86 | 87 |
| 87 void OnValidationComplete(const std::string& token); | 88 void OnValidationComplete(const std::string& token); |
| 88 void OnObtainTokenComplete(const user_manager::UserID& id); | 89 void OnObtainTokenComplete(const AccountId& account_id); |
| 89 | 90 |
| 90 // UserManager that stores corresponding user data. | 91 // UserManager that stores corresponding user data. |
| 91 user_manager::UserManager* user_manager_; | 92 user_manager::UserManager* user_manager_; |
| 92 | 93 |
| 93 // Map of pending check operations. | 94 // Map of pending check operations. |
| 94 base::ScopedPtrHashMap<std::string, scoped_ptr<TokenDelegate>> | 95 base::ScopedPtrHashMap<std::string, scoped_ptr<TokenDelegate>> |
| 95 validation_delegates_; | 96 validation_delegates_; |
| 96 | 97 |
| 97 // Map of pending obtain operations. | 98 // Map of pending obtain operations. |
| 98 base::ScopedPtrHashMap<user_manager::UserID, scoped_ptr<TokenDelegate>> | 99 base::ScopedPtrHashMap<AccountId, scoped_ptr<TokenDelegate>> |
| 99 obtain_delegates_; | 100 obtain_delegates_; |
| 100 | 101 |
| 101 // Instance of GAIA Client. | 102 // Instance of GAIA Client. |
| 102 scoped_ptr<gaia::GaiaOAuthClient> gaia_client_; | 103 scoped_ptr<gaia::GaiaOAuthClient> gaia_client_; |
| 103 | 104 |
| 104 base::WeakPtrFactory<TokenHandleUtil> weak_factory_; | 105 base::WeakPtrFactory<TokenHandleUtil> weak_factory_; |
| 105 | 106 |
| 106 DISALLOW_COPY_AND_ASSIGN(TokenHandleUtil); | 107 DISALLOW_COPY_AND_ASSIGN(TokenHandleUtil); |
| 107 }; | 108 }; |
| 108 | 109 |
| 109 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_TOKEN_HANDLE_UTIL_H_ | 110 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_TOKEN_HANDLE_UTIL_H_ |
| OLD | NEW |