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

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

Issue 2575603002: Add data usage tracking for GAIA auth api (Closed)
Patch Set: rebased Created 4 years 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
11 #include "base/json/json_reader.h" 11 #include "base/json/json_reader.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/strings/string_split.h" 13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/values.h" 15 #include "base/values.h"
16 #include "google_apis/gaia/gaia_urls.h" 16 #include "google_apis/gaia/gaia_urls.h"
17 #include "net/url_request/url_fetcher.h"
18 #include "net/url_request/url_request.h"
17 #include "url/gurl.h" 19 #include "url/gurl.h"
18 20
19 namespace gaia { 21 namespace gaia {
20 22
21 namespace { 23 namespace {
22 24
23 const char kGmailDomain[] = "gmail.com"; 25 const char kGmailDomain[] = "gmail.com";
24 const char kGooglemailDomain[] = "googlemail.com"; 26 const char kGooglemailDomain[] = "googlemail.com";
25 27
28 const void* kURLRequestUserDataKey = &kURLRequestUserDataKey;
msarda 2017/01/23 09:29:28 This is the first time I see this kind of definiti
Raj 2017/01/23 18:47:11 Done.
29
26 std::string CanonicalizeEmailImpl(const std::string& email_address, 30 std::string CanonicalizeEmailImpl(const std::string& email_address,
27 bool change_googlemail_to_gmail) { 31 bool change_googlemail_to_gmail) {
28 std::vector<std::string> parts = base::SplitString( 32 std::vector<std::string> parts = base::SplitString(
29 email_address, "@", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 33 email_address, "@", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
30 if (parts.size() != 2U) { 34 if (parts.size() != 2U) {
31 NOTREACHED() << "expecting exactly one @, but got " 35 NOTREACHED() << "expecting exactly one @, but got "
32 << (parts.empty() ? 0 : parts.size() - 1) 36 << (parts.empty() ? 0 : parts.size() - 1)
33 << " : " << email_address; 37 << " : " << email_address;
34 } else { 38 } else {
35 if (change_googlemail_to_gmail && parts[1] == kGooglemailDomain) 39 if (change_googlemail_to_gmail && parts[1] == kGooglemailDomain)
36 parts[1] = kGmailDomain; 40 parts[1] = kGmailDomain;
37 41
38 if (parts[1] == kGmailDomain) // only strip '.' for gmail accounts. 42 if (parts[1] == kGmailDomain) // only strip '.' for gmail accounts.
39 base::RemoveChars(parts[0], ".", &parts[0]); 43 base::RemoveChars(parts[0], ".", &parts[0]);
40 } 44 }
41 45
42 std::string new_email = base::ToLowerASCII(base::JoinString(parts, "@")); 46 std::string new_email = base::ToLowerASCII(base::JoinString(parts, "@"));
43 VLOG(1) << "Canonicalized " << email_address << " to " << new_email; 47 VLOG(1) << "Canonicalized " << email_address << " to " << new_email;
44 return new_email; 48 return new_email;
45 } 49 }
46 50
51 class GaiaURLRequestUserData : public base::SupportsUserData::Data {
52 public:
53 static base::SupportsUserData::Data* Create() {
54 return new GaiaURLRequestUserData();
55 }
56 };
57
47 } // namespace 58 } // namespace
48 59
49 60
50 ListedAccount::ListedAccount() {} 61 ListedAccount::ListedAccount() {}
51 62
52 ListedAccount::ListedAccount(const ListedAccount& other) = default; 63 ListedAccount::ListedAccount(const ListedAccount& other) = default;
53 64
54 ListedAccount::~ListedAccount() {} 65 ListedAccount::~ListedAccount() {}
55 66
56 bool ListedAccount::operator==(const ListedAccount& other) const { 67 bool ListedAccount::operator==(const ListedAccount& other) const {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 if (list) 184 if (list)
174 list->push_back(listed_account); 185 list->push_back(listed_account);
175 } 186 }
176 } 187 }
177 } 188 }
178 } 189 }
179 190
180 return true; 191 return true;
181 } 192 }
182 193
194 bool RequestOriginatedFromGaia(const net::URLRequest& request) {
195 return request.GetUserData(kURLRequestUserDataKey) != nullptr;
196 }
197
198 void MarkURLFetcherAsGaia(net::URLFetcher* fetcher) {
msarda 2017/01/23 09:29:28 DCHECK(fetcher);
Raj 2017/01/23 18:47:11 Done.
199 fetcher->SetURLRequestUserData(&kURLRequestUserDataKey,
msarda 2017/01/23 09:29:28 Remove the "&"
Raj 2017/01/23 18:47:11 Done.
Raj 2017/01/23 18:47:11 Done.
200 base::Bind(&GaiaURLRequestUserData::Create));
201 }
202
183 } // namespace gaia 203 } // namespace gaia
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698