Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Side by Side Diff: google_apis/gaia/gaia_auth_util.cc

Issue 1162103003: ListAccounts will return the Gaia ID as well as the email of the account. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CrOS #2 (I told you so) - this time for unit tests Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 25 matching lines...) Expand all
36 base::RemoveChars(parts[0], ".", &parts[0]); 36 base::RemoveChars(parts[0], ".", &parts[0]);
37 } 37 }
38 38
39 std::string new_email = base::StringToLowerASCII(JoinString(parts, at)); 39 std::string new_email = base::StringToLowerASCII(JoinString(parts, at));
40 VLOG(1) << "Canonicalized " << email_address << " to " << new_email; 40 VLOG(1) << "Canonicalized " << email_address << " to " << new_email;
41 return new_email; 41 return new_email;
42 } 42 }
43 43
44 } // namespace 44 } // namespace
45 45
46
47 ListedAccount::ListedAccount() {}
48
49 ListedAccount::~ListedAccount() {}
50
51 bool ListedAccount::operator==(const ListedAccount& other) const {
52 return email == other.email &&
53 gaia_id == other.gaia_id &&
54 valid == other.valid &&
55 raw_email == other.raw_email;
Roger Tawa OOO till Jul 10th 2015/06/02 21:58:42 Do we need to check all fields? Should be enough
56 }
57
46 std::string CanonicalizeEmail(const std::string& email_address) { 58 std::string CanonicalizeEmail(const std::string& email_address) {
47 // CanonicalizeEmail() is called to process email strings that are eventually 59 // CanonicalizeEmail() is called to process email strings that are eventually
48 // shown to the user, and may also be used in persisting email strings. To 60 // shown to the user, and may also be used in persisting email strings. To
49 // avoid breaking this existing behavior, this function will not try to 61 // avoid breaking this existing behavior, this function will not try to
50 // change googlemail to gmail. 62 // change googlemail to gmail.
51 return CanonicalizeEmailImpl(email_address, false); 63 return CanonicalizeEmailImpl(email_address, false);
52 } 64 }
53 65
54 std::string CanonicalizeDomain(const std::string& domain) { 66 std::string CanonicalizeDomain(const std::string& domain) {
55 // Canonicalization of domain names means lower-casing them. Make sure to 67 // Canonicalization of domain names means lower-casing them. Make sure to
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 99
88 bool IsGaiaSignonRealm(const GURL& url) { 100 bool IsGaiaSignonRealm(const GURL& url) {
89 if (!url.SchemeIsCryptographic()) 101 if (!url.SchemeIsCryptographic())
90 return false; 102 return false;
91 103
92 return url == GaiaUrls::GetInstance()->gaia_url(); 104 return url == GaiaUrls::GetInstance()->gaia_url();
93 } 105 }
94 106
95 107
96 bool ParseListAccountsData( 108 bool ParseListAccountsData(
97 const std::string& data, 109 const std::string& data, std::vector<ListedAccount>* accounts) {
98 std::vector<std::pair<std::string, bool> >* accounts) {
99 accounts->clear(); 110 accounts->clear();
100 111
101 // Parse returned data and make sure we have data. 112 // Parse returned data and make sure we have data.
102 scoped_ptr<base::Value> value = base::JSONReader::Read(data); 113 scoped_ptr<base::Value> value = base::JSONReader::Read(data);
103 if (!value) 114 if (!value)
104 return false; 115 return false;
105 116
106 base::ListValue* list; 117 base::ListValue* list;
107 if (!value->GetAsList(&list) || list->GetSize() < 2) 118 if (!value->GetAsList(&list) || list->GetSize() < 2)
108 return false; 119 return false;
(...skipping 12 matching lines...) Expand all
121 // Canonicalize the email since ListAccounts returns "display email". 132 // Canonicalize the email since ListAccounts returns "display email".
122 if (account->GetString(3, &email) && !email.empty()) { 133 if (account->GetString(3, &email) && !email.empty()) {
123 // New version if ListAccounts indicates whether the email's session 134 // New version if ListAccounts indicates whether the email's session
124 // is still valid or not. If this value is present and false, assume 135 // is still valid or not. If this value is present and false, assume
125 // its invalid. Otherwise assume it's valid to remain compatible with 136 // its invalid. Otherwise assume it's valid to remain compatible with
126 // old version. 137 // old version.
127 int is_email_valid = 1; 138 int is_email_valid = 1;
128 if (!account->GetInteger(9, &is_email_valid)) 139 if (!account->GetInteger(9, &is_email_valid))
129 is_email_valid = 1; 140 is_email_valid = 1;
130 141
131 accounts->push_back( 142 std::string gaia_id;
132 std::make_pair(CanonicalizeEmail(email), is_email_valid != 0)); 143 // ListAccounts must also return the Gaia Id.
144 if (account->GetString(10, &gaia_id) && !gaia_id.empty()) {
145 ListedAccount listed_account;
146 listed_account.email = CanonicalizeEmail(email);
147 listed_account.gaia_id = gaia_id;
148 listed_account.valid = is_email_valid != 0;
149 listed_account.raw_email = email;
150 accounts->push_back(listed_account);
151 }
133 } 152 }
134 } 153 }
135 } 154 }
136 155
137 return true; 156 return true;
138 } 157 }
139 158
140 } // namespace gaia 159 } // namespace gaia
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698