Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_TOKEN_HANDLER_UTIL_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_TOKEN_HANDLER_UTIL_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/callback.h" | |
| 12 #include "base/containers/scoped_ptr_hash_map.h" | |
| 13 #include "base/memory/weak_ptr.h" | |
| 14 #include "components/user_manager/user_id.h" | |
| 15 #include "google_apis/gaia/gaia_oauth_client.h" | |
| 16 | |
| 17 namespace base { | |
| 18 class DictionaryValue; | |
| 19 } | |
| 20 | |
| 21 namespace user_manager { | |
| 22 class UserManager; | |
| 23 } | |
| 24 | |
| 25 // This class is responsible for operations with External Token Handle. | |
| 26 // Handle is an extra token associated with OAuth refresh token that have | |
| 27 // exactly same lifetime. It is not secure, and it's only purpose is checking | |
| 28 // validity of corresponding refresh token in the insecure environment. | |
| 29 class TokenHandlerUtil { | |
| 30 public: | |
| 31 explicit TokenHandlerUtil(user_manager::UserManager* user_manager); | |
| 32 ~TokenHandlerUtil(); | |
| 33 | |
| 34 enum TokenHandleStatus { VALID, INVALID, UNKNOWN }; | |
| 35 | |
| 36 typedef base::Callback<void(const user_manager::UserID&, TokenHandleStatus)> | |
| 37 TokenValidationCallback; | |
| 38 | |
| 39 // Returns true if UserManager has token handle associated with |user_id|. | |
| 40 bool HasToken(const user_manager::UserID& user_id); | |
| 41 // Removes token handle for |user_id| from UserManager storage. | |
|
Nikita (slow)
2015/03/20 18:06:49
nit: insert empty line before comments.
Denis Kuznetsov (DE-MUC)
2015/03/20 19:50:29
Done.
| |
| 42 void DeleteToken(const user_manager::UserID& user_id); | |
| 43 // Performs token handle check for |user_id|. Will call |callback| with | |
| 44 // corresponding result. | |
| 45 void CheckToken(const user_manager::UserID& user_id, | |
| 46 const TokenValidationCallback& callback); | |
| 47 | |
| 48 private: | |
| 49 // Associates GaiaOAuthClient::Delegate with User ID and Token. | |
| 50 class TokenValidationDelegate : public gaia::GaiaOAuthClient::Delegate { | |
| 51 public: | |
| 52 TokenValidationDelegate(const base::WeakPtr<TokenHandlerUtil>& owner, | |
| 53 const user_manager::UserID& user_id, | |
| 54 const std::string& token, | |
| 55 const TokenValidationCallback& callback); | |
| 56 ~TokenValidationDelegate() override; | |
| 57 void OnOAuthError() override; | |
| 58 void OnNetworkError(int response_code) override; | |
| 59 void OnGetTokenInfoResponse( | |
| 60 scoped_ptr<base::DictionaryValue> token_info) override; | |
| 61 | |
| 62 private: | |
| 63 base::WeakPtr<TokenHandlerUtil> owner_; | |
| 64 user_manager::UserID user_id_; | |
| 65 std::string token_; | |
| 66 TokenValidationCallback callback_; | |
| 67 | |
| 68 DISALLOW_COPY_AND_ASSIGN(TokenValidationDelegate); | |
| 69 }; | |
| 70 | |
| 71 void OnValidationComplete(const std::string& token); | |
| 72 | |
| 73 // UserManager that stores corresponding user data. | |
| 74 user_manager::UserManager* user_manager_; | |
| 75 | |
| 76 // Map of pending check operations. | |
| 77 base::ScopedPtrHashMap<std::string, TokenValidationDelegate> | |
| 78 validation_delegates_; | |
| 79 // Instance of GAIA Client | |
|
Nikita (slow)
2015/03/20 18:06:49
nit: dot at the end, insert empty line.
Denis Kuznetsov (DE-MUC)
2015/03/20 19:50:29
Done.
| |
| 80 scoped_ptr<gaia::GaiaOAuthClient> gaia_client_; | |
| 81 | |
| 82 base::WeakPtrFactory<TokenHandlerUtil> weak_factory_; | |
| 83 | |
| 84 DISALLOW_COPY_AND_ASSIGN(TokenHandlerUtil); | |
| 85 }; | |
| 86 | |
| 87 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_TOKEN_HANDLER_UTIL_H_ | |
| OLD | NEW |