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

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

Issue 617183003: Make sure GetAuthenticatedAccountId() returns a canonicalized id. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments Created 6 years, 2 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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "chrome/browser/profiles/profile_android.h" 12 #include "chrome/browser/profiles/profile_android.h"
13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" 13 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h"
14 #include "chrome/browser/sync/profile_sync_service_android.h" 14 #include "chrome/browser/sync/profile_sync_service_android.h"
15 #include "content/public/browser/browser_thread.h" 15 #include "content/public/browser/browser_thread.h"
16 #include "google_apis/gaia/gaia_auth_util.h"
16 #include "google_apis/gaia/oauth2_access_token_fetcher.h" 17 #include "google_apis/gaia/oauth2_access_token_fetcher.h"
17 #include "jni/OAuth2TokenService_jni.h" 18 #include "jni/OAuth2TokenService_jni.h"
18 19
19 using base::android::AttachCurrentThread; 20 using base::android::AttachCurrentThread;
20 using base::android::ConvertJavaStringToUTF8; 21 using base::android::ConvertJavaStringToUTF8;
21 using base::android::ConvertUTF8ToJavaString; 22 using base::android::ConvertUTF8ToJavaString;
22 using base::android::ScopedJavaLocalRef; 23 using base::android::ScopedJavaLocalRef;
23 using content::BrowserThread; 24 using content::BrowserThread;
24 25
25 namespace { 26 namespace {
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 165
165 if (!is_testing_profile_) { 166 if (!is_testing_profile_) {
166 Java_OAuth2TokenService_validateAccounts( 167 Java_OAuth2TokenService_validateAccounts(
167 AttachCurrentThread(), java_ref_.obj(), 168 AttachCurrentThread(), java_ref_.obj(),
168 base::android::GetApplicationContext(), JNI_TRUE); 169 base::android::GetApplicationContext(), JNI_TRUE);
169 } 170 }
170 } 171 }
171 172
172 bool AndroidProfileOAuth2TokenService::RefreshTokenIsAvailable( 173 bool AndroidProfileOAuth2TokenService::RefreshTokenIsAvailable(
173 const std::string& account_id) const { 174 const std::string& account_id) const {
175 ValidateAccountId(account_id);
174 JNIEnv* env = AttachCurrentThread(); 176 JNIEnv* env = AttachCurrentThread();
175 ScopedJavaLocalRef<jstring> j_account_id = 177 ScopedJavaLocalRef<jstring> j_account_id =
176 ConvertUTF8ToJavaString(env, account_id); 178 ConvertUTF8ToJavaString(env, account_id);
177 jboolean refresh_token_is_available = 179 jboolean refresh_token_is_available =
178 Java_OAuth2TokenService_hasOAuth2RefreshToken( 180 Java_OAuth2TokenService_hasOAuth2RefreshToken(
179 env, base::android::GetApplicationContext(), 181 env, base::android::GetApplicationContext(),
180 j_account_id.obj()); 182 j_account_id.obj());
181 return refresh_token_is_available == JNI_TRUE; 183 return refresh_token_is_available == JNI_TRUE;
182 } 184 }
183 185
(...skipping 26 matching lines...) Expand all
210 j_accounts.obj(), 212 j_accounts.obj(),
211 &accounts); 213 &accounts);
212 return accounts; 214 return accounts;
213 } 215 }
214 216
215 OAuth2AccessTokenFetcher* 217 OAuth2AccessTokenFetcher*
216 AndroidProfileOAuth2TokenService::CreateAccessTokenFetcher( 218 AndroidProfileOAuth2TokenService::CreateAccessTokenFetcher(
217 const std::string& account_id, 219 const std::string& account_id,
218 net::URLRequestContextGetter* getter, 220 net::URLRequestContextGetter* getter,
219 OAuth2AccessTokenConsumer* consumer) { 221 OAuth2AccessTokenConsumer* consumer) {
220 DCHECK(!account_id.empty()); 222 ValidateAccountId(account_id);
221 return new AndroidAccessTokenFetcher(consumer, account_id); 223 return new AndroidAccessTokenFetcher(consumer, account_id);
222 } 224 }
223 225
224 void AndroidProfileOAuth2TokenService::InvalidateOAuth2Token( 226 void AndroidProfileOAuth2TokenService::InvalidateOAuth2Token(
225 const std::string& account_id, 227 const std::string& account_id,
226 const std::string& client_id, 228 const std::string& client_id,
227 const ScopeSet& scopes, 229 const ScopeSet& scopes,
228 const std::string& access_token) { 230 const std::string& access_token) {
231 ValidateAccountId(account_id);
229 OAuth2TokenService::InvalidateOAuth2Token(account_id, 232 OAuth2TokenService::InvalidateOAuth2Token(account_id,
230 client_id, 233 client_id,
231 scopes, 234 scopes,
232 access_token); 235 access_token);
233 236
234 JNIEnv* env = AttachCurrentThread(); 237 JNIEnv* env = AttachCurrentThread();
235 ScopedJavaLocalRef<jstring> j_access_token = 238 ScopedJavaLocalRef<jstring> j_access_token =
236 ConvertUTF8ToJavaString(env, access_token); 239 ConvertUTF8ToJavaString(env, access_token);
237 Java_OAuth2TokenService_invalidateOAuth2AuthToken( 240 Java_OAuth2TokenService_invalidateOAuth2AuthToken(
238 env, base::android::GetApplicationContext(), 241 env, base::android::GetApplicationContext(),
239 j_access_token.obj()); 242 j_access_token.obj());
240 } 243 }
241 244
242 void AndroidProfileOAuth2TokenService::ValidateAccounts( 245 void AndroidProfileOAuth2TokenService::ValidateAccounts(
243 JNIEnv* env, 246 JNIEnv* env,
244 jobject obj, 247 jobject obj,
245 jstring j_current_acc, 248 jstring j_current_acc,
246 jboolean j_force_notifications) { 249 jboolean j_force_notifications) {
247 VLOG(1) << "AndroidProfileOAuth2TokenService::ValidateAccounts from java"; 250 VLOG(1) << "AndroidProfileOAuth2TokenService::ValidateAccounts from java";
248 std::string signed_in_account = ConvertJavaStringToUTF8(env, j_current_acc); 251 std::string signed_in_account = ConvertJavaStringToUTF8(env, j_current_acc);
252 if (!signed_in_account.empty())
253 signed_in_account = gaia::CanonicalizeEmail(signed_in_account);
249 ValidateAccounts(signed_in_account, j_force_notifications != JNI_FALSE); 254 ValidateAccounts(signed_in_account, j_force_notifications != JNI_FALSE);
250 } 255 }
251 256
252 void AndroidProfileOAuth2TokenService::ValidateAccounts( 257 void AndroidProfileOAuth2TokenService::ValidateAccounts(
253 const std::string& signed_in_account, 258 const std::string& signed_in_account,
254 bool force_notifications) { 259 bool force_notifications) {
255 std::vector<std::string> prev_ids = GetAccounts(); 260 std::vector<std::string> prev_ids = GetAccounts();
256 std::vector<std::string> curr_ids = GetSystemAccounts(); 261 std::vector<std::string> curr_ids = GetSystemAccounts();
257 std::vector<std::string> refreshed_ids; 262 std::vector<std::string> refreshed_ids;
258 std::vector<std::string> revoked_ids; 263 std::vector<std::string> revoked_ids;
259 264
265 // Canonicalize system accounts. |prev_ids| is already done.
266 for (size_t i = 0; i < curr_ids.size(); ++i)
267 curr_ids[i] = gaia::CanonicalizeEmail(curr_ids[i]);
268 for (size_t i = 0; i < prev_ids.size(); ++i)
269 ValidateAccountId(prev_ids[i]);
270
260 VLOG(1) << "AndroidProfileOAuth2TokenService::ValidateAccounts:" 271 VLOG(1) << "AndroidProfileOAuth2TokenService::ValidateAccounts:"
261 << " sigined_in_account=" << signed_in_account 272 << " sigined_in_account=" << signed_in_account
262 << " prev_ids=" << prev_ids.size() 273 << " prev_ids=" << prev_ids.size()
263 << " curr_ids=" << curr_ids.size() 274 << " curr_ids=" << curr_ids.size()
264 << " force=" << (force_notifications ? "true" : "false"); 275 << " force=" << (force_notifications ? "true" : "false");
265 276
266 if (!ValidateAccounts(signed_in_account, prev_ids, curr_ids, refreshed_ids, 277 if (!ValidateAccounts(signed_in_account, prev_ids, curr_ids, refreshed_ids,
267 revoked_ids, force_notifications)) { 278 revoked_ids, force_notifications)) {
268 curr_ids.clear(); 279 curr_ids.clear();
269 } 280 }
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 GoogleServiceAuthError err(result ? 464 GoogleServiceAuthError err(result ?
454 GoogleServiceAuthError::NONE : 465 GoogleServiceAuthError::NONE :
455 GoogleServiceAuthError::CONNECTION_FAILED); 466 GoogleServiceAuthError::CONNECTION_FAILED);
456 heap_callback->Run(err, token, base::Time()); 467 heap_callback->Run(err, token, base::Time());
457 } 468 }
458 469
459 // static 470 // static
460 bool AndroidProfileOAuth2TokenService::Register(JNIEnv* env) { 471 bool AndroidProfileOAuth2TokenService::Register(JNIEnv* env) {
461 return RegisterNativesImpl(env); 472 return RegisterNativesImpl(env);
462 } 473 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698