1// Copyright (c) 2010 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef NET_FTP_FTP_TRANSACTION_H_
6#define NET_FTP_FTP_TRANSACTION_H_
7#pragma once
8
9#include "base/string16.h"
10#include "net/base/completion_callback.h"
11#include "net/base/io_buffer.h"
12#include "net/base/load_states.h"
13
14namespace net {
15
16class FtpResponseInfo;
17class FtpRequestInfo;
18class BoundNetLog;
19
20// Represents a single FTP transaction.
21class FtpTransaction {
22 public:
23  // Stops any pending IO and destroys the transaction object.
24  virtual ~FtpTransaction() {}
25
26  // Starts the FTP transaction (i.e., sends the FTP request).
27  //
28  // Returns OK if the transaction could be started synchronously, which means
29  // that the request was served from the cache (only supported for directory
30  // listings).  ERR_IO_PENDING is returned to indicate that the
31  // CompletionCallback will be notified once response info is available or if
32  // an IO error occurs.  Any other return value indicates that the transaction
33  // could not be started.
34  //
35  // Regardless of the return value, the caller is expected to keep the
36  // request_info object alive until Destroy is called on the transaction.
37  //
38  // NOTE: The transaction is not responsible for deleting the callback object.
39  //
40  // Profiling information for the request is saved to |net_log| if non-NULL.
41  virtual int Start(const FtpRequestInfo* request_info,
42                    CompletionCallback* callback,
43                    const BoundNetLog& net_log) = 0;
44
45  // Restarts the FTP transaction with authentication credentials.
46  virtual int RestartWithAuth(const string16& username,
47                              const string16& password,
48                              CompletionCallback* callback) = 0;
49
50  // Once response info is available for the transaction, response data may be
51  // read by calling this method.
52  //
53  // Response data is copied into the given buffer and the number of bytes
54  // copied is returned.  ERR_IO_PENDING is returned if response data is not
55  // yet available.  The CompletionCallback is notified when the data copy
56  // completes, and it is passed the number of bytes that were successfully
57  // copied.  Or, if a read error occurs, the CompletionCallback is notified of
58  // the error.  Any other negative return value indicates that the transaction
59  // could not be read.
60  //
61  // NOTE: The transaction is not responsible for deleting the callback object.
62  //
63  virtual int Read(IOBuffer* buf,
64                   int buf_len,
65                   CompletionCallback* callback) = 0;
66
67  // Returns the response info for this transaction or NULL if the response
68  // info is not available.
69  virtual const FtpResponseInfo* GetResponseInfo() const = 0;
70
71  // Returns the load state for this transaction.
72  virtual LoadState GetLoadState() const = 0;
73
74  // Returns the upload progress in bytes.  If there is no upload data,
75  // zero will be returned.
76  virtual uint64 GetUploadProgress() const = 0;
77};
78
79}  // namespace net
80
81#endif  // NET_FTP_FTP_TRANSACTION_H_
82