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

Use CompletionOnceCallback in FtpTransaction.

Bug: 807724
Change-Id: I018eb874f2e9097dba9d8acdf58d6a18c569cc9d
Reviewed-on: https://chromium-review.googlesource.com/1100354Reviewed-by: default avatarZhongyi Shi <zhongyi@chromium.org>
Commit-Queue: Bence Béky <bnc@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567988}
parent 4765c1ec
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/values.h" #include "base/values.h"
#include "net/base/address_list.h" #include "net/base/address_list.h"
#include "net/base/completion_once_callback.h"
#include "net/base/escape.h" #include "net/base/escape.h"
#include "net/base/net_errors.h" #include "net/base/net_errors.h"
#include "net/base/parse_number.h" #include "net/base/parse_number.h"
...@@ -257,7 +258,7 @@ int FtpNetworkTransaction::Stop(int error) { ...@@ -257,7 +258,7 @@ int FtpNetworkTransaction::Stop(int error) {
int FtpNetworkTransaction::Start( int FtpNetworkTransaction::Start(
const FtpRequestInfo* request_info, const FtpRequestInfo* request_info,
const CompletionCallback& callback, CompletionOnceCallback callback,
const NetLogWithSource& net_log, const NetLogWithSource& net_log,
const NetworkTrafficAnnotationTag& traffic_annotation) { const NetworkTrafficAnnotationTag& traffic_annotation) {
net_log_ = net_log; net_log_ = net_log;
...@@ -281,12 +282,12 @@ int FtpNetworkTransaction::Start( ...@@ -281,12 +282,12 @@ int FtpNetworkTransaction::Start(
next_state_ = STATE_CTRL_RESOLVE_HOST; next_state_ = STATE_CTRL_RESOLVE_HOST;
int rv = DoLoop(OK); int rv = DoLoop(OK);
if (rv == ERR_IO_PENDING) if (rv == ERR_IO_PENDING)
user_callback_ = callback; user_callback_ = std::move(callback);
return rv; return rv;
} }
int FtpNetworkTransaction::RestartWithAuth(const AuthCredentials& credentials, int FtpNetworkTransaction::RestartWithAuth(const AuthCredentials& credentials,
const CompletionCallback& callback) { CompletionOnceCallback callback) {
ResetStateForRestart(); ResetStateForRestart();
credentials_ = credentials; credentials_ = credentials;
...@@ -294,13 +295,13 @@ int FtpNetworkTransaction::RestartWithAuth(const AuthCredentials& credentials, ...@@ -294,13 +295,13 @@ int FtpNetworkTransaction::RestartWithAuth(const AuthCredentials& credentials,
next_state_ = STATE_CTRL_RESOLVE_HOST; next_state_ = STATE_CTRL_RESOLVE_HOST;
int rv = DoLoop(OK); int rv = DoLoop(OK);
if (rv == ERR_IO_PENDING) if (rv == ERR_IO_PENDING)
user_callback_ = callback; user_callback_ = std::move(callback);
return rv; return rv;
} }
int FtpNetworkTransaction::Read(IOBuffer* buf, int FtpNetworkTransaction::Read(IOBuffer* buf,
int buf_len, int buf_len,
const CompletionCallback& callback) { CompletionOnceCallback callback) {
DCHECK(buf); DCHECK(buf);
DCHECK_GT(buf_len, 0); DCHECK_GT(buf_len, 0);
...@@ -310,7 +311,7 @@ int FtpNetworkTransaction::Read(IOBuffer* buf, ...@@ -310,7 +311,7 @@ int FtpNetworkTransaction::Read(IOBuffer* buf,
next_state_ = STATE_DATA_READ; next_state_ = STATE_DATA_READ;
int rv = DoLoop(OK); int rv = DoLoop(OK);
if (rv == ERR_IO_PENDING) if (rv == ERR_IO_PENDING)
user_callback_ = callback; user_callback_ = std::move(callback);
return rv; return rv;
} }
...@@ -372,10 +373,8 @@ void FtpNetworkTransaction::EstablishDataConnection(State state_after_connect) { ...@@ -372,10 +373,8 @@ void FtpNetworkTransaction::EstablishDataConnection(State state_after_connect) {
void FtpNetworkTransaction::DoCallback(int rv) { void FtpNetworkTransaction::DoCallback(int rv) {
DCHECK(rv != ERR_IO_PENDING); DCHECK(rv != ERR_IO_PENDING);
DCHECK(!user_callback_.is_null());
// Since Run may result in Read being called, clear callback_ up front. std::move(user_callback_).Run(rv);
base::ResetAndReturn(&user_callback_).Run(rv);
} }
void FtpNetworkTransaction::OnIOComplete(int result) { void FtpNetworkTransaction::OnIOComplete(int result) {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "net/base/address_list.h" #include "net/base/address_list.h"
#include "net/base/auth.h" #include "net/base/auth.h"
#include "net/base/completion_once_callback.h"
#include "net/base/completion_repeating_callback.h" #include "net/base/completion_repeating_callback.h"
#include "net/base/net_export.h" #include "net/base/net_export.h"
#include "net/dns/host_resolver.h" #include "net/dns/host_resolver.h"
...@@ -40,14 +41,14 @@ class NET_EXPORT_PRIVATE FtpNetworkTransaction : public FtpTransaction { ...@@ -40,14 +41,14 @@ class NET_EXPORT_PRIVATE FtpNetworkTransaction : public FtpTransaction {
// FtpTransaction methods: // FtpTransaction methods:
int Start(const FtpRequestInfo* request_info, int Start(const FtpRequestInfo* request_info,
const CompletionCallback& callback, CompletionOnceCallback callback,
const NetLogWithSource& net_log, const NetLogWithSource& net_log,
const NetworkTrafficAnnotationTag& traffic_annotation) override; const NetworkTrafficAnnotationTag& traffic_annotation) override;
int RestartWithAuth(const AuthCredentials& credentials, int RestartWithAuth(const AuthCredentials& credentials,
const CompletionCallback& callback) override; CompletionOnceCallback callback) override;
int Read(IOBuffer* buf, int Read(IOBuffer* buf,
int buf_len, int buf_len,
const CompletionCallback& callback) override; CompletionOnceCallback callback) override;
const FtpResponseInfo* GetResponseInfo() const override; const FtpResponseInfo* GetResponseInfo() const override;
LoadState GetLoadState() const override; LoadState GetLoadState() const override;
uint64_t GetUploadProgress() const override; uint64_t GetUploadProgress() const override;
...@@ -203,7 +204,7 @@ class NET_EXPORT_PRIVATE FtpNetworkTransaction : public FtpTransaction { ...@@ -203,7 +204,7 @@ class NET_EXPORT_PRIVATE FtpNetworkTransaction : public FtpTransaction {
Command command_sent_; Command command_sent_;
CompletionRepeatingCallback io_callback_; CompletionRepeatingCallback io_callback_;
CompletionCallback user_callback_; CompletionOnceCallback user_callback_;
NetLogWithSource net_log_; NetLogWithSource net_log_;
const FtpRequestInfo* request_; const FtpRequestInfo* request_;
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <stdint.h> #include <stdint.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/load_states.h" #include "net/base/load_states.h"
#include "net/base/net_export.h" #include "net/base/net_export.h"
...@@ -30,10 +30,9 @@ class NET_EXPORT_PRIVATE FtpTransaction { ...@@ -30,10 +30,9 @@ class NET_EXPORT_PRIVATE FtpTransaction {
// //
// Returns OK if the transaction could be started synchronously, which means // Returns OK if the transaction could be started synchronously, which means
// that the request was served from the cache (only supported for directory // that the request was served from the cache (only supported for directory
// listings). ERR_IO_PENDING is returned to indicate that the // listings). ERR_IO_PENDING is returned to indicate that |callback| will be
// CompletionCallback will be notified once response info is available or if // notified once response info is available or if an IO error occurs. Any
// an IO error occurs. Any other return value indicates that the transaction // other return value indicates that the transaction could not be started.
// could not be started.
// //
// Regardless of the return value, the caller is expected to keep the // Regardless of the return value, the caller is expected to keep the
// request_info object alive until Destroy is called on the transaction. // request_info object alive until Destroy is called on the transaction.
...@@ -42,30 +41,29 @@ class NET_EXPORT_PRIVATE FtpTransaction { ...@@ -42,30 +41,29 @@ class NET_EXPORT_PRIVATE FtpTransaction {
// //
// Profiling information for the request is saved to |net_log| if non-NULL. // Profiling information for the request is saved to |net_log| if non-NULL.
virtual int Start(const FtpRequestInfo* request_info, virtual int Start(const FtpRequestInfo* request_info,
const CompletionCallback& callback, CompletionOnceCallback callback,
const NetLogWithSource& net_log, const NetLogWithSource& net_log,
const NetworkTrafficAnnotationTag& traffic_annotation) = 0; const NetworkTrafficAnnotationTag& traffic_annotation) = 0;
// Restarts the FTP transaction with authentication credentials. // Restarts the FTP transaction with authentication credentials.
virtual int RestartWithAuth(const AuthCredentials& credentials, virtual int RestartWithAuth(const AuthCredentials& credentials,
const CompletionCallback& callback) = 0; CompletionOnceCallback callback) = 0;
// Once response info is available for the transaction, response data may be // Once response info is available for the transaction, response data may be
// read by calling this method. // read by calling this method.
// //
// Response data is copied into the given buffer and the number of bytes // Response data is copied into the given buffer and the number of bytes
// copied is returned. ERR_IO_PENDING is returned if response data is not // copied is returned. ERR_IO_PENDING is returned if response data is not yet
// yet available. The CompletionCallback is notified when the data copy // available. |callback| is notified when the data copy completes, and it is
// completes, and it is passed the number of bytes that were successfully // passed the number of bytes that were successfully copied. Or, if a read
// copied. Or, if a read error occurs, the CompletionCallback is notified of // error occurs, |callback| is notified of the error. Any other negative
// the error. Any other negative return value indicates that the transaction // return value indicates that the transaction could not be read.
// could not be read.
// //
// NOTE: The transaction is not responsible for deleting the callback object. // NOTE: The transaction is not responsible for deleting the callback object.
// //
virtual int Read(IOBuffer* buf, virtual int Read(IOBuffer* buf,
int buf_len, int buf_len,
const CompletionCallback& callback) = 0; CompletionOnceCallback callback) = 0;
// Returns the response info for this transaction or NULL if the response // Returns the response info for this transaction or NULL if the response
// info is not available. // info is not available.
......
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