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" |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 152 |
153 void AndroidProfileOAuth2TokenService::ValidateAccounts(JNIEnv* env, | 153 void AndroidProfileOAuth2TokenService::ValidateAccounts(JNIEnv* env, |
154 jobject obj, | 154 jobject obj, |
155 jobjectArray accounts, | 155 jobjectArray accounts, |
156 jstring j_current_acc) { | 156 jstring j_current_acc) { |
157 std::vector<std::string> account_ids; | 157 std::vector<std::string> account_ids; |
158 base::android::AppendJavaStringArrayToStringVector(env, | 158 base::android::AppendJavaStringArrayToStringVector(env, |
159 accounts, | 159 accounts, |
160 &account_ids); | 160 &account_ids); |
161 std::string signed_in_account = ConvertJavaStringToUTF8(env, j_current_acc); | 161 std::string signed_in_account = ConvertJavaStringToUTF8(env, j_current_acc); |
| 162 ValidateAccounts(signed_in_account, account_ids); |
| 163 } |
162 | 164 |
| 165 void AndroidProfileOAuth2TokenService::ValidateAccounts( |
| 166 const std::string& signed_in_account, |
| 167 const std::vector<std::string>& account_ids) { |
163 if (signed_in_account.empty()) | 168 if (signed_in_account.empty()) |
164 return; | 169 return; |
165 | 170 |
166 if (std::find(account_ids.begin(), | 171 if (std::find(account_ids.begin(), |
167 account_ids.end(), | 172 account_ids.end(), |
168 signed_in_account) != account_ids.end()) { | 173 signed_in_account) != account_ids.end()) { |
169 // Currently signed in account still exists among accounts on system. | 174 // Currently signed in account still exists among accounts on system. |
| 175 std::vector<std::string> ids = GetAccounts(); |
| 176 |
| 177 // Always fire the primary signed in account first. |
170 FireRefreshTokenAvailable(signed_in_account); | 178 FireRefreshTokenAvailable(signed_in_account); |
| 179 |
| 180 for (std::vector<std::string>::iterator it = ids.begin(); |
| 181 it != ids.end(); it++) { |
| 182 if (*it != signed_in_account) { |
| 183 FireRefreshTokenAvailable(*it); |
| 184 } |
| 185 } |
171 } else { | 186 } else { |
172 // Currently signed in account does not any longer exist among accounts on | 187 // Currently signed in account does not any longer exist among accounts on |
173 // system. | 188 // system. |
174 FireRefreshTokenRevoked(signed_in_account); | 189 FireRefreshTokenRevoked(signed_in_account); |
175 } | 190 } |
176 } | 191 } |
177 | 192 |
178 void AndroidProfileOAuth2TokenService::FireRefreshTokenAvailableFromJava( | 193 void AndroidProfileOAuth2TokenService::FireRefreshTokenAvailableFromJava( |
179 JNIEnv* env, | 194 JNIEnv* env, |
180 jobject obj, | 195 jobject obj, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 GoogleServiceAuthError err(result ? | 259 GoogleServiceAuthError err(result ? |
245 GoogleServiceAuthError::NONE : | 260 GoogleServiceAuthError::NONE : |
246 GoogleServiceAuthError::CONNECTION_FAILED); | 261 GoogleServiceAuthError::CONNECTION_FAILED); |
247 heap_callback->Run(err, token, base::Time()); | 262 heap_callback->Run(err, token, base::Time()); |
248 } | 263 } |
249 | 264 |
250 // static | 265 // static |
251 bool AndroidProfileOAuth2TokenService::Register(JNIEnv* env) { | 266 bool AndroidProfileOAuth2TokenService::Register(JNIEnv* env) { |
252 return RegisterNativesImpl(env); | 267 return RegisterNativesImpl(env); |
253 } | 268 } |
OLD | NEW |