Chromium Code Reviews| Index: content/browser/android/cookies_retriever_impl.cc |
| diff --git a/content/browser/android/cookies_retriever_impl.cc b/content/browser/android/cookies_retriever_impl.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..62ab9b060a586a31b5831aab01e644d36692097e |
| --- /dev/null |
| +++ b/content/browser/android/cookies_retriever_impl.cc |
| @@ -0,0 +1,67 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "content/browser/android/cookies_retriever_impl.h" |
| + |
| +#include "base/bind.h" |
| +#include "content/public/browser/browser_thread.h" |
| +#include "googleurl/src/gurl.h" |
| +#include "net/cookies/cookie_store.h" |
| +#include "net/url_request/url_request_context.h" |
| +#include "net/url_request/url_request_context_getter.h" |
| + |
| +using content::BrowserThread; |
| + |
| +namespace content { |
| + |
| +CookiesRetrieverImpl::CookiesRetrieverImpl( |
| + net::URLRequestContextGetter* context_getter) |
| + : context_getter_(context_getter) { |
| +} |
| + |
| +CookiesRetrieverImpl::~CookiesRetrieverImpl() { |
| +} |
| + |
| +void CookiesRetrieverImpl::GetCookiesAsync(std::string url, |
| + const media::CookiesRetriever::GetCookieCB& callback) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + url_ = url; |
|
scherkus (not reviewing)
2012/09/07 13:17:35
what happens if I call this multiple times with di
qinmin
2012/09/07 22:48:27
passed url to the RequestCookies closure.
On 2012
|
| + get_cookies_cb_ = callback; |
| + BrowserThread::PostTask( |
| + BrowserThread::IO, |
| + FROM_HERE, |
| + base::Bind(&CookiesRetrieverImpl::RequestCookies, |
| + this)); |
|
scherkus (not reviewing)
2012/09/07 13:17:35
instead of storing url_ and get_cookies_cb_ in the
qinmin
2012/09/07 22:48:27
Done.
|
| +} |
| + |
| +void CookiesRetrieverImpl::RequestCookies() { |
|
scherkus (not reviewing)
2012/09/07 13:17:35
this function should be:
RequestCookies(const std:
qinmin
2012/09/07 22:48:27
Done. Use partial binding to pass GetCookiesCB
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + net::CookieOptions options; |
| + options.set_include_httponly(); |
| + net::CookieStore* cookie_store = |
| + context_getter_->GetURLRequestContext()->cookie_store(); |
| + if (cookie_store) { |
| + cookie_store->GetCookiesWithOptionsAsync( |
| + GURL(url_), options, base::Bind(&CookiesRetrieverImpl::ReturnCookies, |
|
scherkus (not reviewing)
2012/09/07 13:17:35
you're accessing url_ on different threads
qinmin
2012/09/07 22:48:27
Done. passing url to this function.
|
| + this)); |
| + } else { |
| + std::string cookies; |
| + ReturnCookies(cookies); |
| + } |
| +} |
| + |
| +void CookiesRetrieverImpl::ReturnCookies(const std::string& cookies) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| + BrowserThread::PostTask( |
| + BrowserThread::UI, |
| + FROM_HERE, |
| + base::Bind(&CookiesRetrieverImpl::GetCookiesCallback, this, cookies)); |
| +} |
| + |
| +void CookiesRetrieverImpl::GetCookiesCallback(const std::string& cookies) { |
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| + get_cookies_cb_.Run(cookies); |
| +} |
| + |
| +} // namespace content |