| Index: mojo/services/network/cookie_store_impl.cc
|
| diff --git a/mojo/services/network/cookie_store_impl.cc b/mojo/services/network/cookie_store_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..03409337f103a55716a7d3abdbad810c4283cf10
|
| --- /dev/null
|
| +++ b/mojo/services/network/cookie_store_impl.cc
|
| @@ -0,0 +1,66 @@
|
| +// Copyright 2014 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 "mojo/services/network/cookie_store_impl.h"
|
| +
|
| +#include "mojo/common/common_type_converters.h"
|
| +#include "mojo/services/network/network_context.h"
|
| +#include "net/cookies/cookie_store.h"
|
| +#include "net/url_request/url_request_context.h"
|
| +
|
| +namespace mojo {
|
| +namespace {
|
| +
|
| +void AdaptGetCookiesCallback(const Callback<void(String)>& callback,
|
| + const std::string& cookies) {
|
| + callback.Run(cookies);
|
| +}
|
| +
|
| +void AdaptSetCookieCallback(const Callback<void(bool)>& callback,
|
| + bool success) {
|
| + callback.Run(success);
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| +CookieStoreImpl::CookieStoreImpl(NetworkContext* context,
|
| + const GURL& origin)
|
| + : context_(context),
|
| + origin_(origin) {
|
| +}
|
| +
|
| +CookieStoreImpl::~CookieStoreImpl() {
|
| +}
|
| +
|
| +void CookieStoreImpl::Get(const String& url,
|
| + const Callback<void(String)>& callback) {
|
| + // TODO(darin): Perform origin restriction.
|
| + net::CookieStore* store = context_->url_request_context()->cookie_store();
|
| + if (!store) {
|
| + callback.Run(String());
|
| + return;
|
| + }
|
| + store->GetCookiesWithOptionsAsync(
|
| + url.To<GURL>(),
|
| + net::CookieOptions(),
|
| + base::Bind(&AdaptGetCookiesCallback, callback));
|
| +}
|
| +
|
| +void CookieStoreImpl::Set(const String& url,
|
| + const String& cookie,
|
| + const Callback<void(bool)>& callback) {
|
| + // TODO(darin): Perform origin restriction.
|
| + net::CookieStore* store = context_->url_request_context()->cookie_store();
|
| + if (!store) {
|
| + callback.Run(false);
|
| + return;
|
| + }
|
| + store->SetCookieWithOptionsAsync(
|
| + url.To<GURL>(),
|
| + cookie,
|
| + net::CookieOptions(),
|
| + base::Bind(&AdaptSetCookieCallback, callback));
|
| +}
|
| +
|
| +} // namespace mojo
|
|
|