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

Side by Side Diff: chrome/browser/chromeos/login/signin/token_handler_util.h

Issue 1025663002: Implement oauth token external handler checking. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update fake user manager Created 5 years, 9 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
(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
42 // Removes token handle for |user_id| from UserManager storage.
43 void DeleteToken(const user_manager::UserID& user_id);
44
45 // Performs token handle check for |user_id|. Will call |callback| with
46 // corresponding result.
47 void CheckToken(const user_manager::UserID& user_id,
48 const TokenValidationCallback& callback);
49
50 private:
51 // Associates GaiaOAuthClient::Delegate with User ID and Token.
52 class TokenValidationDelegate : public gaia::GaiaOAuthClient::Delegate {
53 public:
54 TokenValidationDelegate(const base::WeakPtr<TokenHandlerUtil>& owner,
55 const user_manager::UserID& user_id,
56 const std::string& token,
57 const TokenValidationCallback& callback);
58 ~TokenValidationDelegate() override;
59 void OnOAuthError() override;
60 void OnNetworkError(int response_code) override;
61 void OnGetTokenInfoResponse(
62 scoped_ptr<base::DictionaryValue> token_info) override;
63
64 private:
65 base::WeakPtr<TokenHandlerUtil> owner_;
66 user_manager::UserID user_id_;
67 std::string token_;
68 TokenValidationCallback callback_;
69
70 DISALLOW_COPY_AND_ASSIGN(TokenValidationDelegate);
71 };
72
73 void OnValidationComplete(const std::string& token);
74
75 // UserManager that stores corresponding user data.
76 user_manager::UserManager* user_manager_;
77
78 // Map of pending check operations.
79 base::ScopedPtrHashMap<std::string, TokenValidationDelegate>
80 validation_delegates_;
81
82 // Instance of GAIA Client.
83 scoped_ptr<gaia::GaiaOAuthClient> gaia_client_;
84
85 base::WeakPtrFactory<TokenHandlerUtil> weak_factory_;
86
87 DISALLOW_COPY_AND_ASSIGN(TokenHandlerUtil);
88 };
89
90 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_SIGNIN_TOKEN_HANDLER_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698