OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "components/autofill/content/browser/wallet/wallet_signin_helper.h" | 5 #include "components/autofill/content/browser/wallet/wallet_signin_helper.h" |
6 | 6 |
7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
8 #include "base/json/json_reader.h" | 8 #include "base/json/json_reader.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 namespace { | 31 namespace { |
32 | 32 |
33 const char kWalletCookieName[] = "gdtoken"; | 33 const char kWalletCookieName[] = "gdtoken"; |
34 | 34 |
35 // Callback for retrieving Google Wallet cookies. |callback| is passed the | 35 // Callback for retrieving Google Wallet cookies. |callback| is passed the |
36 // retrieved cookies and posted back to the UI thread. |cookies| is any Google | 36 // retrieved cookies and posted back to the UI thread. |cookies| is any Google |
37 // Wallet cookies. | 37 // Wallet cookies. |
38 void GetGoogleCookiesCallback( | 38 void GetGoogleCookiesCallback( |
39 const base::Callback<void(const std::string&)>& callback, | 39 const base::Callback<void(const std::string&)>& callback, |
40 const net::CookieList& cookies) { | 40 const net::CookieList& cookies) { |
41 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 41 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
42 | 42 |
43 // Cookies for parent domains will also be returned; we only want cookies with | 43 // Cookies for parent domains will also be returned; we only want cookies with |
44 // exact host matches. TODO(estade): really? | 44 // exact host matches. TODO(estade): really? |
45 std::string host = wallet::GetPassiveAuthUrl(0).host(); | 45 std::string host = wallet::GetPassiveAuthUrl(0).host(); |
46 std::string wallet_cookie; | 46 std::string wallet_cookie; |
47 for (size_t i = 0; i < cookies.size(); ++i) { | 47 for (size_t i = 0; i < cookies.size(); ++i) { |
48 if (LowerCaseEqualsASCII(cookies[i].Name(), kWalletCookieName) && | 48 if (LowerCaseEqualsASCII(cookies[i].Name(), kWalletCookieName) && |
49 LowerCaseEqualsASCII(cookies[i].Domain(), host.c_str())) { | 49 LowerCaseEqualsASCII(cookies[i].Domain(), host.c_str())) { |
50 wallet_cookie = cookies[i].Value(); | 50 wallet_cookie = cookies[i].Value(); |
51 break; | 51 break; |
52 } | 52 } |
53 } | 53 } |
54 content::BrowserThread::PostTask(content::BrowserThread::UI, | 54 content::BrowserThread::PostTask(content::BrowserThread::UI, |
55 FROM_HERE, | 55 FROM_HERE, |
56 base::Bind(callback, wallet_cookie)); | 56 base::Bind(callback, wallet_cookie)); |
57 } | 57 } |
58 | 58 |
59 // Gets Google Wallet cookies. Must be called on the IO thread. | 59 // Gets Google Wallet cookies. Must be called on the IO thread. |
60 // |request_context_getter| is a getter for the current request context. | 60 // |request_context_getter| is a getter for the current request context. |
61 // |callback| is called when retrieving cookies is completed. | 61 // |callback| is called when retrieving cookies is completed. |
62 void GetGoogleCookies( | 62 void GetGoogleCookies( |
63 scoped_refptr<net::URLRequestContextGetter> request_context_getter, | 63 scoped_refptr<net::URLRequestContextGetter> request_context_getter, |
64 const base::Callback<void(const std::string&)>& callback) { | 64 const base::Callback<void(const std::string&)>& callback) { |
65 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 65 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); |
66 | 66 |
67 net::URLRequestContext* url_request_context = | 67 net::URLRequestContext* url_request_context = |
68 request_context_getter->GetURLRequestContext(); | 68 request_context_getter->GetURLRequestContext(); |
69 net::CookieStore* cookie_store = url_request_context ? | 69 net::CookieStore* cookie_store = url_request_context ? |
70 url_request_context->cookie_store() : NULL; | 70 url_request_context->cookie_store() : NULL; |
71 net::CookieMonster* cookie_monster = cookie_store ? | 71 net::CookieMonster* cookie_monster = cookie_store ? |
72 cookie_store->GetCookieMonster() : NULL; | 72 cookie_store->GetCookieMonster() : NULL; |
73 if (!cookie_monster) { | 73 if (!cookie_monster) { |
74 content::BrowserThread::PostTask(content::BrowserThread::UI, | 74 content::BrowserThread::PostTask(content::BrowserThread::UI, |
75 FROM_HERE, | 75 FROM_HERE, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 OnServiceError( | 159 OnServiceError( |
160 GoogleServiceAuthError(GoogleServiceAuthError::USER_NOT_SIGNED_UP)); | 160 GoogleServiceAuthError(GoogleServiceAuthError::USER_NOT_SIGNED_UP)); |
161 return; | 161 return; |
162 } | 162 } |
163 | 163 |
164 delegate_->OnPassiveSigninSuccess(); | 164 delegate_->OnPassiveSigninSuccess(); |
165 } | 165 } |
166 | 166 |
167 void WalletSigninHelper::ReturnWalletCookieValue( | 167 void WalletSigninHelper::ReturnWalletCookieValue( |
168 const std::string& cookie_value) { | 168 const std::string& cookie_value) { |
169 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 169 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
170 | 170 |
171 delegate_->OnDidFetchWalletCookieValue(cookie_value); | 171 delegate_->OnDidFetchWalletCookieValue(cookie_value); |
172 } | 172 } |
173 | 173 |
174 } // namespace wallet | 174 } // namespace wallet |
175 } // namespace autofill | 175 } // namespace autofill |
OLD | NEW |