Commit a5829b9c authored by Bence Béky's avatar Bence Béky Committed by Commit Bot

Use CompletionOnceCallback in //content/browser/appcache.

Use CompletionOnceCallback instead of CompletionCallback, and
CancelableCompletionOnceCallback instead of CancelableCompletionCallback
in //content/browser/appcache.

Bug: 807724

This exact CL has been reviewed and approved at
https://crrev.com/c/1163933.  However, due to a bug in Gerrit, I
inadvertently submitted that CL skipping the CQ.  See
https://crbug.com/872722.  That CL was reverted, and now I am relanding
it properly in this CL, through CQ this time.  Original reviewer is
TBR'd.

TBR=kinuko@chromium.org

Change-Id: Ie1d8e275e754cc51457aca6537ad08b228cfaaac
Reviewed-on: https://chromium-review.googlesource.com/1169307Reviewed-by: default avatarBence Béky <bnc@chromium.org>
Commit-Queue: Bence Béky <bnc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581894}
parent b3e28328
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "content/browser/appcache/appcache_response.h" #include "content/browser/appcache/appcache_response.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "net/base/completion_once_callback.h"
#include "net/disk_cache/disk_cache.h" #include "net/disk_cache/disk_cache.h"
namespace content { namespace content {
...@@ -32,23 +33,23 @@ class CONTENT_EXPORT AppCacheDiskCache ...@@ -32,23 +33,23 @@ class CONTENT_EXPORT AppCacheDiskCache
int disk_cache_size, int disk_cache_size,
bool force, bool force,
base::OnceClosure post_cleanup_callback, base::OnceClosure post_cleanup_callback,
const net::CompletionCallback& callback); net::CompletionOnceCallback callback);
// Initializes the object to use memory only storage. // Initializes the object to use memory only storage.
// This is used for Chrome's incognito browsing. // This is used for Chrome's incognito browsing.
int InitWithMemBackend(int disk_cache_size, int InitWithMemBackend(int disk_cache_size,
const net::CompletionCallback& callback); net::CompletionOnceCallback callback);
void Disable(); void Disable();
bool is_disabled() const { return is_disabled_; } bool is_disabled() const { return is_disabled_; }
int CreateEntry(int64_t key, int CreateEntry(int64_t key,
Entry** entry, Entry** entry,
const net::CompletionCallback& callback) override; net::CompletionOnceCallback callback) override;
int OpenEntry(int64_t key, int OpenEntry(int64_t key,
Entry** entry, Entry** entry,
const net::CompletionCallback& callback) override; net::CompletionOnceCallback callback) override;
int DoomEntry(int64_t key, const net::CompletionCallback& callback) override; int DoomEntry(int64_t key, net::CompletionOnceCallback callback) override;
void set_is_waiting_to_initialize(bool is_waiting_to_initialize) { void set_is_waiting_to_initialize(bool is_waiting_to_initialize) {
is_waiting_to_initialize_ = is_waiting_to_initialize; is_waiting_to_initialize_ = is_waiting_to_initialize;
...@@ -73,21 +74,19 @@ class CONTENT_EXPORT AppCacheDiskCache ...@@ -73,21 +74,19 @@ class CONTENT_EXPORT AppCacheDiskCache
DOOM DOOM
}; };
struct PendingCall { struct PendingCall {
PendingCallType call_type;
int64_t key;
Entry** entry;
net::CompletionCallback callback;
PendingCall(); PendingCall();
PendingCall(PendingCallType call_type, PendingCall(PendingCallType call_type,
int64_t key, int64_t key,
Entry** entry, Entry** entry,
const net::CompletionCallback& callback); net::CompletionOnceCallback callback);
PendingCall(PendingCall&& other);
PendingCall(const PendingCall& other);
~PendingCall(); ~PendingCall();
PendingCallType call_type;
int64_t key;
Entry** entry;
net::CompletionOnceCallback callback;
}; };
using PendingCalls = std::vector<PendingCall>; using PendingCalls = std::vector<PendingCall>;
...@@ -104,7 +103,7 @@ class CONTENT_EXPORT AppCacheDiskCache ...@@ -104,7 +103,7 @@ class CONTENT_EXPORT AppCacheDiskCache
int cache_size, int cache_size,
bool force, bool force,
base::OnceClosure post_cleanup_callback, base::OnceClosure post_cleanup_callback,
const net::CompletionCallback& callback); net::CompletionOnceCallback callback);
void OnCreateBackendComplete(int rv); void OnCreateBackendComplete(int rv);
void AddOpenEntry(EntryImpl* entry) { open_entries_.insert(entry); } void AddOpenEntry(EntryImpl* entry) { open_entries_.insert(entry); }
void RemoveOpenEntry(EntryImpl* entry) { open_entries_.erase(entry); } void RemoveOpenEntry(EntryImpl* entry) { open_entries_.erase(entry); }
...@@ -112,7 +111,7 @@ class CONTENT_EXPORT AppCacheDiskCache ...@@ -112,7 +111,7 @@ class CONTENT_EXPORT AppCacheDiskCache
bool use_simple_cache_; bool use_simple_cache_;
bool is_disabled_; bool is_disabled_;
bool is_waiting_to_initialize_; bool is_waiting_to_initialize_;
net::CompletionCallback init_callback_; net::CompletionOnceCallback init_callback_;
scoped_refptr<CreateBackendCallbackShim> create_backend_callback_; scoped_refptr<CreateBackendCallbackShim> create_backend_callback_;
PendingCalls pending_calls_; PendingCalls pending_calls_;
OpenEntries open_entries_; OpenEntries open_entries_;
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
#include "base/test/scoped_task_environment.h" #include "base/test/scoped_task_environment.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "net/base/completion_repeating_callback.h"
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h" #include "net/base/test_completion_callback.h"
...@@ -24,9 +25,8 @@ class AppCacheDiskCacheTest : public testing::Test { ...@@ -24,9 +25,8 @@ class AppCacheDiskCacheTest : public testing::Test {
void SetUp() override { void SetUp() override {
ASSERT_TRUE(directory_.CreateUniqueTempDir()); ASSERT_TRUE(directory_.CreateUniqueTempDir());
completion_callback_ = base::Bind( completion_callback_ = base::BindRepeating(
&AppCacheDiskCacheTest::OnComplete, &AppCacheDiskCacheTest::OnComplete, base::Unretained(this));
base::Unretained(this));
} }
void TearDown() override { scoped_task_environment_.RunUntilIdle(); } void TearDown() override { scoped_task_environment_.RunUntilIdle(); }
...@@ -42,7 +42,7 @@ class AppCacheDiskCacheTest : public testing::Test { ...@@ -42,7 +42,7 @@ class AppCacheDiskCacheTest : public testing::Test {
base::test::ScopedTaskEnvironment scoped_task_environment_; base::test::ScopedTaskEnvironment scoped_task_environment_;
base::ScopedTempDir directory_; base::ScopedTempDir directory_;
net::CompletionCallback completion_callback_; net::CompletionRepeatingCallback completion_callback_;
std::vector<int> completion_results_; std::vector<int> completion_results_;
static const int k10MBytes = 10 * 1024 * 1024; static const int k10MBytes = 10 * 1024 * 1024;
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <algorithm> #include <algorithm>
#include <map> #include <map>
#include <set> #include <set>
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
...@@ -207,15 +208,16 @@ const AppCacheStorage::UsageMap* AppCacheQuotaClient::GetUsageMap() { ...@@ -207,15 +208,16 @@ const AppCacheStorage::UsageMap* AppCacheQuotaClient::GetUsageMap() {
return service_->storage()->usage_map(); return service_->storage()->usage_map();
} }
net::CancelableCompletionCallback* net::CancelableCompletionRepeatingCallback*
AppCacheQuotaClient::GetServiceDeleteCallback() { AppCacheQuotaClient::GetServiceDeleteCallback() {
// Lazily created due to CancelableCompletionCallback's threading // Lazily created due to base::CancelableCallback's threading restrictions,
// restrictions, there is no way to detach from the thread created on. // there is no way to detach from the thread created on.
if (!service_delete_callback_) { if (!service_delete_callback_) {
service_delete_callback_.reset( service_delete_callback_ =
new net::CancelableCompletionCallback( std::make_unique<net::CancelableCompletionRepeatingCallback>(
base::Bind(&AppCacheQuotaClient::DidDeleteAppCachesForOrigin, base::BindRepeating(
base::Unretained(this)))); &AppCacheQuotaClient::DidDeleteAppCachesForOrigin,
base::Unretained(this)));
} }
return service_delete_callback_.get(); return service_delete_callback_.get();
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "content/browser/appcache/appcache_storage.h" #include "content/browser/appcache/appcache_storage.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "net/base/completion_callback.h" #include "net/base/completion_repeating_callback.h"
#include "storage/browser/quota/quota_client.h" #include "storage/browser/quota/quota_client.h"
#include "storage/browser/quota/quota_task.h" #include "storage/browser/quota/quota_task.h"
#include "third_party/blink/public/mojom/quota/quota_types.mojom.h" #include "third_party/blink/public/mojom/quota/quota_types.mojom.h"
...@@ -67,7 +67,7 @@ class AppCacheQuotaClient : public storage::QuotaClient { ...@@ -67,7 +67,7 @@ class AppCacheQuotaClient : public storage::QuotaClient {
void ProcessPendingRequests(); void ProcessPendingRequests();
void DeletePendingRequests(); void DeletePendingRequests();
const AppCacheStorage::UsageMap* GetUsageMap(); const AppCacheStorage::UsageMap* GetUsageMap();
net::CancelableCompletionCallback* GetServiceDeleteCallback(); net::CancelableCompletionRepeatingCallback* GetServiceDeleteCallback();
// For use by appcache internals during initialization and shutdown. // For use by appcache internals during initialization and shutdown.
CONTENT_EXPORT void NotifyAppCacheReady(); CONTENT_EXPORT void NotifyAppCacheReady();
...@@ -81,7 +81,8 @@ class AppCacheQuotaClient : public storage::QuotaClient { ...@@ -81,7 +81,8 @@ class AppCacheQuotaClient : public storage::QuotaClient {
// And once it's ready, we can only handle one delete request at a time, // And once it's ready, we can only handle one delete request at a time,
// so we queue up additional requests while one is in already in progress. // so we queue up additional requests while one is in already in progress.
DeletionCallback current_delete_request_callback_; DeletionCallback current_delete_request_callback_;
std::unique_ptr<net::CancelableCompletionCallback> service_delete_callback_; std::unique_ptr<net::CancelableCompletionRepeatingCallback>
service_delete_callback_;
AppCacheServiceImpl* service_; AppCacheServiceImpl* service_;
bool appcache_is_ready_; bool appcache_is_ready_;
......
...@@ -403,8 +403,8 @@ void AppCacheRequestHandler::OnMainResponseFound( ...@@ -403,8 +403,8 @@ void AppCacheRequestHandler::OnMainResponseFound(
} }
if (should_reset_appcache_ && !manifest_url.is_empty()) { if (should_reset_appcache_ && !manifest_url.is_empty()) {
host_->service()->DeleteAppCacheGroup( host_->service()->DeleteAppCacheGroup(manifest_url,
manifest_url, net::CompletionCallback()); net::CompletionOnceCallback());
DeliverNetworkResponse(); DeliverNetworkResponse();
return; return;
} }
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
#include <stddef.h> #include <stddef.h>
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/compiler_specific.h" #include "base/compiler_specific.h"
...@@ -17,7 +19,7 @@ ...@@ -17,7 +19,7 @@
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/threading/thread_task_runner_handle.h" #include "base/threading/thread_task_runner_handle.h"
#include "content/browser/appcache/appcache_storage.h" #include "content/browser/appcache/appcache_storage.h"
#include "net/base/completion_callback.h" #include "net/base/completion_once_callback.h"
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "storage/common/storage_histograms.h" #include "storage/common/storage_histograms.h"
...@@ -159,28 +161,34 @@ void AppCacheResponseIO::OpenEntryIfNeeded() { ...@@ -159,28 +161,34 @@ void AppCacheResponseIO::OpenEntryIfNeeded() {
rv = net::ERR_FAILED; rv = net::ERR_FAILED;
} else { } else {
entry_ptr = new AppCacheDiskCacheInterface::Entry*; entry_ptr = new AppCacheDiskCacheInterface::Entry*;
open_callback_ = rv = disk_cache_->OpenEntry(
base::Bind(&AppCacheResponseIO::OpenEntryCallback, response_id_, entry_ptr,
weak_factory_.GetWeakPtr(), base::Owned(entry_ptr)); base::BindOnce(&AppCacheResponseIO::OpenEntryCallback,
rv = disk_cache_->OpenEntry(response_id_, entry_ptr, open_callback_); weak_factory_.GetWeakPtr(), entry_ptr));
} }
if (rv != net::ERR_IO_PENDING) if (rv != net::ERR_IO_PENDING)
OpenEntryCallback(entry_ptr, rv); OpenEntryCallback(weak_factory_.GetWeakPtr(), entry_ptr, rv);
} }
// static
void AppCacheResponseIO::OpenEntryCallback( void AppCacheResponseIO::OpenEntryCallback(
AppCacheDiskCacheInterface::Entry** entry, int rv) { base::WeakPtr<AppCacheResponseIO> response,
DCHECK(info_buffer_.get() || buffer_.get()); AppCacheDiskCacheInterface::Entry** entry,
int rv) {
if (!response) {
delete entry;
return;
}
if (!open_callback_.is_null()) { DCHECK(response->info_buffer_.get() || response->buffer_.get());
if (rv == net::OK) {
DCHECK(entry); if (!response->entry_ && rv == net::OK) {
entry_ = *entry; DCHECK(entry);
} response->entry_ = *entry;
open_callback_.Reset();
} }
OnOpenEntryComplete(); delete entry;
response->OnOpenEntryComplete();
} }
...@@ -408,55 +416,73 @@ void AppCacheResponseWriter::CreateEntryIfNeededAndContinue() { ...@@ -408,55 +416,73 @@ void AppCacheResponseWriter::CreateEntryIfNeededAndContinue() {
} else { } else {
creation_phase_ = INITIAL_ATTEMPT; creation_phase_ = INITIAL_ATTEMPT;
entry_ptr = new AppCacheDiskCacheInterface::Entry*; entry_ptr = new AppCacheDiskCacheInterface::Entry*;
create_callback_ = rv = disk_cache_->CreateEntry(
base::Bind(&AppCacheResponseWriter::OnCreateEntryComplete, response_id_, entry_ptr,
weak_factory_.GetWeakPtr(), base::Owned(entry_ptr)); base::BindOnce(&AppCacheResponseWriter::OnCreateEntryComplete,
rv = disk_cache_->CreateEntry(response_id_, entry_ptr, create_callback_); weak_factory_.GetWeakPtr(), entry_ptr));
} }
if (rv != net::ERR_IO_PENDING) if (rv != net::ERR_IO_PENDING)
OnCreateEntryComplete(entry_ptr, rv); OnCreateEntryComplete(weak_factory_.GetWeakPtr(), entry_ptr, rv);
} }
// static
void AppCacheResponseWriter::OnCreateEntryComplete( void AppCacheResponseWriter::OnCreateEntryComplete(
AppCacheDiskCacheInterface::Entry** entry, int rv) { base::WeakPtr<AppCacheResponseWriter> writer,
DCHECK(info_buffer_.get() || buffer_.get()); AppCacheDiskCacheInterface::Entry** entry,
int rv) {
if (!writer) {
if (entry) {
delete entry;
}
return;
}
if (!disk_cache_) { DCHECK(writer->info_buffer_.get() || writer->buffer_.get());
ScheduleIOCompletionCallback(net::ERR_FAILED);
if (!writer->disk_cache_) {
if (entry) {
delete entry;
}
writer->ScheduleIOCompletionCallback(net::ERR_FAILED);
return; return;
} else if (creation_phase_ == INITIAL_ATTEMPT) { } else if (writer->creation_phase_ == INITIAL_ATTEMPT) {
if (rv != net::OK) { if (rv != net::OK) {
// We may try to overwrite existing entries. // We may try to overwrite existing entries.
creation_phase_ = DOOM_EXISTING; delete entry;
rv = disk_cache_->DoomEntry(response_id_, create_callback_); writer->creation_phase_ = DOOM_EXISTING;
rv = writer->disk_cache_->DoomEntry(
writer->response_id_,
base::BindOnce(&AppCacheResponseWriter::OnCreateEntryComplete, writer,
nullptr));
if (rv != net::ERR_IO_PENDING) if (rv != net::ERR_IO_PENDING)
OnCreateEntryComplete(nullptr, rv); OnCreateEntryComplete(writer, nullptr, rv);
return; return;
} }
} else if (creation_phase_ == DOOM_EXISTING) { } else if (writer->creation_phase_ == DOOM_EXISTING) {
creation_phase_ = SECOND_ATTEMPT; DCHECK_EQ(nullptr, entry);
writer->creation_phase_ = SECOND_ATTEMPT;
AppCacheDiskCacheInterface::Entry** entry_ptr = AppCacheDiskCacheInterface::Entry** entry_ptr =
new AppCacheDiskCacheInterface::Entry*; new AppCacheDiskCacheInterface::Entry*;
create_callback_ = rv = writer->disk_cache_->CreateEntry(
base::Bind(&AppCacheResponseWriter::OnCreateEntryComplete, writer->response_id_, entry_ptr,
weak_factory_.GetWeakPtr(), base::Owned(entry_ptr)); base::BindOnce(&AppCacheResponseWriter::OnCreateEntryComplete, writer,
rv = disk_cache_->CreateEntry(response_id_, entry_ptr, create_callback_); entry_ptr));
if (rv != net::ERR_IO_PENDING) if (rv != net::ERR_IO_PENDING)
OnCreateEntryComplete(entry_ptr, rv); OnCreateEntryComplete(writer, entry_ptr, rv);
return; return;
} }
if (!create_callback_.is_null()) { if (!writer->entry_ && rv == net::OK) {
if (rv == net::OK) DCHECK(entry);
entry_ = *entry; writer->entry_ = *entry;
create_callback_.Reset();
} }
if (info_buffer_.get()) delete entry;
ContinueWriteInfo();
if (writer->info_buffer_.get())
writer->ContinueWriteInfo();
else else
ContinueWriteData(); writer->ContinueWriteData();
} }
// AppCacheResponseMetadataWriter ---------------------------------------------- // AppCacheResponseMetadataWriter ----------------------------------------------
...@@ -474,7 +500,7 @@ AppCacheResponseMetadataWriter::~AppCacheResponseMetadataWriter() { ...@@ -474,7 +500,7 @@ AppCacheResponseMetadataWriter::~AppCacheResponseMetadataWriter() {
void AppCacheResponseMetadataWriter::WriteMetadata( void AppCacheResponseMetadataWriter::WriteMetadata(
net::IOBuffer* buf, net::IOBuffer* buf,
int buf_len, int buf_len,
const net::CompletionCallback& callback) { net::CompletionOnceCallback callback) {
DCHECK(!callback.is_null()); DCHECK(!callback.is_null());
DCHECK(!IsIOPending()); DCHECK(!IsIOPending());
DCHECK(buf); DCHECK(buf);
...@@ -483,7 +509,7 @@ void AppCacheResponseMetadataWriter::WriteMetadata( ...@@ -483,7 +509,7 @@ void AppCacheResponseMetadataWriter::WriteMetadata(
buffer_ = buf; buffer_ = buf;
write_amount_ = buf_len; write_amount_ = buf_len;
callback_ = callback; // cleared on completion callback_ = std::move(callback); // cleared on completion
OpenEntryIfNeeded(); OpenEntryIfNeeded();
} }
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "content/common/appcache_interfaces.h" #include "content/common/appcache_interfaces.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "net/base/completion_callback.h" #include "net/base/completion_once_callback.h"
#include "net/http/http_response_info.h" #include "net/http/http_response_info.h"
#include "url/gurl.h" #include "url/gurl.h"
...@@ -84,12 +84,12 @@ class CONTENT_EXPORT AppCacheDiskCacheInterface { ...@@ -84,12 +84,12 @@ class CONTENT_EXPORT AppCacheDiskCacheInterface {
int64_t offset, int64_t offset,
net::IOBuffer* buf, net::IOBuffer* buf,
int buf_len, int buf_len,
const net::CompletionCallback& callback) = 0; net::CompletionOnceCallback callback) = 0;
virtual int Write(int index, virtual int Write(int index,
int64_t offset, int64_t offset,
net::IOBuffer* buf, net::IOBuffer* buf,
int buf_len, int buf_len,
const net::CompletionCallback& callback) = 0; net::CompletionOnceCallback callback) = 0;
virtual int64_t GetSize(int index) = 0; virtual int64_t GetSize(int index) = 0;
virtual void Close() = 0; virtual void Close() = 0;
protected: protected:
...@@ -101,12 +101,11 @@ class CONTENT_EXPORT AppCacheDiskCacheInterface { ...@@ -101,12 +101,11 @@ class CONTENT_EXPORT AppCacheDiskCacheInterface {
virtual int CreateEntry(int64_t key, virtual int CreateEntry(int64_t key,
Entry** entry, Entry** entry,
const net::CompletionCallback& callback) = 0; net::CompletionOnceCallback callback) = 0;
virtual int OpenEntry(int64_t key, virtual int OpenEntry(int64_t key,
Entry** entry, Entry** entry,
const net::CompletionCallback& callback) = 0; net::CompletionOnceCallback callback) = 0;
virtual int DoomEntry(int64_t key, virtual int DoomEntry(int64_t key, net::CompletionOnceCallback callback) = 0;
const net::CompletionCallback& callback) = 0;
const char* uma_name() const { return uma_name_; } const char* uma_name() const { return uma_name_; }
base::WeakPtr<AppCacheDiskCacheInterface> GetWeakPtr(); base::WeakPtr<AppCacheDiskCacheInterface> GetWeakPtr();
...@@ -146,12 +145,14 @@ class CONTENT_EXPORT AppCacheResponseIO { ...@@ -146,12 +145,14 @@ class CONTENT_EXPORT AppCacheResponseIO {
scoped_refptr<net::IOBuffer> buffer_; scoped_refptr<net::IOBuffer> buffer_;
int buffer_len_; int buffer_len_;
OnceCompletionCallback callback_; OnceCompletionCallback callback_;
net::CompletionCallback open_callback_; net::CompletionOnceCallback open_callback_;
base::WeakPtrFactory<AppCacheResponseIO> weak_factory_; base::WeakPtrFactory<AppCacheResponseIO> weak_factory_;
private: private:
void OnRawIOComplete(int result); void OnRawIOComplete(int result);
void OpenEntryCallback(AppCacheDiskCacheInterface::Entry** entry, int rv); static void OpenEntryCallback(base::WeakPtr<AppCacheResponseIO> response,
AppCacheDiskCacheInterface::Entry** entry,
int rv);
}; };
// Reads existing response data from storage. If the object is deleted // Reads existing response data from storage. If the object is deleted
...@@ -277,13 +278,15 @@ class CONTENT_EXPORT AppCacheResponseWriter ...@@ -277,13 +278,15 @@ class CONTENT_EXPORT AppCacheResponseWriter
void ContinueWriteInfo(); void ContinueWriteInfo();
void ContinueWriteData(); void ContinueWriteData();
void CreateEntryIfNeededAndContinue(); void CreateEntryIfNeededAndContinue();
void OnCreateEntryComplete(AppCacheDiskCacheInterface::Entry** entry, int rv); static void OnCreateEntryComplete(
base::WeakPtr<AppCacheResponseWriter> writer,
AppCacheDiskCacheInterface::Entry** entry,
int rv);
int info_size_; int info_size_;
int write_position_; int write_position_;
int write_amount_; int write_amount_;
CreationPhase creation_phase_; CreationPhase creation_phase_;
net::CompletionCallback create_callback_;
base::WeakPtrFactory<AppCacheResponseWriter> weak_factory_; base::WeakPtrFactory<AppCacheResponseWriter> weak_factory_;
}; };
...@@ -307,7 +310,7 @@ class CONTENT_EXPORT AppCacheResponseMetadataWriter ...@@ -307,7 +310,7 @@ class CONTENT_EXPORT AppCacheResponseMetadataWriter
// progress. // progress.
void WriteMetadata(net::IOBuffer* buf, void WriteMetadata(net::IOBuffer* buf,
int buf_len, int buf_len,
const net::CompletionCallback& callback); net::CompletionOnceCallback callback);
// Returns true if there is a write pending. // Returns true if there is a write pending.
bool IsWritePending() { return IsIOPending(); } bool IsWritePending() { return IsIOPending(); }
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include "content/browser/appcache/appcache_response.h" #include "content/browser/appcache/appcache_response.h"
#include "content/browser/appcache/appcache_service_impl.h" #include "content/browser/appcache/appcache_service_impl.h"
#include "content/browser/appcache/appcache_storage_impl.h" #include "content/browser/appcache/appcache_storage_impl.h"
#include "net/base/completion_callback.h"
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
#include "storage/browser/quota/special_storage_policy.h" #include "storage/browser/quota/special_storage_policy.h"
...@@ -90,11 +89,11 @@ void AppCacheServiceImpl::AsyncHelper::Cancel() { ...@@ -90,11 +89,11 @@ void AppCacheServiceImpl::AsyncHelper::Cancel() {
class AppCacheServiceImpl::DeleteHelper : public AsyncHelper { class AppCacheServiceImpl::DeleteHelper : public AsyncHelper {
public: public:
DeleteHelper( DeleteHelper(AppCacheServiceImpl* service,
AppCacheServiceImpl* service, const GURL& manifest_url, const GURL& manifest_url,
const net::CompletionCallback& callback) net::CompletionOnceCallback callback)
: AsyncHelper(service, callback), manifest_url_(manifest_url) { : AsyncHelper(service, std::move(callback)),
} manifest_url_(manifest_url) {}
void Start() override { void Start() override {
service_->storage()->LoadOrCreateGroup(manifest_url_, this); service_->storage()->LoadOrCreateGroup(manifest_url_, this);
...@@ -137,8 +136,8 @@ class AppCacheServiceImpl::DeleteOriginHelper : public AsyncHelper { ...@@ -137,8 +136,8 @@ class AppCacheServiceImpl::DeleteOriginHelper : public AsyncHelper {
public: public:
DeleteOriginHelper(AppCacheServiceImpl* service, DeleteOriginHelper(AppCacheServiceImpl* service,
const url::Origin& origin, const url::Origin& origin,
const net::CompletionCallback& callback) net::CompletionOnceCallback callback)
: AsyncHelper(service, callback), : AsyncHelper(service, std::move(callback)),
origin_(origin), origin_(origin),
num_caches_to_delete_(0), num_caches_to_delete_(0),
successes_(0), successes_(0),
...@@ -261,7 +260,7 @@ class AppCacheServiceImpl::CheckResponseHelper : AsyncHelper { ...@@ -261,7 +260,7 @@ class AppCacheServiceImpl::CheckResponseHelper : AsyncHelper {
const GURL& manifest_url, const GURL& manifest_url,
int64_t cache_id, int64_t cache_id,
int64_t response_id) int64_t response_id)
: AsyncHelper(service, net::CompletionCallback()), : AsyncHelper(service, net::CompletionOnceCallback()),
manifest_url_(manifest_url), manifest_url_(manifest_url),
cache_id_(cache_id), cache_id_(cache_id),
response_id_(response_id), response_id_(response_id),
...@@ -320,7 +319,8 @@ void AppCacheServiceImpl::CheckResponseHelper::OnGroupLoaded( ...@@ -320,7 +319,8 @@ void AppCacheServiceImpl::CheckResponseHelper::OnGroupLoaded(
if (cache_->cache_id() == cache_id_) { if (cache_->cache_id() == cache_id_) {
AppCacheHistograms::CountCheckResponseResult( AppCacheHistograms::CountCheckResponseResult(
AppCacheHistograms::ENTRY_NOT_FOUND); AppCacheHistograms::ENTRY_NOT_FOUND);
service_->DeleteAppCacheGroup(manifest_url_, net::CompletionCallback()); service_->DeleteAppCacheGroup(manifest_url_,
net::CompletionOnceCallback());
} else { } else {
AppCacheHistograms::CountCheckResponseResult( AppCacheHistograms::CountCheckResponseResult(
AppCacheHistograms::RESPONSE_OUT_OF_DATE); AppCacheHistograms::RESPONSE_OUT_OF_DATE);
...@@ -344,7 +344,7 @@ void AppCacheServiceImpl::CheckResponseHelper::OnReadInfoComplete(int result) { ...@@ -344,7 +344,7 @@ void AppCacheServiceImpl::CheckResponseHelper::OnReadInfoComplete(int result) {
if (result < 0) { if (result < 0) {
AppCacheHistograms::CountCheckResponseResult( AppCacheHistograms::CountCheckResponseResult(
AppCacheHistograms::READ_HEADERS_ERROR); AppCacheHistograms::READ_HEADERS_ERROR);
service_->DeleteAppCacheGroup(manifest_url_, net::CompletionCallback()); service_->DeleteAppCacheGroup(manifest_url_, net::CompletionOnceCallback());
delete this; delete this;
return; return;
} }
...@@ -380,7 +380,7 @@ void AppCacheServiceImpl::CheckResponseHelper::OnReadDataComplete(int result) { ...@@ -380,7 +380,7 @@ void AppCacheServiceImpl::CheckResponseHelper::OnReadDataComplete(int result) {
AppCacheHistograms::CountCheckResponseResult(check_result); AppCacheHistograms::CountCheckResponseResult(check_result);
if (check_result != AppCacheHistograms::RESPONSE_OK) if (check_result != AppCacheHistograms::RESPONSE_OK)
service_->DeleteAppCacheGroup(manifest_url_, net::CompletionCallback()); service_->DeleteAppCacheGroup(manifest_url_, net::CompletionOnceCallback());
delete this; delete this;
} }
...@@ -484,15 +484,17 @@ void AppCacheServiceImpl::GetAllAppCacheInfo(AppCacheInfoCollection* collection, ...@@ -484,15 +484,17 @@ void AppCacheServiceImpl::GetAllAppCacheInfo(AppCacheInfoCollection* collection,
void AppCacheServiceImpl::DeleteAppCacheGroup( void AppCacheServiceImpl::DeleteAppCacheGroup(
const GURL& manifest_url, const GURL& manifest_url,
const net::CompletionCallback& callback) { net::CompletionOnceCallback callback) {
DeleteHelper* helper = new DeleteHelper(this, manifest_url, callback); DeleteHelper* helper =
new DeleteHelper(this, manifest_url, std::move(callback));
helper->Start(); helper->Start();
} }
void AppCacheServiceImpl::DeleteAppCachesForOrigin( void AppCacheServiceImpl::DeleteAppCachesForOrigin(
const url::Origin& origin, const url::Origin& origin,
const net::CompletionCallback& callback) { net::CompletionOnceCallback callback) {
DeleteOriginHelper* helper = new DeleteOriginHelper(this, origin, callback); DeleteOriginHelper* helper =
new DeleteOriginHelper(this, origin, std::move(callback));
helper->Start(); helper->Start();
} }
......
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
#include "content/common/appcache_interfaces.h" #include "content/common/appcache_interfaces.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/public/browser/appcache_service.h" #include "content/public/browser/appcache_service.h"
#include "net/base/completion_callback.h" #include "net/base/completion_once_callback.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "storage/browser/quota/quota_manager_proxy.h" #include "storage/browser/quota/quota_manager_proxy.h"
...@@ -105,14 +105,13 @@ class CONTENT_EXPORT AppCacheServiceImpl ...@@ -105,14 +105,13 @@ class CONTENT_EXPORT AppCacheServiceImpl
void GetAllAppCacheInfo(AppCacheInfoCollection* collection, void GetAllAppCacheInfo(AppCacheInfoCollection* collection,
OnceCompletionCallback callback) override; OnceCompletionCallback callback) override;
void DeleteAppCacheGroup(const GURL& manifest_url, void DeleteAppCacheGroup(const GURL& manifest_url,
const net::CompletionCallback& callback) override; net::CompletionOnceCallback callback) override;
// Deletes all appcaches for the origin, 'callback' is invoked upon // Deletes all appcaches for the origin, 'callback' is invoked upon
// completion. This method always completes asynchronously. // completion. This method always completes asynchronously.
// (virtual for unit testing) // (virtual for unit testing)
virtual void DeleteAppCachesForOrigin( virtual void DeleteAppCachesForOrigin(const url::Origin& origin,
const url::Origin& origin, net::CompletionOnceCallback callback);
const net::CompletionCallback& callback);
// Checks the integrity of 'response_id' by reading the headers and data. // Checks the integrity of 'response_id' by reading the headers and data.
// If it cannot be read, the cache group for 'manifest_url' is deleted. // If it cannot be read, the cache group for 'manifest_url' is deleted.
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
#include "content/browser/appcache/appcache_response.h" #include "content/browser/appcache/appcache_response.h"
#include "content/browser/appcache/appcache_service_impl.h" #include "content/browser/appcache/appcache_service_impl.h"
#include "content/browser/appcache/mock_appcache_storage.h" #include "content/browser/appcache/mock_appcache_storage.h"
#include "net/base/completion_callback.h" #include "net/base/completion_once_callback.h"
#include "net/base/io_buffer.h" #include "net/base/io_buffer.h"
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -101,10 +101,7 @@ class AppCacheServiceImplTest : public testing::Test { ...@@ -101,10 +101,7 @@ class AppCacheServiceImplTest : public testing::Test {
kManifestUrl(kOriginURL.Resolve("manifest")), kManifestUrl(kOriginURL.Resolve("manifest")),
service_(new AppCacheServiceImpl(nullptr)), service_(new AppCacheServiceImpl(nullptr)),
delete_result_(net::OK), delete_result_(net::OK),
delete_completion_count_(0), delete_completion_count_(0) {
deletion_callback_(
base::Bind(&AppCacheServiceImplTest::OnDeleteAppCachesComplete,
base::Unretained(this))) {
// Setup to use mock storage. // Setup to use mock storage.
service_->storage_.reset(new MockAppCacheStorage(service_.get())); service_->storage_.reset(new MockAppCacheStorage(service_.get()));
} }
...@@ -183,6 +180,11 @@ class AppCacheServiceImplTest : public testing::Test { ...@@ -183,6 +180,11 @@ class AppCacheServiceImplTest : public testing::Test {
return pickle->size(); return pickle->size();
} }
net::CompletionOnceCallback deletion_callback() {
return base::BindOnce(&AppCacheServiceImplTest::OnDeleteAppCachesComplete,
base::Unretained(this));
}
const GURL kOriginURL; const GURL kOriginURL;
const url::Origin kOrigin; const url::Origin kOrigin;
const GURL kManifestUrl; const GURL kManifestUrl;
...@@ -191,12 +193,11 @@ class AppCacheServiceImplTest : public testing::Test { ...@@ -191,12 +193,11 @@ class AppCacheServiceImplTest : public testing::Test {
std::unique_ptr<AppCacheServiceImpl> service_; std::unique_ptr<AppCacheServiceImpl> service_;
int delete_result_; int delete_result_;
int delete_completion_count_; int delete_completion_count_;
net::CompletionCallback deletion_callback_;
}; };
TEST_F(AppCacheServiceImplTest, DeleteAppCachesForOrigin) { TEST_F(AppCacheServiceImplTest, DeleteAppCachesForOrigin) {
// Without giving mock storage simiulated info, should fail. // Without giving mock storage simiulated info, should fail.
service_->DeleteAppCachesForOrigin(kOrigin, deletion_callback_); service_->DeleteAppCachesForOrigin(kOrigin, deletion_callback());
EXPECT_EQ(0, delete_completion_count_); EXPECT_EQ(0, delete_completion_count_);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, delete_completion_count_); EXPECT_EQ(1, delete_completion_count_);
...@@ -205,7 +206,7 @@ TEST_F(AppCacheServiceImplTest, DeleteAppCachesForOrigin) { ...@@ -205,7 +206,7 @@ TEST_F(AppCacheServiceImplTest, DeleteAppCachesForOrigin) {
// Should succeed given an empty info collection. // Should succeed given an empty info collection.
mock_storage()->SimulateGetAllInfo(new content::AppCacheInfoCollection); mock_storage()->SimulateGetAllInfo(new content::AppCacheInfoCollection);
service_->DeleteAppCachesForOrigin(kOrigin, deletion_callback_); service_->DeleteAppCachesForOrigin(kOrigin, deletion_callback());
EXPECT_EQ(0, delete_completion_count_); EXPECT_EQ(0, delete_completion_count_);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, delete_completion_count_); EXPECT_EQ(1, delete_completion_count_);
...@@ -227,7 +228,7 @@ TEST_F(AppCacheServiceImplTest, DeleteAppCachesForOrigin) { ...@@ -227,7 +228,7 @@ TEST_F(AppCacheServiceImplTest, DeleteAppCachesForOrigin) {
info_vector.push_back(mock_manifest_3); info_vector.push_back(mock_manifest_3);
info->infos_by_origin[kOrigin] = info_vector; info->infos_by_origin[kOrigin] = info_vector;
mock_storage()->SimulateGetAllInfo(info.get()); mock_storage()->SimulateGetAllInfo(info.get());
service_->DeleteAppCachesForOrigin(kOrigin, deletion_callback_); service_->DeleteAppCachesForOrigin(kOrigin, deletion_callback());
EXPECT_EQ(0, delete_completion_count_); EXPECT_EQ(0, delete_completion_count_);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, delete_completion_count_); EXPECT_EQ(1, delete_completion_count_);
...@@ -238,7 +239,7 @@ TEST_F(AppCacheServiceImplTest, DeleteAppCachesForOrigin) { ...@@ -238,7 +239,7 @@ TEST_F(AppCacheServiceImplTest, DeleteAppCachesForOrigin) {
info->infos_by_origin[kOrigin] = info_vector; info->infos_by_origin[kOrigin] = info_vector;
mock_storage()->SimulateGetAllInfo(info.get()); mock_storage()->SimulateGetAllInfo(info.get());
mock_storage()->SimulateMakeGroupObsoleteFailure(); mock_storage()->SimulateMakeGroupObsoleteFailure();
service_->DeleteAppCachesForOrigin(kOrigin, deletion_callback_); service_->DeleteAppCachesForOrigin(kOrigin, deletion_callback());
EXPECT_EQ(0, delete_completion_count_); EXPECT_EQ(0, delete_completion_count_);
base::RunLoop().RunUntilIdle(); base::RunLoop().RunUntilIdle();
EXPECT_EQ(1, delete_completion_count_); EXPECT_EQ(1, delete_completion_count_);
...@@ -247,7 +248,7 @@ TEST_F(AppCacheServiceImplTest, DeleteAppCachesForOrigin) { ...@@ -247,7 +248,7 @@ TEST_F(AppCacheServiceImplTest, DeleteAppCachesForOrigin) {
// Should complete with abort error if the service is deleted // Should complete with abort error if the service is deleted
// prior to a delete completion. // prior to a delete completion.
service_->DeleteAppCachesForOrigin(kOrigin, deletion_callback_); service_->DeleteAppCachesForOrigin(kOrigin, deletion_callback());
EXPECT_EQ(0, delete_completion_count_); EXPECT_EQ(0, delete_completion_count_);
service_.reset(); // kill it service_.reset(); // kill it
EXPECT_EQ(1, delete_completion_count_); EXPECT_EQ(1, delete_completion_count_);
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "content/browser/appcache/appcache_working_set.h" #include "content/browser/appcache/appcache_working_set.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "net/base/completion_callback.h"
#include "url/origin.h" #include "url/origin.h"
class GURL; class GURL;
......
...@@ -893,7 +893,8 @@ void AppCacheUpdateJob::CheckIfManifestChanged() { ...@@ -893,7 +893,8 @@ void AppCacheUpdateJob::CheckIfManifestChanged() {
GURL(), 0, false /*is_cross_origin*/), GURL(), 0, false /*is_cross_origin*/),
DB_ERROR, GURL()); DB_ERROR, GURL());
AppCacheHistograms::AddMissingManifestEntrySample(); AppCacheHistograms::AddMissingManifestEntrySample();
service->DeleteAppCacheGroup(manifest_url_, net::CompletionCallback()); service->DeleteAppCacheGroup(manifest_url_,
net::CompletionOnceCallback());
} }
return; return;
} }
......
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "content/browser/appcache/appcache_storage.h" #include "content/browser/appcache/appcache_storage.h"
#include "content/common/appcache_interfaces.h" #include "content/common/appcache_interfaces.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "net/base/completion_callback.h"
#include "net/http/http_response_headers.h" #include "net/http/http_response_headers.h"
#include "net/url_request/url_request.h" #include "net/url_request/url_request.h"
#include "url/gurl.h" #include "url/gurl.h"
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "content/browser/appcache/mock_appcache_service.h" #include "content/browser/appcache/mock_appcache_service.h"
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/location.h" #include "base/location.h"
#include "base/single_thread_task_runner.h" #include "base/single_thread_task_runner.h"
...@@ -11,17 +13,16 @@ ...@@ -11,17 +13,16 @@
namespace content { namespace content {
static void DeferredCallCallback( static void DeferredCallCallback(net::CompletionOnceCallback callback, int rv) {
const net::CompletionCallback& callback, int rv) { std::move(callback).Run(rv);
callback.Run(rv);
} }
void MockAppCacheService::DeleteAppCachesForOrigin( void MockAppCacheService::DeleteAppCachesForOrigin(
const url::Origin& origin, const url::Origin& origin,
const net::CompletionCallback& callback) { net::CompletionOnceCallback callback) {
++delete_called_count_; ++delete_called_count_;
base::ThreadTaskRunnerHandle::Get()->PostTask( base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&DeferredCallCallback, callback, FROM_HERE, base::BindOnce(&DeferredCallCallback, std::move(callback),
mock_delete_appcaches_for_origin_result_)); mock_delete_appcaches_for_origin_result_));
} }
......
...@@ -24,9 +24,8 @@ class MockAppCacheService : public AppCacheServiceImpl { ...@@ -24,9 +24,8 @@ class MockAppCacheService : public AppCacheServiceImpl {
// Just returns a canned completion code without actually // Just returns a canned completion code without actually
// removing groups and caches in our mock storage instance. // removing groups and caches in our mock storage instance.
void DeleteAppCachesForOrigin( void DeleteAppCachesForOrigin(const url::Origin& origin,
const url::Origin& origin, net::CompletionOnceCallback callback) override;
const net::CompletionCallback& callback) override;
void set_quota_manager_proxy(storage::QuotaManagerProxy* proxy) { void set_quota_manager_proxy(storage::QuotaManagerProxy* proxy) {
quota_manager_proxy_ = proxy; quota_manager_proxy_ = proxy;
......
...@@ -144,7 +144,8 @@ class MockAppCacheStorage : public AppCacheStorage { ...@@ -144,7 +144,8 @@ class MockAppCacheStorage : public AppCacheStorage {
if (!disk_cache_) { if (!disk_cache_) {
const int kMaxCacheSize = 10 * 1024 * 1024; const int kMaxCacheSize = 10 * 1024 * 1024;
disk_cache_.reset(new AppCacheDiskCache); disk_cache_.reset(new AppCacheDiskCache);
disk_cache_->InitWithMemBackend(kMaxCacheSize, net::CompletionCallback()); disk_cache_->InitWithMemBackend(kMaxCacheSize,
net::CompletionOnceCallback());
} }
return disk_cache_.get(); return disk_cache_.get();
} }
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "content/public/common/appcache_info.h" #include "content/public/common/appcache_info.h"
#include "net/base/completion_callback.h" #include "net/base/completion_once_callback.h"
#include "url/origin.h" #include "url/origin.h"
namespace content { namespace content {
...@@ -46,7 +46,7 @@ class CONTENT_EXPORT AppCacheService { ...@@ -46,7 +46,7 @@ class CONTENT_EXPORT AppCacheService {
// subresource loads for pages associated with a deleted group // subresource loads for pages associated with a deleted group
// will fail. This method always completes asynchronously. // will fail. This method always completes asynchronously.
virtual void DeleteAppCacheGroup(const GURL& manifest_url, virtual void DeleteAppCacheGroup(const GURL& manifest_url,
const net::CompletionCallback& callback) = 0; net::CompletionOnceCallback callback) = 0;
protected: protected:
virtual ~AppCacheService() {} virtual ~AppCacheService() {}
......
...@@ -21,8 +21,6 @@ typedef base::Callback<void(int)> CompletionCallback; ...@@ -21,8 +21,6 @@ typedef base::Callback<void(int)> CompletionCallback;
// error code. // error code.
typedef base::Callback<void(int64_t)> Int64CompletionCallback; typedef base::Callback<void(int64_t)> Int64CompletionCallback;
typedef base::CancelableCallback<void(int)> CancelableCompletionCallback;
} // namespace net } // namespace net
#endif // NET_BASE_COMPLETION_CALLBACK_H_ #endif // NET_BASE_COMPLETION_CALLBACK_H_
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