blob: 47e14601a81427ed6f5e0e4d39e8ba12ae61ddd9 [file] [log] [blame]
// Copyright 2015 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 <stdint.h>
#include <list>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "base/macros.h"
#include "content/browser/cache_storage/cache_storage.h"
#include "content/browser/cache_storage/cache_storage_index.h"
#include "content/public/browser/browser_thread.h"
#include "mojo/public/cpp/bindings/strong_associated_binding_set.h"
#include "mojo/public/cpp/bindings/strong_binding_set.h"
#include "third_party/blink/public/mojom/fetch/fetch_api_request.mojom.h"
namespace url {
class Origin;
namespace content {
class CacheStorageContextImpl;
// Handles Cache Storage related messages sent to the browser process from
// child processes. One host instance exists per child process. All
// messages are processed on the IO thread.
class CONTENT_EXPORT CacheStorageDispatcherHost
: public base::RefCountedThreadSafe<CacheStorageDispatcherHost,
BrowserThread::DeleteOnIOThread> {
// Runs on UI thread.
void Init(CacheStorageContextImpl* context);
// Binds Mojo request to this instance, must be called on IO thread.
// NOTE: The same CacheStorageDispatcherHost instance may be bound to
// different clients on different origins. Each context is kept on
// BindingSet's context. This guarantees that the browser process uses the
// origin of the client known at the binding time, instead of relying on the
// client to provide its origin at every method call.
void AddBinding(blink::mojom::CacheStorageRequest request,
const url::Origin& origin);
// Friends to allow BrowserThread::DeleteOnIOThread delegation.
friend struct BrowserThread::DeleteOnThread<BrowserThread::IO>;
friend class base::DeleteHelper<CacheStorageDispatcherHost>;
class CacheStorageImpl;
class CacheImpl;
friend class CacheImpl;
void AddCacheBinding(
std::unique_ptr<CacheImpl> cache_impl,
blink::mojom::CacheStorageCacheAssociatedRequest request);
CacheStorageHandle OpenCacheStorage(const url::Origin& origin);
// Called by Init() on IO thread.
void CreateCacheListener(CacheStorageContextImpl* context);
scoped_refptr<CacheStorageContextImpl> context_;
mojo::StrongBindingSet<blink::mojom::CacheStorage> bindings_;
} // namespace content