OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "google_apis/gaia/gaia_auth_util.h" | 5 #include "google_apis/gaia/gaia_auth_util.h" |
6 | 6 |
7 #include "base/json/json_reader.h" | 7 #include "base/json/json_reader.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/strings/string_split.h" | 9 #include "base/strings/string_split.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 } | 68 } |
69 | 69 |
70 bool IsGaiaSignonRealm(const GURL& url) { | 70 bool IsGaiaSignonRealm(const GURL& url) { |
71 if (!url.SchemeIsSecure()) | 71 if (!url.SchemeIsSecure()) |
72 return false; | 72 return false; |
73 | 73 |
74 return url == GaiaUrls::GetInstance()->gaia_url(); | 74 return url == GaiaUrls::GetInstance()->gaia_url(); |
75 } | 75 } |
76 | 76 |
77 | 77 |
78 bool ParseListAccountsData(const std::string& data, | 78 bool ParseListAccountsData( |
79 std::vector<std::string>* accounts) { | 79 const std::string& data, |
| 80 std::vector<std::pair<std::string, bool> >* accounts) { |
80 accounts->clear(); | 81 accounts->clear(); |
81 | 82 |
82 // Parse returned data and make sure we have data. | 83 // Parse returned data and make sure we have data. |
83 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); | 84 scoped_ptr<base::Value> value(base::JSONReader::Read(data)); |
84 if (!value) | 85 if (!value) |
85 return false; | 86 return false; |
86 | 87 |
87 base::ListValue* list; | 88 base::ListValue* list; |
88 if (!value->GetAsList(&list) || list->GetSize() < 2) | 89 if (!value->GetAsList(&list) || list->GetSize() < 2) |
89 return false; | 90 return false; |
90 | 91 |
91 // Get list of account info. | 92 // Get list of account info. |
92 base::ListValue* account_list; | 93 base::ListValue* account_list; |
93 if (!list->GetList(1, &account_list) || accounts == NULL) | 94 if (!list->GetList(1, &account_list) || accounts == NULL) |
94 return false; | 95 return false; |
95 | 96 |
96 // Build a vector of accounts from the cookie. Order is important: the first | 97 // Build a vector of accounts from the cookie. Order is important: the first |
97 // account in the list is the primary account. | 98 // account in the list is the primary account. |
98 for (size_t i = 0; i < account_list->GetSize(); ++i) { | 99 for (size_t i = 0; i < account_list->GetSize(); ++i) { |
99 base::ListValue* account; | 100 base::ListValue* account; |
100 if (account_list->GetList(i, &account) && account != NULL) { | 101 if (account_list->GetList(i, &account) && account != NULL) { |
101 std::string email; | 102 std::string email; |
102 // Canonicalize the email since ListAccounts returns "display email". | 103 // Canonicalize the email since ListAccounts returns "display email". |
103 if (account->GetString(3, &email) && !email.empty()) | 104 if (account->GetString(3, &email) && !email.empty()) { |
104 accounts->push_back(CanonicalizeEmail(email)); | 105 // New version if ListAccounts indicates whether the email's session |
| 106 // is still valid or not. If this value is present and false, assume |
| 107 // its invalid. Otherwise assume it's valid to remain compatible with |
| 108 // old version. |
| 109 int is_email_valid = 1; |
| 110 if (!account->GetInteger(9, &is_email_valid)) |
| 111 is_email_valid = 1; |
| 112 |
| 113 accounts->push_back( |
| 114 std::make_pair(CanonicalizeEmail(email), is_email_valid != 0)); |
| 115 } |
105 } | 116 } |
106 } | 117 } |
107 | 118 |
108 return true; | 119 return true; |
109 } | 120 } |
110 | 121 |
111 } // namespace gaia | 122 } // namespace gaia |
OLD | NEW |