Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / mojo / services / network / cookie_store_impl.cc
blobb921ddcb5f371796e54b592b98711c869d7db38d
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"
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(
28 NetworkContext* context,
29 const GURL& origin,
30 scoped_ptr<mojo::AppRefCount> app_refcount,
31 InterfaceRequest<CookieStore> request)
32 : context_(context),
33 origin_(origin),
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();
45 if (!store) {
46 callback.Run(String());
47 return;
49 store->GetCookiesWithOptionsAsync(
50 url.To<GURL>(),
51 net::CookieOptions(),
52 base::Bind(&AdaptGetCookiesCallback, callback));
55 void CookieStoreImpl::Set(const String& url,
56 const String& cookie,
57 const Callback<void(bool)>& callback) {
58 // TODO(darin): Perform origin restriction.
59 net::CookieStore* store = context_->url_request_context()->cookie_store();
60 if (!store) {
61 callback.Run(false);
62 return;
64 store->SetCookieWithOptionsAsync(
65 url.To<GURL>(),
66 cookie,
67 net::CookieOptions(),
68 base::Bind(&AdaptSetCookieCallback, callback));
71 } // namespace mojo