#include "components/drive/drive_uploader.h"
#include <algorithm>
#include <memory>
#include <utility>
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/string_number_conversions.h"
#include "components/drive/service/drive_service_interface.h"
#include "google_apis/drive/drive_api_parser.h"
#include "services/device/public/mojom/wake_lock.mojom.h"
ApiErrorCode;
CancelCallbackOnce;
CANCELLED;
DRIVE_NO_SPACE;
FileResource;
HTTP_CONFLICT;
HTTP_CREATED;
HTTP_FORBIDDEN;
HTTP_NOT_FOUND;
HTTP_PRECONDITION;
HTTP_RESUME_INCOMPLETE;
HTTP_SUCCESS;
ProgressCallback;
UploadRangeResponse;
namespace drive {
namespace {
const int64_t kUploadChunkSize = …;
const int64_t kMaxMultipartUploadSize = …;
enum DriveUploadProtocol { … };
void RecordDriveUploadProtocol(DriveUploadProtocol protocol) { … }
}
class DriveUploader::RefCountedBatchRequest
: public base::RefCounted<RefCountedBatchRequest> { … };
struct DriveUploader::UploadFileInfo { … };
DriveUploader::DriveUploader(
DriveServiceInterface* drive_service,
const scoped_refptr<base::TaskRunner>& blocking_task_runner,
mojo::PendingRemote<device::mojom::WakeLockProvider> wake_lock_provider)
: … { … }
DriveUploader::~DriveUploader() = default;
CancelCallbackOnce DriveUploader::UploadNewFile(
const std::string& parent_resource_id,
const base::FilePath& local_file_path,
const std::string& title,
const std::string& content_type,
const UploadNewFileOptions& options,
UploadCompletionCallback callback,
ProgressCallback progress_callback) { … }
void DriveUploader::StartBatchProcessing() { … }
void DriveUploader::StopBatchProcessing() { … }
CancelCallbackOnce DriveUploader::UploadExistingFile(
const std::string& resource_id,
const base::FilePath& local_file_path,
const std::string& content_type,
const UploadExistingFileOptions& options,
UploadCompletionCallback callback,
ProgressCallback progress_callback) { … }
CancelCallbackOnce DriveUploader::ResumeUploadFile(
const GURL& upload_location,
const base::FilePath& local_file_path,
const std::string& content_type,
UploadCompletionCallback callback,
ProgressCallback progress_callback) { … }
CancelCallbackOnce DriveUploader::StartUploadFile(
std::unique_ptr<UploadFileInfo> upload_file_info,
StartInitiateUploadCallback start_initiate_upload_callback) { … }
void DriveUploader::StartUploadFileAfterGetFileSize(
std::unique_ptr<UploadFileInfo> upload_file_info,
StartInitiateUploadCallback start_initiate_upload_callback,
bool get_file_size_result) { … }
void DriveUploader::CallUploadServiceAPINewFile(
const std::string& parent_resource_id,
const std::string& title,
const UploadNewFileOptions& options,
const scoped_refptr<RefCountedBatchRequest>& batch_request,
std::unique_ptr<UploadFileInfo> upload_file_info) { … }
void DriveUploader::CallUploadServiceAPIExistingFile(
const std::string& resource_id,
const UploadExistingFileOptions& options,
const scoped_refptr<RefCountedBatchRequest>& batch_request,
std::unique_ptr<UploadFileInfo> upload_file_info) { … }
void DriveUploader::OnUploadLocationReceived(
std::unique_ptr<UploadFileInfo> upload_file_info,
ApiErrorCode code,
const GURL& upload_location) { … }
void DriveUploader::StartGetUploadStatus(
std::unique_ptr<UploadFileInfo> upload_file_info) { … }
void DriveUploader::UploadNextChunk(
std::unique_ptr<UploadFileInfo> upload_file_info) { … }
void DriveUploader::OnUploadRangeResponseReceived(
std::unique_ptr<UploadFileInfo> upload_file_info,
const UploadRangeResponse& response,
std::unique_ptr<FileResource> entry) { … }
void DriveUploader::OnUploadProgress(ProgressCallback callback,
int64_t start_position,
int64_t total_size,
int64_t progress_of_chunk,
int64_t total_of_chunk) { … }
void DriveUploader::UploadFailed(
std::unique_ptr<UploadFileInfo> upload_file_info,
ApiErrorCode error) { … }
void DriveUploader::OnMultipartUploadComplete(
std::unique_ptr<UploadFileInfo> upload_file_info,
google_apis::ApiErrorCode error,
std::unique_ptr<FileResource> entry) { … }
device::mojom::WakeLockProvider* DriveUploader::GetWakeLockProvider() { … }
}