| Index: content/common/cookie_service_impl.cc
|
| diff --git a/content/common/cookie_service_impl.cc b/content/common/cookie_service_impl.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..15daec16bdeb43edeb2103407513848c16616d21
|
| --- /dev/null
|
| +++ b/content/common/cookie_service_impl.cc
|
| @@ -0,0 +1,123 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "content/common/cookie_service_impl.h"
|
| +
|
| +#include "net/cookies/canonical_cookie.h"
|
| +#include "net/cookies/cookie_constants.h"
|
| +#include "net/cookies/cookie_options.h"
|
| +#include "net/cookies/cookie_store.h"
|
| +#include "url/gurl.h"
|
| +
|
| +// Class to wrap a CookieDeletionFilterPtr and provide a predicate for
|
| +// use by DeleteAllCreatedBetweenWithPredicateAsync.
|
| +class PredicateWrapper {
|
| + public:
|
| + // TODO(rdsmith): Convert vectors into sets for faster processing.
|
| + // TODO(rdsmith): Initialize booleans, similarly.
|
| + PredicateWrapper(content::mojom::CookieDeletionFilterPtr filter)
|
| + : filter_(std::move(filter)) {}
|
| +
|
| + bool Predicate(const net::CanonicalCookie& cookie) {
|
| + // Ignore begin/end times; they're handled by method args.
|
| + if (filter_->domain_blacklist.has_value()) {
|
| + std::vector<std::string>& blacklist_array(
|
| + filter_->domain_blacklist.value());
|
| + if (std::find(std::begin(blacklist_array), std::end(blacklist_array),
|
| + cookie.Domain()) != std::end(blacklist_array)) {
|
| + return true;
|
| + }
|
| + }
|
| +
|
| + if (filter_->domain_whitelist.has_value()) {
|
| + std::vector<std::string>& whitelist_array(
|
| + filter_->domain_whitelist.value());
|
| + if (std::find(std::begin(whitelist_array), std::end(whitelist_array),
|
| + cookie.Domain()) == std::end(whitelist_array)) {
|
| + return true;
|
| + }
|
| + }
|
| +
|
| + if ((filter_->session_control ==
|
| + content::mojom::CookieDeletionSessionControl::SESSION) &&
|
| + !cookie.IsPersistent())
|
| + return true;
|
| +
|
| + if (filter_->session_control ==
|
| + content::mojom::CookieDeletionSessionControl::PERSISTENT &&
|
| + cookie.IsPersistent())
|
| + return true;
|
| +
|
| + return false;
|
| + }
|
| +
|
| + private:
|
| + content::mojom::CookieDeletionFilterPtr filter_;
|
| + DISALLOW_COPY_AND_ASSIGN(PredicateWrapper);
|
| +};
|
| +
|
| +namespace content {
|
| +
|
| +CookieServiceImpl::CookieServiceImpl(net::CookieStore* cookie_store)
|
| + : cookie_store_(cookie_store) {}
|
| +
|
| +CookieServiceImpl::~CookieServiceImpl() {}
|
| +
|
| +void CookieServiceImpl::AddRequest(
|
| + content::mojom::CookieServiceRequest request) {
|
| + bindings_.AddBinding(this, std::move(request));
|
| +}
|
| +
|
| +void CookieServiceImpl::GetAllCookies(GetAllCookiesCallback callback) {
|
| + cookie_store_->GetAllCookiesAsync(std::move(callback));
|
| +}
|
| +
|
| +void CookieServiceImpl::GetCookieList(const GURL& url,
|
| + const net::CookieOptions& cookie_options,
|
| + GetCookieListCallback callback) {
|
| + cookie_store_->GetCookieListWithOptionsAsync(url, cookie_options,
|
| + std::move(callback));
|
| +}
|
| +
|
| +void CookieServiceImpl::SetCanonicalCookie(
|
| + const net::CanonicalCookie& cookie,
|
| + bool secure_source,
|
| + bool modify_http_only,
|
| + SetCanonicalCookieCallback callback) {
|
| + cookie_store_->SetCanonicalCookieAsync(
|
| + base::MakeUnique<net::CanonicalCookie>(cookie), secure_source,
|
| + modify_http_only, std::move(callback));
|
| +}
|
| +
|
| +void CookieServiceImpl::DeleteCookies(
|
| + content::mojom::CookieDeletionFilterPtr filter,
|
| + DeleteCookiesCallback callback) {
|
| + base::Time start_time;
|
| + base::Time end_time;
|
| +
|
| + if (filter->created_after_time.has_value())
|
| + end_time = filter->created_after_time.value();
|
| +
|
| + if (filter->created_before_time.has_value())
|
| + start_time = filter->created_before_time.value();
|
| +
|
| + cookie_store_->DeleteAllCreatedBetweenWithPredicateAsync(
|
| + start_time, end_time,
|
| + base::Bind(&PredicateWrapper::Predicate,
|
| + base::MakeUnique<PredicateWrapper>(std::move(filter))),
|
| + std::move(callback));
|
| +}
|
| +
|
| +void CookieServiceImpl::RequestNotification(
|
| + const GURL& url,
|
| + const std::string& name,
|
| + mojom::CookieChangeNotificationRequest notification_interface,
|
| + RequestNotificationCallback callback) {}
|
| +
|
| +void CookieServiceImpl::CloneInterface(
|
| + mojom::CookieServiceRequest new_interface) {
|
| + AddRequest(std::move(new_interface));
|
| +}
|
| +
|
| +} // namespace content
|
|
|