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

Use CompletionOnceCallback in ViewCacheHelper.

Bug: 807724
Change-Id: I065796ef6b9f954f3e623b0c5db800b24889d95b
Reviewed-on: https://chromium-review.googlesource.com/1155088Reviewed-by: default avatarRyan Hamilton <rch@chromium.org>
Commit-Queue: Bence Béky <bnc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#579493}
parent 86055195
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "net/url_request/view_cache_helper.h" #include "net/url_request/view_cache_helper.h"
#include <utility>
#include "base/bind.h" #include "base/bind.h"
#include "base/bind_helpers.h" #include "base/bind_helpers.h"
#include "base/strings/stringprintf.h" #include "base/strings/stringprintf.h"
...@@ -61,15 +63,16 @@ ViewCacheHelper::~ViewCacheHelper() { ...@@ -61,15 +63,16 @@ ViewCacheHelper::~ViewCacheHelper() {
int ViewCacheHelper::GetEntryInfoHTML(const std::string& key, int ViewCacheHelper::GetEntryInfoHTML(const std::string& key,
const URLRequestContext* context, const URLRequestContext* context,
std::string* out, std::string* out,
const CompletionCallback& callback) { CompletionOnceCallback callback) {
return GetInfoHTML(key, context, std::string(), out, callback); return GetInfoHTML(key, context, std::string(), out, std::move(callback));
} }
int ViewCacheHelper::GetContentsHTML(const URLRequestContext* context, int ViewCacheHelper::GetContentsHTML(const URLRequestContext* context,
const std::string& url_prefix, const std::string& url_prefix,
std::string* out, std::string* out,
const CompletionCallback& callback) { CompletionOnceCallback callback) {
return GetInfoHTML(std::string(), context, url_prefix, out, callback); return GetInfoHTML(std::string(), context, url_prefix, out,
std::move(callback));
} }
// static // static
...@@ -118,7 +121,7 @@ int ViewCacheHelper::GetInfoHTML(const std::string& key, ...@@ -118,7 +121,7 @@ int ViewCacheHelper::GetInfoHTML(const std::string& key,
const URLRequestContext* context, const URLRequestContext* context,
const std::string& url_prefix, const std::string& url_prefix,
std::string* out, std::string* out,
const CompletionCallback& callback) { CompletionOnceCallback callback) {
DCHECK(callback_.is_null()); DCHECK(callback_.is_null());
DCHECK(context); DCHECK(context);
key_ = key; key_ = key;
...@@ -129,7 +132,7 @@ int ViewCacheHelper::GetInfoHTML(const std::string& key, ...@@ -129,7 +132,7 @@ int ViewCacheHelper::GetInfoHTML(const std::string& key,
int rv = DoLoop(OK); int rv = DoLoop(OK);
if (rv == ERR_IO_PENDING) if (rv == ERR_IO_PENDING)
callback_ = callback; callback_ = std::move(callback);
return rv; return rv;
} }
...@@ -138,8 +141,7 @@ void ViewCacheHelper::DoCallback(int rv) { ...@@ -138,8 +141,7 @@ void ViewCacheHelper::DoCallback(int rv) {
DCHECK_NE(ERR_IO_PENDING, rv); DCHECK_NE(ERR_IO_PENDING, rv);
DCHECK(!callback_.is_null()); DCHECK(!callback_.is_null());
callback_.Run(rv); std::move(callback_).Run(rv);
callback_.Reset();
} }
void ViewCacheHelper::HandleResult(int rv) { void ViewCacheHelper::HandleResult(int rv) {
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.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_export.h" #include "net/base/net_export.h"
#include "net/disk_cache/disk_cache.h" #include "net/disk_cache/disk_cache.h"
...@@ -32,7 +32,7 @@ class NET_EXPORT ViewCacheHelper { ...@@ -32,7 +32,7 @@ class NET_EXPORT ViewCacheHelper {
int GetEntryInfoHTML(const std::string& key, int GetEntryInfoHTML(const std::string& key,
const URLRequestContext* context, const URLRequestContext* context,
std::string* out, std::string* out,
const CompletionCallback& callback); CompletionOnceCallback callback);
// Formats the cache contents as HTML. Returns a net error code. // Formats the cache contents as HTML. Returns a net error code.
// If this method returns ERR_IO_PENDING, |callback| will be notified when the // If this method returns ERR_IO_PENDING, |callback| will be notified when the
...@@ -42,7 +42,7 @@ class NET_EXPORT ViewCacheHelper { ...@@ -42,7 +42,7 @@ class NET_EXPORT ViewCacheHelper {
int GetContentsHTML(const URLRequestContext* context, int GetContentsHTML(const URLRequestContext* context,
const std::string& url_prefix, const std::string& url_prefix,
std::string* out, std::string* out,
const CompletionCallback& callback); CompletionOnceCallback callback);
// Lower-level helper to produce a textual representation of binary data. // Lower-level helper to produce a textual representation of binary data.
// The results are appended to |result| and can be used in HTML pages // The results are appended to |result| and can be used in HTML pages
...@@ -69,7 +69,7 @@ class NET_EXPORT ViewCacheHelper { ...@@ -69,7 +69,7 @@ class NET_EXPORT ViewCacheHelper {
const URLRequestContext* context, const URLRequestContext* context,
const std::string& url_prefix, const std::string& url_prefix,
std::string* out, std::string* out,
const CompletionCallback& callback); CompletionOnceCallback callback);
// This is a helper function used to trigger a completion callback. It may // This is a helper function used to trigger a completion callback. It may
// only be called if callback_ is non-null. // only be called if callback_ is non-null.
...@@ -109,7 +109,7 @@ class NET_EXPORT ViewCacheHelper { ...@@ -109,7 +109,7 @@ class NET_EXPORT ViewCacheHelper {
std::string key_; std::string key_;
std::string url_prefix_; std::string url_prefix_;
std::string* data_; std::string* data_;
CompletionCallback callback_; CompletionOnceCallback callback_;
State next_state_; State next_state_;
......
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