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

Side by Side Diff: chrome/browser/signin/android_profile_oauth2_token_service.cc

Issue 213823004: Calls FireRefreshTokenRevoked if an account is removed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix some issues. Created 6 years, 8 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 #include "chrome/browser/signin/android_profile_oauth2_token_service.h" 5 #include "chrome/browser/signin/android_profile_oauth2_token_service.h"
6 6
7 #include "base/android/jni_android.h" 7 #include "base/android/jni_android.h"
8 #include "base/android/jni_array.h" 8 #include "base/android/jni_array.h"
9 #include "base/android/jni_string.h" 9 #include "base/android/jni_string.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 access_token); 150 access_token);
151 151
152 JNIEnv* env = AttachCurrentThread(); 152 JNIEnv* env = AttachCurrentThread();
153 ScopedJavaLocalRef<jstring> j_access_token = 153 ScopedJavaLocalRef<jstring> j_access_token =
154 ConvertUTF8ToJavaString(env, access_token); 154 ConvertUTF8ToJavaString(env, access_token);
155 Java_OAuth2TokenService_invalidateOAuth2AuthToken( 155 Java_OAuth2TokenService_invalidateOAuth2AuthToken(
156 env, base::android::GetApplicationContext(), 156 env, base::android::GetApplicationContext(),
157 j_access_token.obj()); 157 j_access_token.obj());
158 } 158 }
159 159
160 void AndroidProfileOAuth2TokenService::ValidateAccounts(JNIEnv* env, 160 void AndroidProfileOAuth2TokenService::ValidateAccounts(
161 jobject obj, 161 JNIEnv* env,
162 jobjectArray accounts, 162 jobject obj,
163 jstring j_current_acc) { 163 jobjectArray prev_account_ids,
164 jstring j_current_acc) {
164 std::vector<std::string> account_ids; 165 std::vector<std::string> account_ids;
165 base::android::AppendJavaStringArrayToStringVector(env, 166 base::android::AppendJavaStringArrayToStringVector(env,
166 accounts, 167 prev_account_ids,
167 &account_ids); 168 &account_ids);
168 std::string signed_in_account = ConvertJavaStringToUTF8(env, j_current_acc); 169 std::string signed_in_account = ConvertJavaStringToUTF8(env, j_current_acc);
169 ValidateAccounts(signed_in_account, account_ids); 170 ValidateAccounts(signed_in_account, account_ids);
170 } 171 }
171 172
172 void AndroidProfileOAuth2TokenService::ValidateAccounts( 173 void AndroidProfileOAuth2TokenService::ValidateAccounts(
173 const std::string& signed_in_account, 174 const std::string& signed_in_account,
174 const std::vector<std::string>& account_ids) { 175 const std::vector<std::string>& prev_account_ids) {
175 if (signed_in_account.empty()) 176 if (signed_in_account.empty())
176 return; 177 return;
177 178
179 std::vector<std::string> account_ids = GetAccounts();
178 if (std::find(account_ids.begin(), 180 if (std::find(account_ids.begin(),
179 account_ids.end(), 181 account_ids.end(),
180 signed_in_account) != account_ids.end()) { 182 signed_in_account) != account_ids.end()) {
181 // Currently signed in account still exists among accounts on system. 183 // Test to see if an account is removed from the Android AccountManager.
182 std::vector<std::string> ids = GetAccounts(); 184 // If so, invoke FireRefreshTokenRevoked to notify the reconcilor.
185 for (std::vector<std::string>::const_iterator it = prev_account_ids.begin();
186 it != prev_account_ids.end(); it++) {
187 if (*it == signed_in_account)
188 continue;
189
190 if (std::find(account_ids.begin(),
191 account_ids.end(),
192 *it) == account_ids.end()) {
193 FireRefreshTokenRevoked(*it);
194 }
195 }
183 196
184 // Always fire the primary signed in account first. 197 // Always fire the primary signed in account first.
185 FireRefreshTokenAvailable(signed_in_account); 198 FireRefreshTokenAvailable(signed_in_account);
186 199
187 for (std::vector<std::string>::iterator it = ids.begin(); 200 for (std::vector<std::string>::iterator it = account_ids.begin();
188 it != ids.end(); it++) { 201 it != account_ids.end(); it++) {
189 if (*it != signed_in_account) { 202 if (*it != signed_in_account) {
190 FireRefreshTokenAvailable(*it); 203 FireRefreshTokenAvailable(*it);
191 } 204 }
192 } 205 }
193 } else { 206 } else {
194 // Currently signed in account does not any longer exist among accounts on 207 // Currently signed in account does not any longer exist among accounts on
195 // system. 208 // system together with all other accounts.
196 FireRefreshTokenRevoked(signed_in_account); 209 for (std::vector<std::string>::iterator it = account_ids.begin();
210 it != account_ids.end(); it++) {
Roger Tawa OOO till Jul 10th 2014/04/08 20:40:53 Should this be |prev_account_ids| instead of |acco
acleung1 2014/04/09 00:55:00 Yes. It will cover the case where user deletes ano
211 FireRefreshTokenRevoked(*it);
212 }
197 } 213 }
198 } 214 }
199 215
200 void AndroidProfileOAuth2TokenService::FireRefreshTokenAvailableFromJava( 216 void AndroidProfileOAuth2TokenService::FireRefreshTokenAvailableFromJava(
201 JNIEnv* env, 217 JNIEnv* env,
202 jobject obj, 218 jobject obj,
203 const jstring account_name) { 219 const jstring account_name) {
204 std::string account_id = ConvertJavaStringToUTF8(env, account_name); 220 std::string account_id = ConvertJavaStringToUTF8(env, account_name);
205 AndroidProfileOAuth2TokenService::FireRefreshTokenAvailable(account_id); 221 AndroidProfileOAuth2TokenService::FireRefreshTokenAvailable(account_id);
206 } 222 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 261
246 void AndroidProfileOAuth2TokenService::FireRefreshTokensLoaded() { 262 void AndroidProfileOAuth2TokenService::FireRefreshTokensLoaded() {
247 // Notify native observers. 263 // Notify native observers.
248 OAuth2TokenService::FireRefreshTokensLoaded(); 264 OAuth2TokenService::FireRefreshTokensLoaded();
249 // Notify Java observers. 265 // Notify Java observers.
250 JNIEnv* env = AttachCurrentThread(); 266 JNIEnv* env = AttachCurrentThread();
251 Java_OAuth2TokenService_notifyRefreshTokensLoaded( 267 Java_OAuth2TokenService_notifyRefreshTokensLoaded(
252 env, java_ref_.obj()); 268 env, java_ref_.obj());
253 } 269 }
254 270
271 void AndroidProfileOAuth2TokenService::RevokeAllCredentials() {
272 std::vector<std::string> accounts = GetAccounts();
273 for (std::vector<std::string>::iterator it = accounts.begin();
274 it != accounts.end(); it++) {
275 FireRefreshTokenRevoked(*it);
276 }
277 }
278
255 // Called from Java when fetching of an OAuth2 token is finished. The 279 // Called from Java when fetching of an OAuth2 token is finished. The
256 // |authToken| param is only valid when |result| is true. 280 // |authToken| param is only valid when |result| is true.
257 void OAuth2TokenFetched(JNIEnv* env, jclass clazz, 281 void OAuth2TokenFetched(JNIEnv* env, jclass clazz,
258 jstring authToken, 282 jstring authToken,
259 jboolean result, 283 jboolean result,
260 jlong nativeCallback) { 284 jlong nativeCallback) {
261 std::string token = ConvertJavaStringToUTF8(env, authToken); 285 std::string token = ConvertJavaStringToUTF8(env, authToken);
262 scoped_ptr<FetchOAuth2TokenCallback> heap_callback( 286 scoped_ptr<FetchOAuth2TokenCallback> heap_callback(
263 reinterpret_cast<FetchOAuth2TokenCallback*>(nativeCallback)); 287 reinterpret_cast<FetchOAuth2TokenCallback*>(nativeCallback));
264 // Android does not provide enough information to know if the credentials are 288 // Android does not provide enough information to know if the credentials are
265 // wrong, so assume any error is transient by using CONNECTION_FAILED. 289 // wrong, so assume any error is transient by using CONNECTION_FAILED.
266 GoogleServiceAuthError err(result ? 290 GoogleServiceAuthError err(result ?
267 GoogleServiceAuthError::NONE : 291 GoogleServiceAuthError::NONE :
268 GoogleServiceAuthError::CONNECTION_FAILED); 292 GoogleServiceAuthError::CONNECTION_FAILED);
269 heap_callback->Run(err, token, base::Time()); 293 heap_callback->Run(err, token, base::Time());
270 } 294 }
271 295
272 // static 296 // static
273 bool AndroidProfileOAuth2TokenService::Register(JNIEnv* env) { 297 bool AndroidProfileOAuth2TokenService::Register(JNIEnv* env) {
274 return RegisterNativesImpl(env); 298 return RegisterNativesImpl(env);
275 } 299 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698