Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(961)

Side by Side Diff: mojo/services/network/cookie_store_impl.cc

Issue 409883007: Mojo: add support for cookies to HTMLViewer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add missing files Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 "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"
11
12 namespace mojo {
13 namespace {
14
15 void AdaptGetCookiesCallback(const Callback<void(String)>& callback,
16 const std::string& cookies) {
17 callback.Run(cookies);
18 }
19
20 void AdaptSetCookieCallback(const Callback<void(bool)>& callback,
21 bool success) {
22 callback.Run(success);
23 }
24
25 } // namespace
26
27 CookieStoreImpl::CookieStoreImpl(NetworkContext* context,
28 const GURL& origin)
29 : context_(context),
30 origin_(origin) {
31 }
32
33 CookieStoreImpl::~CookieStoreImpl() {
34 }
35
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;
43 }
44 store->GetCookiesWithOptionsAsync(
45 url.To<GURL>(),
46 net::CookieOptions(),
47 base::Bind(&AdaptGetCookiesCallback, callback));
48 }
49
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;
58 }
59 store->SetCookieWithOptionsAsync(
60 url.To<GURL>(),
61 cookie,
62 net::CookieOptions(),
63 base::Bind(&AdaptSetCookieCallback, callback));
64 }
65
66 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698