OLD | NEW |
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 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 j_accounts.obj(), | 211 j_accounts.obj(), |
211 &accounts); | 212 &accounts); |
212 return accounts; | 213 return accounts; |
213 } | 214 } |
214 | 215 |
215 OAuth2AccessTokenFetcher* | 216 OAuth2AccessTokenFetcher* |
216 AndroidProfileOAuth2TokenService::CreateAccessTokenFetcher( | 217 AndroidProfileOAuth2TokenService::CreateAccessTokenFetcher( |
217 const std::string& account_id, | 218 const std::string& account_id, |
218 net::URLRequestContextGetter* getter, | 219 net::URLRequestContextGetter* getter, |
219 OAuth2AccessTokenConsumer* consumer) { | 220 OAuth2AccessTokenConsumer* consumer) { |
220 DCHECK(!account_id.empty()); | 221 ValidateAccountId(account_id); |
221 return new AndroidAccessTokenFetcher(consumer, account_id); | 222 return new AndroidAccessTokenFetcher(consumer, account_id); |
222 } | 223 } |
223 | 224 |
224 void AndroidProfileOAuth2TokenService::InvalidateOAuth2Token( | 225 void AndroidProfileOAuth2TokenService::InvalidateOAuth2Token( |
225 const std::string& account_id, | 226 const std::string& account_id, |
226 const std::string& client_id, | 227 const std::string& client_id, |
227 const ScopeSet& scopes, | 228 const ScopeSet& scopes, |
228 const std::string& access_token) { | 229 const std::string& access_token) { |
| 230 ValidateAccountId(account_id); |
229 OAuth2TokenService::InvalidateOAuth2Token(account_id, | 231 OAuth2TokenService::InvalidateOAuth2Token(account_id, |
230 client_id, | 232 client_id, |
231 scopes, | 233 scopes, |
232 access_token); | 234 access_token); |
233 | 235 |
234 JNIEnv* env = AttachCurrentThread(); | 236 JNIEnv* env = AttachCurrentThread(); |
235 ScopedJavaLocalRef<jstring> j_access_token = | 237 ScopedJavaLocalRef<jstring> j_access_token = |
236 ConvertUTF8ToJavaString(env, access_token); | 238 ConvertUTF8ToJavaString(env, access_token); |
237 Java_OAuth2TokenService_invalidateOAuth2AuthToken( | 239 Java_OAuth2TokenService_invalidateOAuth2AuthToken( |
238 env, base::android::GetApplicationContext(), | 240 env, base::android::GetApplicationContext(), |
239 j_access_token.obj()); | 241 j_access_token.obj()); |
240 } | 242 } |
241 | 243 |
242 void AndroidProfileOAuth2TokenService::ValidateAccounts( | 244 void AndroidProfileOAuth2TokenService::ValidateAccounts( |
243 JNIEnv* env, | 245 JNIEnv* env, |
244 jobject obj, | 246 jobject obj, |
245 jstring j_current_acc, | 247 jstring j_current_acc, |
246 jboolean j_force_notifications) { | 248 jboolean j_force_notifications) { |
247 VLOG(1) << "AndroidProfileOAuth2TokenService::ValidateAccounts from java"; | 249 VLOG(1) << "AndroidProfileOAuth2TokenService::ValidateAccounts from java"; |
248 std::string signed_in_account = ConvertJavaStringToUTF8(env, j_current_acc); | 250 std::string signed_in_account = ConvertJavaStringToUTF8(env, j_current_acc); |
| 251 if (!signed_in_account.empty()) |
| 252 signed_in_account = gaia::CanonicalizeEmail(signed_in_account); |
249 ValidateAccounts(signed_in_account, j_force_notifications != JNI_FALSE); | 253 ValidateAccounts(signed_in_account, j_force_notifications != JNI_FALSE); |
250 } | 254 } |
251 | 255 |
252 void AndroidProfileOAuth2TokenService::ValidateAccounts( | 256 void AndroidProfileOAuth2TokenService::ValidateAccounts( |
253 const std::string& signed_in_account, | 257 const std::string& signed_in_account, |
254 bool force_notifications) { | 258 bool force_notifications) { |
255 std::vector<std::string> prev_ids = GetAccounts(); | 259 std::vector<std::string> prev_ids = GetAccounts(); |
256 std::vector<std::string> curr_ids = GetSystemAccounts(); | 260 std::vector<std::string> curr_ids = GetSystemAccounts(); |
257 std::vector<std::string> refreshed_ids; | 261 std::vector<std::string> refreshed_ids; |
258 std::vector<std::string> revoked_ids; | 262 std::vector<std::string> revoked_ids; |
259 | 263 |
| 264 // Canonicalize system accounts. |prev_ids| is already done. |
| 265 for (size_t i = 0; i < curr_ids.size(); ++i) |
| 266 curr_ids[i] = gaia::CanonicalizeEmail(curr_ids[i]); |
| 267 for (size_t i = 0; i < prev_ids.size(); ++i) |
| 268 ValidateAccountId(prev_ids[i]); |
| 269 |
260 VLOG(1) << "AndroidProfileOAuth2TokenService::ValidateAccounts:" | 270 VLOG(1) << "AndroidProfileOAuth2TokenService::ValidateAccounts:" |
261 << " sigined_in_account=" << signed_in_account | 271 << " sigined_in_account=" << signed_in_account |
262 << " prev_ids=" << prev_ids.size() | 272 << " prev_ids=" << prev_ids.size() |
263 << " curr_ids=" << curr_ids.size() | 273 << " curr_ids=" << curr_ids.size() |
264 << " force=" << (force_notifications ? "true" : "false"); | 274 << " force=" << (force_notifications ? "true" : "false"); |
265 | 275 |
266 if (!ValidateAccounts(signed_in_account, prev_ids, curr_ids, refreshed_ids, | 276 if (!ValidateAccounts(signed_in_account, prev_ids, curr_ids, refreshed_ids, |
267 revoked_ids, force_notifications)) { | 277 revoked_ids, force_notifications)) { |
268 curr_ids.clear(); | 278 curr_ids.clear(); |
269 } | 279 } |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 GoogleServiceAuthError err(result ? | 463 GoogleServiceAuthError err(result ? |
454 GoogleServiceAuthError::NONE : | 464 GoogleServiceAuthError::NONE : |
455 GoogleServiceAuthError::CONNECTION_FAILED); | 465 GoogleServiceAuthError::CONNECTION_FAILED); |
456 heap_callback->Run(err, token, base::Time()); | 466 heap_callback->Run(err, token, base::Time()); |
457 } | 467 } |
458 | 468 |
459 // static | 469 // static |
460 bool AndroidProfileOAuth2TokenService::Register(JNIEnv* env) { | 470 bool AndroidProfileOAuth2TokenService::Register(JNIEnv* env) { |
461 return RegisterNativesImpl(env); | 471 return RegisterNativesImpl(env); |
462 } | 472 } |
OLD | NEW |