#include "components/drive/service/fake_drive_service.h"
#include <stddef.h>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/files/file_util.h"
#include "base/functional/bind.h"
#include "base/hash/md5.h"
#include "base/json/json_string_value_serializer.h"
#include "base/memory/ptr_util.h"
#include "base/not_fatal_until.h"
#include "base/notreached.h"
#include "base/strings/escape.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_tokenizer.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/thread_restrictions.h"
#include "base/values.h"
#include "components/drive/drive_api_util.h"
#include "components/drive/file_system_core_util.h"
#include "google_apis/common/test_util.h"
#include "google_apis/drive/drive_api_parser.h"
#include "google_apis/drive/drive_common_callbacks.h"
#include "net/base/url_util.h"
AboutResource;
AboutResourceCallback;
ApiErrorCode;
AuthStatusCallback;
CancelCallbackOnce;
ChangeList;
ChangeListCallback;
ChangeListOnceCallback;
ChangeResource;
DownloadActionCallback;
DRIVE_FILE_ERROR;
EntryActionCallback;
FileList;
FileListCallback;
FileResource;
FileResourceCallback;
GetContentCallback;
HTTP_BAD_REQUEST;
HTTP_CREATED;
HTTP_FORBIDDEN;
HTTP_NO_CONTENT;
HTTP_NOT_FOUND;
HTTP_PRECONDITION;
HTTP_RESUME_INCOMPLETE;
HTTP_SUCCESS;
InitiateUploadCallback;
NO_CONNECTION;
OTHER_ERROR;
ParentReference;
ProgressCallback;
StartPageToken;
TeamDriveList;
TeamDriveListCallback;
TeamDriveResource;
UploadRangeResponse;
UploadRangeCallback;
test_util;
namespace drive {
namespace {
bool EntryMatchWithQuery(const ChangeResource& entry,
const std::string& query) { … }
void ScheduleUploadRangeCallback(UploadRangeCallback callback,
int64_t start_position,
int64_t end_position,
ApiErrorCode error,
std::unique_ptr<FileResource> entry) { … }
void FileListCallbackAdapter(FileListCallback callback,
ApiErrorCode error,
std::unique_ptr<ChangeList> change_list) { … }
bool UserHasWriteAccess(google_apis::drive::PermissionRole user_permission) { … }
void CallFileResourceCallback(FileResourceCallback callback,
const UploadRangeResponse& response,
std::unique_ptr<FileResource> entry) { … }
struct CallResumeUpload { … };
std::string GetTeamDriveId(const google_apis::ChangeResource& change_resource) { … }
}
struct FakeDriveService::EntryInfo { … };
struct FakeDriveService::UploadSession { … };
FakeDriveService::FakeDriveService()
: … { … }
FakeDriveService::~FakeDriveService() { … }
void FakeDriveService::AddTeamDrive(const std::string& id,
const std::string& name) { … }
void FakeDriveService::AddTeamDrive(const std::string& id,
const std::string& name,
const std::string& start_page_token) { … }
void FakeDriveService::SetQuotaValue(int64_t used, int64_t total) { … }
void FakeDriveService::Initialize(const CoreAccountId& account_id) { … }
void FakeDriveService::AddObserver(DriveServiceObserver* observer) { … }
void FakeDriveService::RemoveObserver(DriveServiceObserver* observer) { … }
bool FakeDriveService::CanSendRequest() const { … }
bool FakeDriveService::HasAccessToken() const { … }
void FakeDriveService::RequestAccessToken(AuthStatusCallback callback) { … }
bool FakeDriveService::HasRefreshToken() const { … }
void FakeDriveService::ClearAccessToken() { … }
void FakeDriveService::ClearRefreshToken() { … }
std::string FakeDriveService::GetRootResourceId() const { … }
void FakeDriveService::GetTeamDriveListInternal(
int start_offset,
int max_results,
int* load_counter,
google_apis::TeamDriveListCallback callback) { … }
CancelCallbackOnce FakeDriveService::GetAllTeamDriveList(
TeamDriveListCallback callback) { … }
CancelCallbackOnce FakeDriveService::GetAllFileList(
const std::string& team_drive_id,
FileListCallback callback) { … }
CancelCallbackOnce FakeDriveService::GetFileListInDirectory(
const std::string& directory_resource_id,
FileListCallback callback) { … }
CancelCallbackOnce FakeDriveService::Search(const std::string& search_query,
FileListCallback callback) { … }
CancelCallbackOnce FakeDriveService::SearchByTitle(
const std::string& title,
const std::string& directory_resource_id,
FileListCallback callback) { … }
CancelCallbackOnce FakeDriveService::GetChangeList(
int64_t start_changestamp,
ChangeListCallback callback) { … }
CancelCallbackOnce FakeDriveService::GetChangeListByToken(
const std::string& team_drive_id,
const std::string& start_page_token,
ChangeListCallback callback) { … }
CancelCallbackOnce FakeDriveService::GetRemainingChangeList(
const GURL& next_link,
ChangeListCallback callback) { … }
CancelCallbackOnce FakeDriveService::GetRemainingTeamDriveList(
const std::string& page_token,
TeamDriveListCallback callback) { … }
CancelCallbackOnce FakeDriveService::GetRemainingFileList(
const GURL& next_link,
FileListCallback callback) { … }
CancelCallbackOnce FakeDriveService::GetFileResource(
const std::string& resource_id,
FileResourceCallback callback) { … }
CancelCallbackOnce FakeDriveService::GetAboutResource(
AboutResourceCallback callback) { … }
CancelCallbackOnce FakeDriveService::GetStartPageToken(
const std::string& team_drive_id,
google_apis::StartPageTokenCallback callback) { … }
CancelCallbackOnce FakeDriveService::DeleteResource(
const std::string& resource_id,
const std::string& etag,
EntryActionCallback callback) { … }
CancelCallbackOnce FakeDriveService::TrashResource(
const std::string& resource_id,
EntryActionCallback callback) { … }
CancelCallbackOnce FakeDriveService::DownloadFile(
const base::FilePath& local_cache_path,
const std::string& resource_id,
DownloadActionCallback download_action_callback,
const GetContentCallback& get_content_callback,
ProgressCallback progress_callback) { … }
CancelCallbackOnce FakeDriveService::CopyResource(
const std::string& resource_id,
const std::string& in_parent_resource_id,
const std::string& new_title,
const base::Time& last_modified,
FileResourceCallback callback) { … }
CancelCallbackOnce FakeDriveService::UpdateResource(
const std::string& resource_id,
const std::string& parent_resource_id,
const std::string& new_title,
const base::Time& last_modified,
const base::Time& last_viewed_by_me,
const google_apis::drive::Properties& properties,
FileResourceCallback callback) { … }
CancelCallbackOnce FakeDriveService::AddResourceToDirectory(
const std::string& parent_resource_id,
const std::string& resource_id,
EntryActionCallback callback) { … }
CancelCallbackOnce FakeDriveService::RemoveResourceFromDirectory(
const std::string& parent_resource_id,
const std::string& resource_id,
EntryActionCallback callback) { … }
CancelCallbackOnce FakeDriveService::AddNewDirectory(
const std::string& parent_resource_id,
const std::string& directory_title,
const AddNewDirectoryOptions& options,
FileResourceCallback callback) { … }
CancelCallbackOnce FakeDriveService::InitiateUploadNewFile(
const std::string& content_type,
int64_t content_length,
const std::string& parent_resource_id,
const std::string& title,
const UploadNewFileOptions& options,
InitiateUploadCallback callback) { … }
CancelCallbackOnce FakeDriveService::InitiateUploadExistingFile(
const std::string& content_type,
int64_t content_length,
const std::string& resource_id,
const UploadExistingFileOptions& options,
InitiateUploadCallback callback) { … }
CancelCallbackOnce FakeDriveService::GetUploadStatus(
const GURL& upload_url,
int64_t content_length,
UploadRangeCallback callback) { … }
CancelCallbackOnce FakeDriveService::ResumeUpload(
const GURL& upload_url,
int64_t start_position,
int64_t end_position,
int64_t content_length,
const std::string& content_type,
const base::FilePath& local_file_path,
UploadRangeCallback callback,
ProgressCallback progress_callback) { … }
CancelCallbackOnce FakeDriveService::MultipartUploadNewFile(
const std::string& content_type,
int64_t content_length,
const std::string& parent_resource_id,
const std::string& title,
const base::FilePath& local_file_path,
const UploadNewFileOptions& options,
FileResourceCallback callback,
ProgressCallback progress_callback) { … }
CancelCallbackOnce FakeDriveService::MultipartUploadExistingFile(
const std::string& content_type,
int64_t content_length,
const std::string& resource_id,
const base::FilePath& local_file_path,
const UploadExistingFileOptions& options,
FileResourceCallback callback,
ProgressCallback progress_callback) { … }
void FakeDriveService::AddNewFile(const std::string& content_type,
const std::string& content_data,
const std::string& parent_resource_id,
const std::string& title,
bool shared_with_me,
FileResourceCallback callback) { … }
void FakeDriveService::AddNewFileWithResourceId(
const std::string& resource_id,
const std::string& content_type,
const std::string& content_data,
const std::string& parent_resource_id,
const std::string& title,
bool shared_with_me,
FileResourceCallback callback) { … }
CancelCallbackOnce FakeDriveService::AddNewDirectoryWithResourceId(
const std::string& resource_id,
const std::string& parent_resource_id,
const std::string& directory_title,
const AddNewDirectoryOptions& options,
FileResourceCallback callback) { … }
void FakeDriveService::SetLastModifiedTime(const std::string& resource_id,
const base::Time& last_modified_time,
FileResourceCallback callback) { … }
void FakeDriveService::SetFileCapabilities(
const std::string& resource_id,
const google_apis::FileResourceCapabilities& capabilities,
FileResourceCallback callback) { … }
bool FakeDriveService::SetTeamDriveCapabilities(
const std::string& team_drive_id,
const google_apis::TeamDriveCapabilities& capabilities) { … }
google_apis::ApiErrorCode FakeDriveService::SetUserPermission(
const std::string& resource_id,
google_apis::drive::PermissionRole user_permission) { … }
google_apis::ApiErrorCode FakeDriveService::SetFileVisibility(
const std::string& resource_id,
google_apis::drive::FileVisibility visibility) { … }
google_apis::ApiErrorCode FakeDriveService::GetFileVisibility(
const std::string& resource_id,
google_apis::drive::FileVisibility* visibility) { … }
google_apis::ApiErrorCode FakeDriveService::SetFileAsSharedWithMe(
const std::string& resource_id) { … }
void FakeDriveService::AddChangeObserver(ChangeObserver* change_observer) { … }
void FakeDriveService::RemoveChangeObserver(ChangeObserver* change_observer) { … }
FakeDriveService::EntryInfo* FakeDriveService::FindEntryByResourceId(
const std::string& resource_id) { … }
std::string FakeDriveService::GetNewResourceId() { … }
void FakeDriveService::UpdateETag(google_apis::FileResource* file) { … }
void FakeDriveService::AddNewChangestamp(google_apis::ChangeResource* change,
const std::string& team_drive_id) { … }
const FakeDriveService::EntryInfo* FakeDriveService::AddNewEntry(
const std::string& given_resource_id,
const std::string& content_type,
const std::string& content_data,
const std::string& parent_resource_id,
const std::string& title,
bool shared_with_me) { … }
const FakeDriveService::EntryInfo* FakeDriveService::AddNewTeamDriveEntry(
const std::string& team_drive_id,
const std::string& team_drive_name) { … }
void FakeDriveService::GetChangeListInternal(
int64_t start_changestamp,
const std::string& search_query,
const std::string& directory_resource_id,
const std::string& team_drive_id,
int start_offset,
int max_results,
int* load_counter,
ChangeListOnceCallback callback) { … }
GURL FakeDriveService::GetNewUploadSessionUrl() { … }
CancelCallbackOnce FakeDriveService::AddPermission(
const std::string& resource_id,
const std::string& email,
google_apis::drive::PermissionRole role,
google_apis::EntryActionCallback callback) { … }
std::unique_ptr<BatchRequestConfiguratorInterface>
FakeDriveService::StartBatchRequest() { … }
void FakeDriveService::NotifyObservers() { … }
void FakeDriveService::UpdateLatestChangelistId(
int64_t change_list_id,
const std::string& team_drive_id) { … }
}