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