| Index: content/browser/android/cookie_getter_impl.cc
|
| diff --git a/content/browser/android/cookie_getter_impl.cc b/content/browser/android/cookie_getter_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8f253f46e161e4e5d3db6b84a7b587c6f51c8797
|
| --- /dev/null
|
| +++ b/content/browser/android/cookie_getter_impl.cc
|
| @@ -0,0 +1,70 @@
|
| +// 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/cookie_getter_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 {
|
| +
|
| +CookieGetterImpl::CookieGetterImpl(
|
| + net::URLRequestContextGetter* context_getter)
|
| + : context_getter_(context_getter) {
|
| +}
|
| +
|
| +CookieGetterImpl::~CookieGetterImpl() {
|
| +}
|
| +
|
| +void CookieGetterImpl::GetCookies(
|
| + const std::string& url, const GetCookieCB& callback) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + BrowserThread::PostTask(
|
| + BrowserThread::IO,
|
| + FROM_HERE,
|
| + base::Bind(&CookieGetterImpl::RequestCookies,
|
| + this, url, callback));
|
| +}
|
| +
|
| +void CookieGetterImpl::RequestCookies(
|
| + const std::string& url, const GetCookieCB& callback) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + net::CookieOptions options;
|
| + options.set_include_httponly();
|
| + net::CookieStore* cookie_store =
|
| + context_getter_->GetURLRequestContext()->cookie_store();
|
| + base::Callback<void(const std::string&)> cb =
|
| + base::Bind(&CookieGetterImpl::ReturnCookies, this, callback);
|
| + if (cookie_store) {
|
| + cookie_store->GetCookiesWithOptionsAsync(
|
| + GURL(url), options, cb);
|
| + } else {
|
| + std::string cookies;
|
| + ReturnCookies(callback, cookies);
|
| + }
|
| +}
|
| +
|
| +void CookieGetterImpl::ReturnCookies(
|
| + const GetCookieCB& callback, const std::string& cookies) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
|
| + BrowserThread::PostTask(
|
| + BrowserThread::UI,
|
| + FROM_HERE,
|
| + base::Bind(
|
| + &CookieGetterImpl::GetCookiesCallback, this, cookies, callback));
|
| +}
|
| +
|
| +void CookieGetterImpl::GetCookiesCallback(
|
| + const std::string& cookies, const GetCookieCB& callback) {
|
| + DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
|
| + callback.Run(cookies);
|
| +}
|
| +
|
| +} // namespace content
|
|
|