Roll src/third_party/skia 0a24297:ceadfef
[chromium-blink-merge.git] / components / html_viewer / web_cookie_jar_impl.cc
blobc59bfd2a75473426457d6c543f094d0a57342f38
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 "components/html_viewer/web_cookie_jar_impl.h"
7 #include "base/bind.h"
8 #include "third_party/WebKit/public/platform/WebURL.h"
10 using mojo::String;
12 namespace html_viewer {
13 namespace {
15 void CopyBool(bool* output, bool input) {
16 *output = input;
19 void CopyString(String* output, const String& input) {
20 *output = input;
23 } // namespace
25 WebCookieJarImpl::WebCookieJarImpl(mojo::CookieStorePtr store)
26 : store_(store.Pass()) {
29 WebCookieJarImpl::~WebCookieJarImpl() {
32 void WebCookieJarImpl::setCookie(const blink::WebURL& url,
33 const blink::WebURL& first_party_for_cookies,
34 const blink::WebString& cookie) {
35 bool success;
36 store_->Set(url.string().utf8(), cookie.utf8(),
37 base::Bind(&CopyBool, &success));
39 // Wait to ensure the cookie was set before advancing. That way any
40 // subsequent URL request will see the changes to the cookie store.
42 // TODO(darin): Consider using associated message pipes for the CookieStore
43 // and URLLoader, so that we could let this method call run asynchronously
44 // without suffering an ordering problem. See crbug/386825.
46 store_.WaitForIncomingResponse();
49 blink::WebString WebCookieJarImpl::cookies(
50 const blink::WebURL& url,
51 const blink::WebURL& first_party_for_cookies) {
52 String result;
53 store_->Get(url.string().utf8(), base::Bind(&CopyString, &result));
55 // Wait for the result. Since every outbound request we make to the cookie
56 // store is followed up with WaitForIncomingResponse, we can be sure that
57 // the next incoming method call will be the response to our request.
58 store_.WaitForIncomingResponse();
59 if (!result)
60 return blink::WebString();
62 return blink::WebString::fromUTF8(result);
65 blink::WebString WebCookieJarImpl::cookieRequestHeaderFieldValue(
66 const blink::WebURL& url,
67 const blink::WebURL& first_party_for_cookies) {
68 return cookies(url, first_party_for_cookies);
71 } // namespace html_viewer