1 // Copyright 2014 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.
5 #include "mojo/services/network/cookie_store_impl.h"
7 #include "mojo/common/url_type_converters.h"
8 #include "mojo/services/network/network_context.h"
9 #include "net/cookies/cookie_store.h"
10 #include "net/url_request/url_request_context.h"
15 void AdaptGetCookiesCallback(const Callback
<void(String
)>& callback
,
16 const std::string
& cookies
) {
17 callback
.Run(cookies
);
20 void AdaptSetCookieCallback(const Callback
<void(bool)>& callback
,
22 callback
.Run(success
);
27 CookieStoreImpl::CookieStoreImpl(
28 NetworkContext
* context
,
30 scoped_ptr
<mojo::AppRefCount
> app_refcount
,
31 InterfaceRequest
<CookieStore
> request
)
34 app_refcount_(app_refcount
.Pass()),
35 binding_(this, request
.Pass()) {
38 CookieStoreImpl::~CookieStoreImpl() {
41 void CookieStoreImpl::Get(const String
& url
,
42 const Callback
<void(String
)>& callback
) {
43 // TODO(darin): Perform origin restriction.
44 net::CookieStore
* store
= context_
->url_request_context()->cookie_store();
46 callback
.Run(String());
49 store
->GetCookiesWithOptionsAsync(
52 base::Bind(&AdaptGetCookiesCallback
, callback
));
55 void CookieStoreImpl::Set(const String
& url
,
57 const Callback
<void(bool)>& callback
) {
58 // TODO(darin): Perform origin restriction.
59 net::CookieStore
* store
= context_
->url_request_context()->cookie_store();
64 store
->SetCookieWithOptionsAsync(
68 base::Bind(&AdaptSetCookieCallback
, callback
));