Commit 3c3e6eed authored by Ben Kelly's avatar Ben Kelly Committed by Commit Bot

CacheStorage: Remove blob thread hopping.

This CL removes various cross-thread affordances necessary to run
cache_storage on a sequence off the IO thread.  Specifically:

1. We bind the BlobDataItemReader implementation directly on the
   cache_storage sequence.
2. We remove cross-thread hopping that were previously required
   when blob Read/ReadSideData were called on the IO thread.  These
   implementations are now generally inlined.
3. We remove class members used to cache values for GetSize().  These
   can now be computed on demand.
4. Many thread assertions were converted to sequence checks.

We still need one cross-thread hop to register the blob at creation
time since the BlobStorageContextImpl is still bound to the IO thread.

Bug: 1021210
Change-Id: I6232d27959bcd1b00e2fb117ce443c53460ecff6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1898173
Commit-Queue: Ben Kelly <wanderview@chromium.org>
Reviewed-by: default avatarenne <enne@chromium.org>
Cr-Commit-Position: refs/heads/master@{#713243}
parent 55873d4a
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include <set> #include <set>
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/ref_counted_delete_on_sequence.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/util/type_safety/pass_key.h" #include "base/util/type_safety/pass_key.h"
...@@ -68,13 +68,7 @@ class CONTENT_EXPORT CacheStorageCacheEntryHandler { ...@@ -68,13 +68,7 @@ class CONTENT_EXPORT CacheStorageCacheEntryHandler {
// The DiskCacheBlobEntry is a ref-counted object containing both // The DiskCacheBlobEntry is a ref-counted object containing both
// a disk_cache Entry and a Handle to the cache in which it lives. This // a disk_cache Entry and a Handle to the cache in which it lives. This
// blob entry can then be used to create an |EntryReaderImpl|. // blob entry can then be used to create an |EntryReaderImpl|.
// class DiskCacheBlobEntry : public base::RefCounted<DiskCacheBlobEntry> {
// |EntryReaderImpl| always lives on the IO thread. The DiskCacheBlobEntry
// is held cross-sequence, but is always created and destroyed on the
// cache_storage scheduler sequence. This ensure both the cache and the
// disk_cache entry live as long as the blob.
class DiskCacheBlobEntry
: public base::RefCountedDeleteOnSequence<DiskCacheBlobEntry> {
public: public:
// Use |CacheStorageCacheEntryHandler::CreateDiskCacheBlobEntry|. // Use |CacheStorageCacheEntryHandler::CreateDiskCacheBlobEntry|.
DiskCacheBlobEntry( DiskCacheBlobEntry(
...@@ -83,70 +77,28 @@ class CONTENT_EXPORT CacheStorageCacheEntryHandler { ...@@ -83,70 +77,28 @@ class CONTENT_EXPORT CacheStorageCacheEntryHandler {
CacheStorageCacheHandle cache_handle, CacheStorageCacheHandle cache_handle,
disk_cache::ScopedEntryPtr disk_cache_entry); disk_cache::ScopedEntryPtr disk_cache_entry);
// Only callable on IO thread.
int Read(scoped_refptr<net::IOBuffer> dst_buffer, int Read(scoped_refptr<net::IOBuffer> dst_buffer,
CacheStorageCache::EntryIndex disk_cache_index, CacheStorageCache::EntryIndex disk_cache_index,
uint64_t offset, uint64_t offset,
int bytes_to_read, int bytes_to_read,
base::OnceCallback<void(int)> callback); base::OnceCallback<void(int)> callback);
// Callable on any thread.
int GetSize(CacheStorageCache::EntryIndex disk_cache_index) const; int GetSize(CacheStorageCache::EntryIndex disk_cache_index) const;
// Callable on any thread.
void PrintTo(::std::ostream* os) const;
// Only callable on the creation sequence.
void Invalidate(); void Invalidate();
// Only callable on the creation sequence.
disk_cache::ScopedEntryPtr& disk_cache_entry(); disk_cache::ScopedEntryPtr& disk_cache_entry();
private: private:
friend class base::DeleteHelper<DiskCacheBlobEntry>; friend class base::RefCounted<DiskCacheBlobEntry>;
friend class base::RefCountedDeleteOnSequence<DiskCacheBlobEntry>;
~DiskCacheBlobEntry(); ~DiskCacheBlobEntry();
// Only callable on the creation sequence.
void ReadOnSequence(scoped_refptr<net::IOBuffer> dst_buffer,
int disk_cache_index,
uint64_t offset,
int bytes_to_read,
base::OnceCallback<void(int)> callback);
// Only callable on the creation sequence.
int ReadOnSequenceInternal(scoped_refptr<net::IOBuffer> dst_buffer,
int disk_cache_index,
uint64_t offset,
int bytes_to_read,
base::OnceCallback<void(int)> callback);
void DidReadOnSequence(base::OnceCallback<void(int)> callback, int result);
// Accessed on any thread
const scoped_refptr<base::SequencedTaskRunner> task_runner_;
// Only accessed on the creation sequence.
base::WeakPtr<CacheStorageCacheEntryHandler> entry_handler_; base::WeakPtr<CacheStorageCacheEntryHandler> entry_handler_;
base::Optional<CacheStorageCacheHandle> cache_handle_; base::Optional<CacheStorageCacheHandle> cache_handle_;
disk_cache::ScopedEntryPtr disk_cache_entry_; disk_cache::ScopedEntryPtr disk_cache_entry_;
// Accessed on any thread.
std::atomic<bool> valid_;
// Cached on the creation sequence so that they can be synchronously
// read on the IO thread.
const std::string key_;
const int index_headers_size_;
const int index_response_body_size_;
const int index_side_data_size_;
// For methods that should only be executed on the creation sequence.
SEQUENCE_CHECKER(sequence_checker_); SEQUENCE_CHECKER(sequence_checker_);
// Do not add a WeakPtrFactory since this class uses a cross-sequence
// delete helper.
DISALLOW_COPY_AND_ASSIGN(DiskCacheBlobEntry); DISALLOW_COPY_AND_ASSIGN(DiskCacheBlobEntry);
}; };
......
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