blob: 4940a037a98500f86af933de86d2247c871fb64d [file] [log] [blame]
[email protected]88e15d2e2013-02-15 10:53:471// Copyright (c) 2013 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
yawano3513e142016-04-20 00:42:425#ifndef COMPONENTS_DRIVE_CHROMEOS_FAKE_FILE_SYSTEM_H_
6#define COMPONENTS_DRIVE_CHROMEOS_FAKE_FILE_SYSTEM_H_
[email protected]88e15d2e2013-02-15 10:53:477
avibc5337b2015-12-25 23:16:338#include <stdint.h>
9
dchengf42750232016-04-12 04:12:2710#include <memory>
Stuart Langley664e2292018-08-31 04:58:2811#include <set>
[email protected]88e15d2e2013-02-15 10:53:4712#include <string>
13
[email protected]d7752262013-03-26 12:56:5914#include "base/callback_forward.h"
[email protected]7e8cd6e32013-04-22 08:01:0115#include "base/files/scoped_temp_dir.h"
avibc5337b2015-12-25 23:16:3316#include "base/macros.h"
yawano3513e142016-04-20 00:42:4217#include "components/drive/chromeos/file_system_interface.h"
lukasza76b4a982015-08-08 00:36:3918#include "components/drive/file_errors.h"
satorux1e04b422015-01-29 07:50:5319#include "google_apis/drive/drive_api_error_codes.h"
[email protected]88e15d2e2013-02-15 10:53:4720
21namespace google_apis {
22
[email protected]d7752262013-03-26 12:56:5923class AboutResource;
[email protected]31258442014-06-05 03:37:4124class FileResource;
[email protected]88e15d2e2013-02-15 10:53:4725
26} // namespace google_apis
27
28namespace drive {
29
[email protected]e50af7652013-06-20 06:39:3130class DriveServiceInterface;
[email protected]43309dd92013-04-25 07:28:0331class FileSystemObserver;
[email protected]67241b832013-05-02 04:55:5232class ResourceEntry;
[email protected]88e15d2e2013-02-15 10:53:4733
34namespace test_util {
35
[email protected]0d52ed52013-05-01 08:21:2136// This class implements a fake FileSystem which acts like a real Drive
[email protected]88e15d2e2013-02-15 10:53:4737// file system with FakeDriveService, for testing purpose.
38// Note that this class doesn't support "caching" at the moment, so the number
39// of interactions to the FakeDriveService may be bigger than the real
40// implementation.
41// Currently most methods are empty (not implemented).
[email protected]976309f12013-05-02 01:19:1542class FakeFileSystem : public FileSystemInterface {
[email protected]88e15d2e2013-02-15 10:53:4743 public:
[email protected]e50af7652013-06-20 06:39:3144 explicit FakeFileSystem(DriveServiceInterface* drive_service);
dchengfe773302015-01-22 19:45:5245 ~FakeFileSystem() override;
[email protected]88e15d2e2013-02-15 10:53:4746
[email protected]976309f12013-05-02 01:19:1547 // FileSystemInterface Overrides.
dchengfe773302015-01-22 19:45:5248 void AddObserver(FileSystemObserver* observer) override;
49 void RemoveObserver(FileSystemObserver* observer) override;
50 void CheckForUpdates() override;
Stuart Langley664e2292018-08-31 04:58:2851 void CheckForUpdates(const std::set<std::string>& ids) override;
dchengfe773302015-01-22 19:45:5252 void TransferFileFromLocalToRemote(
[email protected]88e15d2e2013-02-15 10:53:4753 const base::FilePath& local_src_file_path,
54 const base::FilePath& remote_dest_file_path,
mostynb9108efb92014-10-03 23:46:1555 const FileOperationCallback& callback) override;
dchengfe773302015-01-22 19:45:5256 void OpenFile(const base::FilePath& file_path,
57 OpenMode open_mode,
58 const std::string& mime_type,
Stuart Langley58871062018-08-28 05:10:5859 OpenFileCallback callback) override;
dchengfe773302015-01-22 19:45:5260 void Copy(const base::FilePath& src_file_path,
61 const base::FilePath& dest_file_path,
62 bool preserve_last_modified,
63 const FileOperationCallback& callback) override;
64 void Move(const base::FilePath& src_file_path,
65 const base::FilePath& dest_file_path,
66 const FileOperationCallback& callback) override;
67 void Remove(const base::FilePath& file_path,
68 bool is_recursive,
69 const FileOperationCallback& callback) override;
70 void CreateDirectory(const base::FilePath& directory_path,
71 bool is_exclusive,
72 bool is_recursive,
73 const FileOperationCallback& callback) override;
74 void CreateFile(const base::FilePath& file_path,
75 bool is_exclusive,
76 const std::string& mime_type,
77 const FileOperationCallback& callback) override;
78 void TouchFile(const base::FilePath& file_path,
79 const base::Time& last_access_time,
80 const base::Time& last_modified_time,
81 const FileOperationCallback& callback) override;
82 void TruncateFile(const base::FilePath& file_path,
avibc5337b2015-12-25 23:16:3383 int64_t length,
mostynb9108efb92014-10-03 23:46:1584 const FileOperationCallback& callback) override;
dchengfe773302015-01-22 19:45:5285 void Pin(const base::FilePath& file_path,
86 const FileOperationCallback& callback) override;
87 void Unpin(const base::FilePath& file_path,
88 const FileOperationCallback& callback) override;
89 void GetFile(const base::FilePath& file_path,
Stuart Langleybd8b7ee12018-08-27 01:24:4490 GetFileCallback callback) override;
dchengfe773302015-01-22 19:45:5291 void GetFileForSaving(const base::FilePath& file_path,
Stuart Langleybd8b7ee12018-08-27 01:24:4492 GetFileCallback callback) override;
dchengfe773302015-01-22 19:45:5293 base::Closure GetFileContent(
[email protected]8e6e51f82013-04-16 05:04:0094 const base::FilePath& file_path,
Stuart Langley48b51452018-08-28 01:17:1095 GetFileContentInitializedCallback initialized_callback,
[email protected]8e6e51f82013-04-16 05:04:0096 const google_apis::GetContentCallback& get_content_callback,
mostynb9108efb92014-10-03 23:46:1597 const FileOperationCallback& completion_callback) override;
dchengfe773302015-01-22 19:45:5298 void GetResourceEntry(const base::FilePath& file_path,
Stuart Langleyd3b602022018-08-27 04:24:5999 GetResourceEntryCallback callback) override;
dchengfe773302015-01-22 19:45:52100 void ReadDirectory(const base::FilePath& file_path,
Stuart Langley4819fdb2018-08-27 00:12:28101 ReadDirectoryEntriesCallback entries_callback,
dchengfe773302015-01-22 19:45:52102 const FileOperationCallback& completion_callback) override;
103 void Search(const std::string& search_query,
104 const GURL& next_link,
Stuart Langley6a4013c92018-08-28 01:27:14105 SearchCallback callback) override;
dchengfe773302015-01-22 19:45:52106 void SearchMetadata(const std::string& query,
107 int options,
108 int at_most_num_matches,
Shuhei Takahashi5459d1be2017-08-16 08:47:54109 MetadataSearchOrder order,
Stuart Langley6a4013c92018-08-28 01:27:14110 SearchMetadataCallback callback) override;
hirono87acdc62015-01-23 03:18:21111 void SearchByHashes(const std::set<std::string>& hashes,
Stuart Langley6a4013c92018-08-28 01:27:14112 SearchByHashesCallback callback) override;
Stuart Langley5f462182018-09-11 01:04:16113 void GetAvailableSpace(GetAvailableSpaceCallback callback) override;
Stuart Langley4819fdb2018-08-27 00:12:28114 void GetMetadata(GetFilesystemMetadataCallback callback) override;
dchengfe773302015-01-22 19:45:52115 void MarkCacheFileAsMounted(const base::FilePath& drive_file_path,
Stuart Langley503c3a2c2018-09-14 01:15:46116 MarkMountedCallback callback) override;
dchengfe773302015-01-22 19:45:52117 void MarkCacheFileAsUnmounted(const base::FilePath& cache_file_path,
118 const FileOperationCallback& callback) override;
Tatsuhisa Yamaguchi48101282018-03-20 02:18:39119 void IsCacheFileMarkedAsMounted(const base::FilePath& drive_file_path,
Stuart Langley503c3a2c2018-09-14 01:15:46120 IsMountedCallback callback) override;
dchengfe773302015-01-22 19:45:52121 void AddPermission(const base::FilePath& drive_file_path,
122 const std::string& email,
123 google_apis::drive::PermissionRole role,
124 const FileOperationCallback& callback) override;
mtomasz163271c2015-02-24 10:50:19125 void SetProperty(const base::FilePath& drive_file_path,
126 google_apis::drive::Property::Visibility visibility,
127 const std::string& key,
128 const std::string& value,
129 const FileOperationCallback& callback) override;
dchengfe773302015-01-22 19:45:52130 void Reset(const FileOperationCallback& callback) override;
131 void GetPathFromResourceId(const std::string& resource_id,
132 const GetFilePathCallback& callback) override;
avibc5337b2015-12-25 23:16:33133 void FreeDiskSpaceIfNeededFor(int64_t num_bytes,
hironod727d872015-02-17 09:32:51134 const FreeDiskSpaceCallback& callback) override;
fukino6380c07c2016-06-09 07:28:29135 void CalculateCacheSize(const CacheSizeCallback& callback) override;
136 void CalculateEvictableCacheSize(const CacheSizeCallback& callback) override;
[email protected]88e15d2e2013-02-15 10:53:47137
138 private:
[email protected]6297d0a2013-11-07 14:06:14139 // Helpers of GetFileContent.
[email protected]7e8cd6e32013-04-22 08:01:01140 // How the method works:
[email protected]67241b832013-05-02 04:55:52141 // 1) Gets ResourceEntry of the path.
[email protected]7e8cd6e32013-04-22 08:01:01142 // 2) Look at if there is a cache file or not. If found return it.
143 // 3) Otherwise start DownloadFile.
144 // 4) Runs the |completion_callback| upon the download completion.
[email protected]6297d0a2013-11-07 14:06:14145 void GetFileContentAfterGetResourceEntry(
Stuart Langley48b51452018-08-28 01:17:10146 GetFileContentInitializedCallback initialized_callback,
[email protected]7e8cd6e32013-04-22 08:01:01147 const google_apis::GetContentCallback& get_content_callback,
148 const FileOperationCallback& completion_callback,
[email protected]78a158b2013-04-23 06:57:49149 FileError error,
dchengf42750232016-04-12 04:12:27150 std::unique_ptr<ResourceEntry> entry);
[email protected]31258442014-06-05 03:37:41151 void GetFileContentAfterGetFileResource(
Stuart Langley48b51452018-08-28 01:17:10152 GetFileContentInitializedCallback initialized_callback,
[email protected]5b82c9d2013-05-10 03:06:27153 const google_apis::GetContentCallback& get_content_callback,
154 const FileOperationCallback& completion_callback,
satorux1e04b422015-01-29 07:50:53155 google_apis::DriveApiErrorCode gdata_error,
dchengf42750232016-04-12 04:12:27156 std::unique_ptr<google_apis::FileResource> gdata_entry);
[email protected]6297d0a2013-11-07 14:06:14157 void GetFileContentAfterDownloadFile(
[email protected]7e8cd6e32013-04-22 08:01:01158 const FileOperationCallback& completion_callback,
satorux1e04b422015-01-29 07:50:53159 google_apis::DriveApiErrorCode gdata_error,
[email protected]7e8cd6e32013-04-22 08:01:01160 const base::FilePath& temp_file);
161
[email protected]6297d0a2013-11-07 14:06:14162 // Helpers of GetResourceEntry.
[email protected]d14c29b2013-04-01 09:44:18163 // How the method works:
164 // 1) If the path is root, gets AboutResrouce from the drive service
[email protected]67241b832013-05-02 04:55:52165 // and create ResourceEntry.
166 // 2-1) Otherwise, gets the parent's ResourceEntry by recursive call.
[email protected]d14c29b2013-04-01 09:44:18167 // 2-2) Then, gets the resource list by restricting the parent with its id.
[email protected]67241b832013-05-02 04:55:52168 // 2-3) Search the results based on title, and return the ResourceEntry.
[email protected]d14c29b2013-04-01 09:44:18169 // Note that adding suffix (e.g. " (2)") for files sharing a same name is
[email protected]ec837782013-05-01 07:20:24170 // not supported in FakeFileSystem. Thus, even if the server has
[email protected]d14c29b2013-04-01 09:44:18171 // files sharing the same name under a directory, the second (or later)
172 // file cannot be taken with the suffixed name.
[email protected]6297d0a2013-11-07 14:06:14173 void GetResourceEntryAfterGetAboutResource(
Stuart Langleyd3b602022018-08-27 04:24:59174 GetResourceEntryCallback callback,
satorux1e04b422015-01-29 07:50:53175 google_apis::DriveApiErrorCode gdata_error,
dchengf42750232016-04-12 04:12:27176 std::unique_ptr<google_apis::AboutResource> about_resource);
[email protected]6297d0a2013-11-07 14:06:14177 void GetResourceEntryAfterGetParentEntryInfo(
[email protected]d14c29b2013-04-01 09:44:18178 const base::FilePath& base_name,
Stuart Langleyd3b602022018-08-27 04:24:59179 GetResourceEntryCallback callback,
[email protected]78a158b2013-04-23 06:57:49180 FileError error,
dchengf42750232016-04-12 04:12:27181 std::unique_ptr<ResourceEntry> parent_entry);
[email protected]2d3f7352014-06-02 05:51:54182 void GetResourceEntryAfterGetFileList(
[email protected]d14c29b2013-04-01 09:44:18183 const base::FilePath& base_name,
Stuart Langleyd3b602022018-08-27 04:24:59184 GetResourceEntryCallback callback,
satorux1e04b422015-01-29 07:50:53185 google_apis::DriveApiErrorCode gdata_error,
dchengf42750232016-04-12 04:12:27186 std::unique_ptr<google_apis::FileList> file_list);
[email protected]d14c29b2013-04-01 09:44:18187
[email protected]e50af7652013-06-20 06:39:31188 DriveServiceInterface* drive_service_; // Not owned.
[email protected]7e8cd6e32013-04-22 08:01:01189 base::ScopedTempDir cache_dir_;
[email protected]d7752262013-03-26 12:56:59190
191 // Note: This should remain the last member so it'll be destroyed and
192 // invalidate the weak pointers before any other members are destroyed.
Jeremy Roman47d432e2019-08-20 14:24:00193 base::WeakPtrFactory<FakeFileSystem> weak_ptr_factory_{this};
[email protected]d7752262013-03-26 12:56:59194
[email protected]ec837782013-05-01 07:20:24195 DISALLOW_COPY_AND_ASSIGN(FakeFileSystem);
[email protected]88e15d2e2013-02-15 10:53:47196};
197
198} // namespace test_util
199} // namespace drive
200
yawano3513e142016-04-20 00:42:42201#endif // COMPONENTS_DRIVE_CHROMEOS_FAKE_FILE_SYSTEM_H_