OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "mojo/services/network/cookie_store_impl.h" | |
6 | |
7 #include <utility> | |
8 | |
9 #include "mojo/common/url_type_converters.h" | |
10 #include "mojo/services/network/network_context.h" | |
11 #include "net/cookies/cookie_store.h" | |
12 #include "net/url_request/url_request_context.h" | |
13 | |
14 namespace mojo { | |
15 namespace { | |
16 | |
17 void AdaptGetCookiesCallback(const Callback<void(String)>& callback, | |
18 const std::string& cookies) { | |
19 callback.Run(cookies); | |
20 } | |
21 | |
22 void AdaptSetCookieCallback(const Callback<void(bool)>& callback, | |
23 bool success) { | |
24 callback.Run(success); | |
25 } | |
26 | |
27 } // namespace | |
28 | |
29 CookieStoreImpl::CookieStoreImpl(NetworkContext* context, | |
30 const GURL& origin, | |
31 scoped_ptr<mojo::MessageLoopRef> app_refcount, | |
32 InterfaceRequest<CookieStore> request) | |
33 : context_(context), | |
34 origin_(origin), | |
35 app_refcount_(std::move(app_refcount)), | |
36 binding_(this, std::move(request)) {} | |
37 | |
38 CookieStoreImpl::~CookieStoreImpl() { | |
39 } | |
40 | |
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; | |
48 } | |
49 store->GetCookiesWithOptionsAsync( | |
50 url.To<GURL>(), | |
51 net::CookieOptions(), | |
52 base::Bind(&AdaptGetCookiesCallback, callback)); | |
53 } | |
54 | |
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; | |
63 } | |
64 store->SetCookieWithOptionsAsync( | |
65 url.To<GURL>(), | |
66 cookie, | |
67 net::CookieOptions(), | |
68 base::Bind(&AdaptSetCookieCallback, callback)); | |
69 } | |
70 | |
71 } // namespace mojo | |
OLD | NEW |