Commit 840a5969 authored by Victor Costan's avatar Victor Costan Committed by Chromium LUCI CQ

Cookie Store: Add thread safety annotations to CookieStoreContext.

Change-Id: I9e62fcf1a06a8c1513c8c64662bfb4e7ac6f9419
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2592927
Auto-Submit: Victor Costan <pwnall@chromium.org>
Commit-Queue: Ayu Ishii <ayui@chromium.org>
Reviewed-by: default avatarAyu Ishii <ayui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837256}
parent 44b344d9
......@@ -5,6 +5,7 @@
#include "content/browser/cookie_store/cookie_store_context.h"
#include "base/bind.h"
#include "base/sequence_checker.h"
#include "base/task/post_task.h"
#include "content/browser/service_worker/service_worker_context_wrapper.h"
#include "content/browser/storage_partition_impl.h"
......@@ -19,13 +20,15 @@ namespace content {
CookieStoreContext::CookieStoreContext()
: base::RefCountedDeleteOnSequence<CookieStoreContext>(
base::CreateSingleThreadTaskRunner(
{ServiceWorkerContext::GetCoreThreadId()})) {}
{ServiceWorkerContext::GetCoreThreadId()})) {
DETACH_FROM_SEQUENCE(core_sequence_checker_);
}
CookieStoreContext::~CookieStoreContext() {
// The destructor must be called on the service worker core thread, because it
// runs cookie_store_manager_'s destructor, and the latter is only accessed on
// the core thread.
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
// runs `cookie_store_manager_`'s destructor, and the latter is only accessed
// on the service worker core thread.
DCHECK_CALLED_ON_VALID_SEQUENCE(core_sequence_checker_);
}
void CookieStoreContext::Initialize(
......@@ -126,7 +129,7 @@ void CookieStoreContext::CreateServiceForTesting(
void CookieStoreContext::InitializeOnCoreThread(
scoped_refptr<ServiceWorkerContextWrapper> service_worker_context,
base::OnceCallback<void(bool)> success_callback) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
DCHECK_CALLED_ON_VALID_SEQUENCE(core_sequence_checker_);
DCHECK(!cookie_store_manager_) << __func__ << " called more than once";
cookie_store_manager_ =
......@@ -137,7 +140,7 @@ void CookieStoreContext::InitializeOnCoreThread(
void CookieStoreContext::ListenToCookieChangesOnCoreThread(
mojo::PendingRemote<::network::mojom::CookieManager> cookie_manager_remote,
base::OnceCallback<void(bool)> success_callback) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
DCHECK_CALLED_ON_VALID_SEQUENCE(core_sequence_checker_);
DCHECK(cookie_store_manager_);
cookie_store_manager_->ListenToCookieChanges(std::move(cookie_manager_remote),
......@@ -147,7 +150,7 @@ void CookieStoreContext::ListenToCookieChangesOnCoreThread(
void CookieStoreContext::CreateServiceOnCoreThread(
const url::Origin& origin,
mojo::PendingReceiver<blink::mojom::CookieStore> receiver) {
DCHECK_CURRENTLY_ON(ServiceWorkerContext::GetCoreThreadId());
DCHECK_CALLED_ON_VALID_SEQUENCE(core_sequence_checker_);
DCHECK(cookie_store_manager_);
cookie_store_manager_->CreateService(std::move(receiver), origin);
......
......@@ -9,6 +9,7 @@
#include "base/macros.h"
#include "base/memory/ref_counted_delete_on_sequence.h"
#include "base/memory/scoped_refptr.h"
#include "base/thread_annotations.h"
#include "content/browser/cookie_store/cookie_store_manager.h"
#include "content/common/content_export.h"
#include "services/network/public/mojom/network_service.mojom.h"
......@@ -106,15 +107,20 @@ class CONTENT_EXPORT CookieStoreContext
mojo::PendingReceiver<blink::mojom::CookieStore> receiver);
// Only accessed on the service worker core thread.
std::unique_ptr<CookieStoreManager> cookie_store_manager_;
std::unique_ptr<CookieStoreManager> cookie_store_manager_
GUARDED_BY_CONTEXT(core_sequence_checker_);
#if DCHECK_IS_ON()
// Only accesssed on the UI thread.
bool initialize_called_ = false;
// Only accessed on the UI thread.
bool initialize_called_ GUARDED_BY_CONTEXT(sequence_checker_) = false;
#endif // DCHECK_IS_ON()
// Tracks accesses on the UI thread.
SEQUENCE_CHECKER(sequence_checker_);
// Tracks accesses on the service worker core thread.
SEQUENCE_CHECKER(core_sequence_checker_);
DISALLOW_COPY_AND_ASSIGN(CookieStoreContext);
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment