summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgogerald <gogerald@chromium.org>2015-09-23 19:52:59 -0700
committerCommit bot <commit-bot@chromium.org>2015-09-24 02:54:12 +0000
commitf3bccd6b7d15f3585bdfe924a6d3b33bcf90ea26 (patch)
tree6b79c312eefdb7ebcb97e565afbf621ae8760e4d
parentcb19f775e847043bdc6b9ed2159feb6cc792e0e2 (diff)
downloadchromium_src-f3bccd6b7d15f3585bdfe924a6d3b33bcf90ea26.zip
chromium_src-f3bccd6b7d15f3585bdfe924a6d3b33bcf90ea26.tar.gz
chromium_src-f3bccd6b7d15f3585bdfe924a6d3b33bcf90ea26.tar.bz2
Do not crash in case of messed or missed information.
This is a first step fix of below bug. It filters out invalid persistent accounts in OAuth2TokenService and avoids sending out refresh token revoked notification if its information in ATS is missing for some reason. Next step, we should understand how the user data been corrupted. BUG=535211 Review URL: https://codereview.chromium.org/1362043007 Cr-Commit-Position: refs/heads/master@{#350451}
-rw-r--r--chrome/browser/signin/oauth2_token_service_delegate_android.cc21
-rw-r--r--google_apis/gaia/oauth2_token_service_delegate.cc13
-rw-r--r--google_apis/gaia/oauth2_token_service_delegate.h2
3 files changed, 24 insertions, 12 deletions
diff --git a/chrome/browser/signin/oauth2_token_service_delegate_android.cc b/chrome/browser/signin/oauth2_token_service_delegate_android.cc
index bad1a24..6b88c6e 100644
--- a/chrome/browser/signin/oauth2_token_service_delegate_android.cc
+++ b/chrome/browser/signin/oauth2_token_service_delegate_android.cc
@@ -305,7 +305,8 @@ void OAuth2TokenServiceDelegateAndroid::ValidateAccounts(
void OAuth2TokenServiceDelegateAndroid::ValidateAccounts(
const std::string& signed_in_account,
bool force_notifications) {
- std::vector<std::string> prev_ids = GetAccounts();
+ std::vector<std::string> prev_stored_ids = GetAccounts();
+ std::vector<std::string> prev_ids;
std::vector<std::string> curr_ids = GetSystemAccountNames();
std::vector<std::string> refreshed_ids;
std::vector<std::string> revoked_ids;
@@ -314,8 +315,10 @@ void OAuth2TokenServiceDelegateAndroid::ValidateAccounts(
for (size_t i = 0; i < curr_ids.size(); ++i)
curr_ids[i] = MapAccountNameToAccountId(curr_ids[i]);
- for (size_t i = 0; i < prev_ids.size(); ++i)
- ValidateAccountId(prev_ids[i]);
+ for (size_t i = 0; i < prev_stored_ids.size(); ++i) {
+ if (ValidateAccountId(prev_stored_ids[i]))
+ prev_ids.push_back(prev_stored_ids[i]);
+ }
DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::ValidateAccounts:"
<< " sigined_in_account=" << signed_in_account
@@ -481,10 +484,14 @@ void OAuth2TokenServiceDelegateAndroid::FireRefreshTokenRevoked(
DVLOG(1) << "OAuth2TokenServiceDelegateAndroid::FireRefreshTokenRevoked id="
<< account_id;
JNIEnv* env = AttachCurrentThread();
- ScopedJavaLocalRef<jstring> account_name =
- ConvertUTF8ToJavaString(env, MapAccountIdToAccountName(account_id));
- Java_OAuth2TokenService_notifyRefreshTokenRevoked(env, java_ref_.obj(),
- account_name.obj());
+ std::string account_name = MapAccountIdToAccountName(account_id);
+ // Do not crash in case of missed information.
+ if (!account_name.empty()) {
+ ScopedJavaLocalRef<jstring> account =
+ ConvertUTF8ToJavaString(env, account_name);
+ Java_OAuth2TokenService_notifyRefreshTokenRevoked(env, java_ref_.obj(),
+ account.obj());
+ }
OAuth2TokenServiceDelegate::FireRefreshTokenRevoked(account_id);
}
diff --git a/google_apis/gaia/oauth2_token_service_delegate.cc b/google_apis/gaia/oauth2_token_service_delegate.cc
index aed5db8..3c5f75b 100644
--- a/google_apis/gaia/oauth2_token_service_delegate.cc
+++ b/google_apis/gaia/oauth2_token_service_delegate.cc
@@ -24,16 +24,21 @@ OAuth2TokenServiceDelegate::OAuth2TokenServiceDelegate()
OAuth2TokenServiceDelegate::~OAuth2TokenServiceDelegate() {
}
-void OAuth2TokenServiceDelegate::ValidateAccountId(
+bool OAuth2TokenServiceDelegate::ValidateAccountId(
const std::string& account_id) const {
- DCHECK(!account_id.empty());
+ bool valid = !account_id.empty();
// If the account is given as an email, make sure its a canonical email.
// Note that some tests don't use email strings as account id, and after
// the gaia id migration it won't be an email. So only check for
// canonicalization if the account_id is suspected to be an email.
- if (account_id.find('@') != std::string::npos)
- DCHECK_EQ(gaia::CanonicalizeEmail(account_id), account_id);
+ if (account_id.find('@') != std::string::npos &&
+ gaia::CanonicalizeEmail(account_id) != account_id) {
+ valid = false;
+ }
+
+ DCHECK(valid);
+ return valid;
}
void OAuth2TokenServiceDelegate::AddObserver(
diff --git a/google_apis/gaia/oauth2_token_service_delegate.h b/google_apis/gaia/oauth2_token_service_delegate.h
index 3a2d39f..24bf063 100644
--- a/google_apis/gaia/oauth2_token_service_delegate.h
+++ b/google_apis/gaia/oauth2_token_service_delegate.h
@@ -48,7 +48,7 @@ class OAuth2TokenServiceDelegate {
virtual void RevokeCredentials(const std::string& account_id) {}
virtual net::URLRequestContextGetter* GetRequestContext() const;
- void ValidateAccountId(const std::string& account_id) const;
+ bool ValidateAccountId(const std::string& account_id) const;
// Add or remove observers of this token service.
void AddObserver(OAuth2TokenService::Observer* observer);