X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2Fgoogle_apis%2Fgaia%2Fgaia_auth_util.cc;h=6532d190b8e9075a815347a66156df93aeee45cc;hb=ff3e2503a20db9193d323c1d19c38c68004dec4a;hp=f8f95c14f5b5770d6ff6950a7ff17b3caf45868d;hpb=7338fba38ba696536d1cc9d389afd716a6ab2fe6;p=platform%2Fframework%2Fweb%2Fcrosswalk.git diff --git a/src/google_apis/gaia/gaia_auth_util.cc b/src/google_apis/gaia/gaia_auth_util.cc index f8f95c1..6532d19 100644 --- a/src/google_apis/gaia/gaia_auth_util.cc +++ b/src/google_apis/gaia/gaia_auth_util.cc @@ -22,10 +22,12 @@ std::string CanonicalizeEmail(const std::string& email_address) { std::vector parts; char at = '@'; base::SplitString(email_address, at, &parts); - if (parts.size() != 2U) - NOTREACHED() << "expecting exactly one @, but got " << parts.size(); - else if (parts[1] == kGmailDomain) // only strip '.' for gmail accounts. + if (parts.size() != 2U) { + NOTREACHED() << "expecting exactly one @, but got " << parts.size()-1 << + " : " << email_address; + } else if (parts[1] == kGmailDomain) { // only strip '.' for gmail accounts. base::RemoveChars(parts[0], ".", &parts[0]); + } std::string new_email = StringToLowerASCII(JoinString(parts, at)); VLOG(1) << "Canonicalized " << email_address << " to " << new_email; return new_email; @@ -73,35 +75,48 @@ bool IsGaiaSignonRealm(const GURL& url) { } -std::vector ParseListAccountsData(const std::string& data) { - std::vector account_ids; +bool ParseListAccountsData( + const std::string& data, + std::vector >* accounts) { + accounts->clear(); // Parse returned data and make sure we have data. scoped_ptr value(base::JSONReader::Read(data)); if (!value) - return account_ids; + return false; base::ListValue* list; if (!value->GetAsList(&list) || list->GetSize() < 2) - return account_ids; + return false; // Get list of account info. - base::ListValue* accounts; - if (!list->GetList(1, &accounts) || accounts == NULL) - return account_ids; + base::ListValue* account_list; + if (!list->GetList(1, &account_list) || accounts == NULL) + return false; // Build a vector of accounts from the cookie. Order is important: the first // account in the list is the primary account. - for (size_t i = 0; i < accounts->GetSize(); ++i) { + for (size_t i = 0; i < account_list->GetSize(); ++i) { base::ListValue* account; - if (accounts->GetList(i, &account) && account != NULL) { + if (account_list->GetList(i, &account) && account != NULL) { std::string email; - if (account->GetString(3, &email) && !email.empty()) - account_ids.push_back(email); + // Canonicalize the email since ListAccounts returns "display email". + if (account->GetString(3, &email) && !email.empty()) { + // New version if ListAccounts indicates whether the email's session + // is still valid or not. If this value is present and false, assume + // its invalid. Otherwise assume it's valid to remain compatible with + // old version. + int is_email_valid = 1; + if (!account->GetInteger(9, &is_email_valid)) + is_email_valid = 1; + + accounts->push_back( + std::make_pair(CanonicalizeEmail(email), is_email_valid != 0)); + } } } - return account_ids; + return true; } } // namespace gaia