Battery Status API: add UMA logging for Linux.
[chromium-blink-merge.git] / mojo / services / network / cookie_store_impl.cc
blob03409337f103a55716a7d3abdbad810c4283cf10
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/common_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"
12 namespace mojo {
13 namespace {
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,
21 bool success) {
22 callback.Run(success);
25 } // namespace
27 CookieStoreImpl::CookieStoreImpl(NetworkContext* context,
28 const GURL& origin)
29 : context_(context),
30 origin_(origin) {
33 CookieStoreImpl::~CookieStoreImpl() {
36 void CookieStoreImpl::Get(const String& url,
37 const Callback<void(String)>& callback) {
38 // TODO(darin): Perform origin restriction.
39 net::CookieStore* store = context_->url_request_context()->cookie_store();
40 if (!store) {
41 callback.Run(String());
42 return;
44 store->GetCookiesWithOptionsAsync(
45 url.To<GURL>(),
46 net::CookieOptions(),
47 base::Bind(&AdaptGetCookiesCallback, callback));
50 void CookieStoreImpl::Set(const String& url,
51 const String& cookie,
52 const Callback<void(bool)>& callback) {
53 // TODO(darin): Perform origin restriction.
54 net::CookieStore* store = context_->url_request_context()->cookie_store();
55 if (!store) {
56 callback.Run(false);
57 return;
59 store->SetCookieWithOptionsAsync(
60 url.To<GURL>(),
61 cookie,
62 net::CookieOptions(),
63 base::Bind(&AdaptSetCookieCallback, callback));
66 } // namespace mojo