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

Side by Side Diff: chrome/browser/signin/oauth2_token_service_delegate_android.h

Issue 1256283002: GAIA ID migration for Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: update Created 5 years, 3 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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_SIGNIN_OAUTH2_TOKEN_SERVICE_DELEGATE_ANDROID_H_ 5 #ifndef CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_DELEGATE_ANDROID_H_
6 #define CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_DELEGATE_ANDROID_H_ 6 #define CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_DELEGATE_ANDROID_H_
7 7
8 #include <jni.h> 8 #include <jni.h>
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
11 11
12 #include "base/android/jni_weak_ref.h" 12 #include "base/android/jni_weak_ref.h"
13 #include "base/android/scoped_java_ref.h" 13 #include "base/android/scoped_java_ref.h"
14 #include "base/callback.h" 14 #include "base/callback.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/time/time.h" 16 #include "base/time/time.h"
17 #include "components/signin/core/browser/account_tracker_service.h"
17 #include "components/signin/core/browser/profile_oauth2_token_service.h" 18 #include "components/signin/core/browser/profile_oauth2_token_service.h"
18 #include "google_apis/gaia/google_service_auth_error.h" 19 #include "google_apis/gaia/google_service_auth_error.h"
19 #include "google_apis/gaia/oauth2_token_service_delegate.h" 20 #include "google_apis/gaia/oauth2_token_service_delegate.h"
20 21
21 // A specialization of OAuth2TokenServiceDelegate that will be returned by 22 // A specialization of OAuth2TokenServiceDelegate that will be returned by
22 // OAuth2TokenServiceDelegateFactory for OS_ANDROID. This instance uses 23 // OAuth2TokenServiceDelegateFactory for OS_ANDROID. This instance uses
23 // native Android features to lookup OAuth2 tokens. 24 // native Android features to lookup OAuth2 tokens.
24 // 25 //
25 // See |OAuth2TokenServiceDelegate| for usage details. 26 // See |OAuth2TokenServiceDelegate| for usage details.
26 // 27 //
(...skipping 10 matching lines...) Expand all
37 38
38 // Returns a reference to the Java instance of this service. 39 // Returns a reference to the Java instance of this service.
39 static base::android::ScopedJavaLocalRef<jobject> 40 static base::android::ScopedJavaLocalRef<jobject>
40 GetForProfile(JNIEnv* env, jclass clazz, jobject j_profile_android); 41 GetForProfile(JNIEnv* env, jclass clazz, jobject j_profile_android);
41 42
42 // Called by the TestingProfile class to disable account validation in 43 // Called by the TestingProfile class to disable account validation in
43 // tests. This prevents the token service from trying to look up system 44 // tests. This prevents the token service from trying to look up system
44 // accounts which requires special permission. 45 // accounts which requires special permission.
45 static void set_is_testing_profile() { is_testing_profile_ = true; } 46 static void set_is_testing_profile() { is_testing_profile_ = true; }
46 47
47 void Initialize();
48
49 // OAuth2TokenServiceDelegate overrides: 48 // OAuth2TokenServiceDelegate overrides:
50 bool RefreshTokenIsAvailable(const std::string& account_id) const override; 49 bool RefreshTokenIsAvailable(const std::string& account_id) const override;
51 bool RefreshTokenHasError(const std::string& account_id) const override; 50 bool RefreshTokenHasError(const std::string& account_id) const override;
52 void UpdateAuthError(const std::string& account_id, 51 void UpdateAuthError(const std::string& account_id,
53 const GoogleServiceAuthError& error) override; 52 const GoogleServiceAuthError& error) override;
54 std::vector<std::string> GetAccounts() override; 53 std::vector<std::string> GetAccounts() override;
55 54
56 // Lists account at the OS level. 55 // Lists account names at the OS level.
57 std::vector<std::string> GetSystemAccounts(); 56 std::vector<std::string> GetSystemAccountNames();
58 57
59 void ValidateAccounts(JNIEnv* env, 58 void ValidateAccounts(JNIEnv* env,
60 jobject obj, 59 jobject obj,
61 jstring current_account, 60 jstring current_account,
62 jboolean force_notifications); 61 jboolean force_notifications);
63 62
64 // Takes a the signed in sync account as well as all the other 63 // Takes a the signed in sync account as well as all the other
65 // android account ids and check the token status of each. If 64 // android account ids and check the token status of each. If
66 // |force_notifications| is true, TokenAvailable notifications will 65 // |force_notifications| is true, TokenAvailable notifications will
67 // be sent anyway, even if the account was already known. 66 // be sent anyway, even if the account was already known.
(...skipping 12 matching lines...) Expand all
80 jobject obj, 79 jobject obj,
81 const jstring account_name); 80 const jstring account_name);
82 // Triggers a notification to all observers of the OAuth2TokenService that all 81 // Triggers a notification to all observers of the OAuth2TokenService that all
83 // refresh tokens have now been loaded. 82 // refresh tokens have now been loaded.
84 virtual void FireRefreshTokensLoadedFromJava(JNIEnv* env, jobject obj); 83 virtual void FireRefreshTokensLoadedFromJava(JNIEnv* env, jobject obj);
85 84
86 // Overridden from OAuth2TokenService to complete signout of all 85 // Overridden from OAuth2TokenService to complete signout of all
87 // OA2TService aware accounts. 86 // OA2TService aware accounts.
88 void RevokeAllCredentials() override; 87 void RevokeAllCredentials() override;
89 88
89 void LoadCredentials(const std::string& primary_account_id) override;
90
90 protected: 91 protected:
91 friend class ProfileOAuth2TokenServiceFactory; 92 friend class ProfileOAuth2TokenServiceFactory;
92 OAuth2TokenServiceDelegateAndroid(); 93 OAuth2TokenServiceDelegateAndroid(
94 AccountTrackerService* account_tracker_service);
93 ~OAuth2TokenServiceDelegateAndroid() override; 95 ~OAuth2TokenServiceDelegateAndroid() override;
94 96
95 OAuth2AccessTokenFetcher* CreateAccessTokenFetcher( 97 OAuth2AccessTokenFetcher* CreateAccessTokenFetcher(
96 const std::string& account_id, 98 const std::string& account_id,
97 net::URLRequestContextGetter* getter, 99 net::URLRequestContextGetter* getter,
98 OAuth2AccessTokenConsumer* consumer) override; 100 OAuth2AccessTokenConsumer* consumer) override;
99 101
100 // Overridden from OAuth2TokenService to intercept token fetch requests and 102 // Overridden from OAuth2TokenService to intercept token fetch requests and
101 // redirect them to the Account Manager. 103 // redirect them to the Account Manager.
102 void InvalidateAccessToken(const std::string& account_id, 104 void InvalidateAccessToken(const std::string& account_id,
103 const std::string& client_id, 105 const std::string& client_id,
104 const OAuth2TokenService::ScopeSet& scopes, 106 const OAuth2TokenService::ScopeSet& scopes,
105 const std::string& access_token) override; 107 const std::string& access_token) override;
106 108
107 // Called to notify observers when a refresh token is available. 109 // Called to notify observers when a refresh token is available.
108 void FireRefreshTokenAvailable(const std::string& account_id) override; 110 void FireRefreshTokenAvailable(const std::string& account_id) override;
109 // Called to notify observers when a refresh token has been revoked. 111 // Called to notify observers when a refresh token has been revoked.
110 void FireRefreshTokenRevoked(const std::string& account_id) override; 112 void FireRefreshTokenRevoked(const std::string& account_id) override;
111 // Called to notify observers when refresh tokans have been loaded. 113 // Called to notify observers when refresh tokans have been loaded.
112 void FireRefreshTokensLoaded() override; 114 void FireRefreshTokensLoaded() override;
113 115
114 private: 116 private:
117 std::string MapAccountIdToAccountName(const std::string& account_id) const;
118 std::string MapAccountNameToAccountId(const std::string& account_name) const;
119
115 struct ErrorInfo { 120 struct ErrorInfo {
116 ErrorInfo(); 121 ErrorInfo();
117 explicit ErrorInfo(const GoogleServiceAuthError& error); 122 explicit ErrorInfo(const GoogleServiceAuthError& error);
118 GoogleServiceAuthError error; 123 GoogleServiceAuthError error;
119 }; 124 };
120 125
126 enum RefreshTokenLoadStatus {
127 RT_LOAD_NOT_START,
128 RT_WAIT_FOR_VALIDATION,
129 RT_HAS_BEEN_VALIDATED,
130 RT_LOADED
131 };
132
121 // Return whether |signed_in_account| is valid and we have access 133 // Return whether |signed_in_account| is valid and we have access
122 // to all the tokens in |curr_account_ids|. If |force_notifications| is true, 134 // to all the tokens in |curr_account_ids|. If |force_notifications| is true,
123 // TokenAvailable notifications will be sent anyway, even if the account was 135 // TokenAvailable notifications will be sent anyway, even if the account was
124 // already known. 136 // already known.
125 bool ValidateAccounts(const std::string& signed_in_account, 137 bool ValidateAccounts(const std::string& signed_in_account,
126 const std::vector<std::string>& prev_account_ids, 138 const std::vector<std::string>& prev_account_ids,
127 const std::vector<std::string>& curr_account_ids, 139 const std::vector<std::string>& curr_account_ids,
128 std::vector<std::string>& refreshed_ids, 140 std::vector<std::string>& refreshed_ids,
129 std::vector<std::string>& revoked_ids, 141 std::vector<std::string>& revoked_ids,
130 bool force_notifications); 142 bool force_notifications);
131 143
132 base::android::ScopedJavaGlobalRef<jobject> java_ref_; 144 base::android::ScopedJavaGlobalRef<jobject> java_ref_;
133 145
134 // Maps account_id to the last error for that account. 146 // Maps account_id to the last error for that account.
135 std::map<std::string, ErrorInfo> errors_; 147 std::map<std::string, ErrorInfo> errors_;
136 148
149 AccountTrackerService* account_tracker_service_;
150 RefreshTokenLoadStatus fire_refresh_token_loaded_;
151
137 static bool is_testing_profile_; 152 static bool is_testing_profile_;
138 153
139 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenServiceDelegateAndroid); 154 DISALLOW_COPY_AND_ASSIGN(OAuth2TokenServiceDelegateAndroid);
140 }; 155 };
141 156
142 #endif // CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_DELEGATE_ANDROID_H_ 157 #endif // CHROME_BROWSER_SIGNIN_OAUTH2_TOKEN_SERVICE_DELEGATE_ANDROID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698