Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "content/browser/android/cookie_getter_impl.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "content/public/browser/browser_thread.h" | |
| 9 #include "googleurl/src/gurl.h" | |
| 10 #include "net/cookies/cookie_store.h" | |
| 11 #include "net/url_request/url_request_context.h" | |
| 12 #include "net/url_request/url_request_context_getter.h" | |
| 13 | |
| 14 using content::BrowserThread; | |
| 15 | |
| 16 namespace content { | |
| 17 | |
| 18 CookieGetterImpl::CookieGetterImpl( | |
| 19 net::URLRequestContextGetter* context_getter) | |
| 20 : context_getter_(context_getter), | |
| 21 ALLOW_THIS_IN_INITIALIZER_LIST(weak_this_(this)) { | |
| 22 } | |
| 23 | |
| 24 CookieGetterImpl::~CookieGetterImpl() {} | |
| 25 | |
| 26 void CookieGetterImpl::GetCookies( | |
| 27 const std::string& url, const GetCookieCB& callback) { | |
| 28 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 29 BrowserThread::PostTask( | |
| 30 BrowserThread::IO, | |
| 31 FROM_HERE, | |
| 32 base::Bind(&CookieGetterImpl::RequestCookies, | |
| 33 weak_this_.GetWeakPtr(), url, callback)); | |
| 34 } | |
| 35 | |
| 36 void CookieGetterImpl::RequestCookies( | |
| 37 const std::string& url, const GetCookieCB& callback) { | |
| 38 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 39 net::CookieOptions options; | |
| 40 options.set_include_httponly(); | |
| 41 net::CookieStore* cookie_store = | |
| 42 context_getter_->GetURLRequestContext()->cookie_store(); | |
|
nilesh
2012/09/11 05:48:48
I think you are supposed to ask the request contex
qinmin
2012/09/12 23:12:52
This is getting a little more complicated. Added a
| |
| 43 base::Callback<void(const std::string&)> cb = base::Bind( | |
| 44 &CookieGetterImpl::ReturnCookies, weak_this_.GetWeakPtr(), callback); | |
| 45 if (cookie_store) { | |
| 46 cookie_store->GetCookiesWithOptionsAsync( | |
| 47 GURL(url), options, cb); | |
| 48 } else { | |
| 49 std::string cookies; | |
| 50 ReturnCookies(callback, cookies); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 void CookieGetterImpl::ReturnCookies( | |
| 55 const GetCookieCB& callback, const std::string& cookies) { | |
| 56 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 57 BrowserThread::PostTask( | |
| 58 BrowserThread::UI, | |
| 59 FROM_HERE, | |
| 60 base::Bind(&CookieGetterImpl::GetCookiesCallback, | |
| 61 weak_this_.GetWeakPtr(), cookies, callback)); | |
| 62 } | |
| 63 | |
| 64 void CookieGetterImpl::GetCookiesCallback( | |
| 65 const std::string& cookies, const GetCookieCB& callback) { | |
| 66 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 67 callback.Run(cookies); | |
| 68 } | |
| 69 | |
| 70 } // namespace content | |
| OLD | NEW |