Explicitly add python-numpy dependency to install-build-deps.
[chromium-blink-merge.git] / mojo / services / html_viewer / webcookiejar_impl.cc
blob0d864801edaabb2b472ebfd1e24fa25b393238b3
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/html_viewer/webcookiejar_impl.h"
7 #include "base/bind.h"
8 #include "third_party/WebKit/public/platform/WebURL.h"
10 namespace mojo {
11 namespace {
13 void CopyBool(bool* output, bool input) {
14 *output = input;
17 void CopyString(String* output, const String& input) {
18 *output = input;
21 } // namespace
23 WebCookieJarImpl::WebCookieJarImpl(CookieStorePtr store)
24 : store_(store.Pass()) {
27 WebCookieJarImpl::~WebCookieJarImpl() {
30 void WebCookieJarImpl::setCookie(const blink::WebURL& url,
31 const blink::WebURL& first_party_for_cookies,
32 const blink::WebString& cookie) {
33 bool success;
34 store_->Set(url.string().utf8(), cookie.utf8(),
35 base::Bind(&CopyBool, &success));
37 // Wait to ensure the cookie was set before advancing. That way any
38 // subsequent URL request will see the changes to the cookie store.
40 // TODO(darin): Consider using associated message pipes for the CookieStore
41 // and URLLoader, so that we could let this method call run asynchronously
42 // without suffering an ordering problem. See crbug/386825.
44 store_.WaitForIncomingMethodCall();
47 blink::WebString WebCookieJarImpl::cookies(
48 const blink::WebURL& url,
49 const blink::WebURL& first_party_for_cookies) {
50 String result;
51 store_->Get(url.string().utf8(), base::Bind(&CopyString, &result));
53 // Wait for the result. Since every outbound request we make to the cookie
54 // store is followed up with WaitForIncomingMethodCall, we can be sure that
55 // the next incoming method call will be the response to our request.
56 store_.WaitForIncomingMethodCall();
57 if (!result)
58 return blink::WebString();
60 return blink::WebString::fromUTF8(result);
63 blink::WebString WebCookieJarImpl::cookieRequestHeaderFieldValue(
64 const blink::WebURL& url,
65 const blink::WebURL& first_party_for_cookies) {
66 return cookies(url, first_party_for_cookies);
69 } // namespace mojo