blob: 328a99dd4dd8b45de1b9a45692e0abefe149ab88 [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;
dchengfe773302015-01-22 19:45:52113 void GetAvailableSpace(const GetAvailableSpaceCallback& callback) override;
114 void GetShareUrl(const base::FilePath& file_path,
115 const GURL& embed_origin,
116 const GetShareUrlCallback& callback) override;
Stuart Langley4819fdb2018-08-27 00:12:28117 void GetMetadata(GetFilesystemMetadataCallback callback) override;
dchengfe773302015-01-22 19:45:52118 void MarkCacheFileAsMounted(const base::FilePath& drive_file_path,
119 const MarkMountedCallback& callback) override;
120 void MarkCacheFileAsUnmounted(const base::FilePath& cache_file_path,
121 const FileOperationCallback& callback) override;
Tatsuhisa Yamaguchi48101282018-03-20 02:18:39122 void IsCacheFileMarkedAsMounted(const base::FilePath& drive_file_path,
123 const IsMountedCallback& callback) override;
dchengfe773302015-01-22 19:45:52124 void AddPermission(const base::FilePath& drive_file_path,
125 const std::string& email,
126 google_apis::drive::PermissionRole role,
127 const FileOperationCallback& callback) override;
mtomasz163271c2015-02-24 10:50:19128 void SetProperty(const base::FilePath& drive_file_path,
129 google_apis::drive::Property::Visibility visibility,
130 const std::string& key,
131 const std::string& value,
132 const FileOperationCallback& callback) override;
dchengfe773302015-01-22 19:45:52133 void Reset(const FileOperationCallback& callback) override;
134 void GetPathFromResourceId(const std::string& resource_id,
135 const GetFilePathCallback& callback) override;
avibc5337b2015-12-25 23:16:33136 void FreeDiskSpaceIfNeededFor(int64_t num_bytes,
hironod727d872015-02-17 09:32:51137 const FreeDiskSpaceCallback& callback) override;
fukino6380c07c2016-06-09 07:28:29138 void CalculateCacheSize(const CacheSizeCallback& callback) override;
139 void CalculateEvictableCacheSize(const CacheSizeCallback& callback) override;
[email protected]88e15d2e2013-02-15 10:53:47140
141 private:
[email protected]6297d0a2013-11-07 14:06:14142 // Helpers of GetFileContent.
[email protected]7e8cd6e32013-04-22 08:01:01143 // How the method works:
[email protected]67241b832013-05-02 04:55:52144 // 1) Gets ResourceEntry of the path.
[email protected]7e8cd6e32013-04-22 08:01:01145 // 2) Look at if there is a cache file or not. If found return it.
146 // 3) Otherwise start DownloadFile.
147 // 4) Runs the |completion_callback| upon the download completion.
[email protected]6297d0a2013-11-07 14:06:14148 void GetFileContentAfterGetResourceEntry(
Stuart Langley48b51452018-08-28 01:17:10149 GetFileContentInitializedCallback initialized_callback,
[email protected]7e8cd6e32013-04-22 08:01:01150 const google_apis::GetContentCallback& get_content_callback,
151 const FileOperationCallback& completion_callback,
[email protected]78a158b2013-04-23 06:57:49152 FileError error,
dchengf42750232016-04-12 04:12:27153 std::unique_ptr<ResourceEntry> entry);
[email protected]31258442014-06-05 03:37:41154 void GetFileContentAfterGetFileResource(
Stuart Langley48b51452018-08-28 01:17:10155 GetFileContentInitializedCallback initialized_callback,
[email protected]5b82c9d2013-05-10 03:06:27156 const google_apis::GetContentCallback& get_content_callback,
157 const FileOperationCallback& completion_callback,
satorux1e04b422015-01-29 07:50:53158 google_apis::DriveApiErrorCode gdata_error,
dchengf42750232016-04-12 04:12:27159 std::unique_ptr<google_apis::FileResource> gdata_entry);
[email protected]6297d0a2013-11-07 14:06:14160 void GetFileContentAfterDownloadFile(
[email protected]7e8cd6e32013-04-22 08:01:01161 const FileOperationCallback& completion_callback,
satorux1e04b422015-01-29 07:50:53162 google_apis::DriveApiErrorCode gdata_error,
[email protected]7e8cd6e32013-04-22 08:01:01163 const base::FilePath& temp_file);
164
[email protected]6297d0a2013-11-07 14:06:14165 // Helpers of GetResourceEntry.
[email protected]d14c29b2013-04-01 09:44:18166 // How the method works:
167 // 1) If the path is root, gets AboutResrouce from the drive service
[email protected]67241b832013-05-02 04:55:52168 // and create ResourceEntry.
169 // 2-1) Otherwise, gets the parent's ResourceEntry by recursive call.
[email protected]d14c29b2013-04-01 09:44:18170 // 2-2) Then, gets the resource list by restricting the parent with its id.
[email protected]67241b832013-05-02 04:55:52171 // 2-3) Search the results based on title, and return the ResourceEntry.
[email protected]d14c29b2013-04-01 09:44:18172 // Note that adding suffix (e.g. " (2)") for files sharing a same name is
[email protected]ec837782013-05-01 07:20:24173 // not supported in FakeFileSystem. Thus, even if the server has
[email protected]d14c29b2013-04-01 09:44:18174 // files sharing the same name under a directory, the second (or later)
175 // file cannot be taken with the suffixed name.
[email protected]6297d0a2013-11-07 14:06:14176 void GetResourceEntryAfterGetAboutResource(
Stuart Langleyd3b602022018-08-27 04:24:59177 GetResourceEntryCallback callback,
satorux1e04b422015-01-29 07:50:53178 google_apis::DriveApiErrorCode gdata_error,
dchengf42750232016-04-12 04:12:27179 std::unique_ptr<google_apis::AboutResource> about_resource);
[email protected]6297d0a2013-11-07 14:06:14180 void GetResourceEntryAfterGetParentEntryInfo(
[email protected]d14c29b2013-04-01 09:44:18181 const base::FilePath& base_name,
Stuart Langleyd3b602022018-08-27 04:24:59182 GetResourceEntryCallback callback,
[email protected]78a158b2013-04-23 06:57:49183 FileError error,
dchengf42750232016-04-12 04:12:27184 std::unique_ptr<ResourceEntry> parent_entry);
[email protected]2d3f7352014-06-02 05:51:54185 void GetResourceEntryAfterGetFileList(
[email protected]d14c29b2013-04-01 09:44:18186 const base::FilePath& base_name,
Stuart Langleyd3b602022018-08-27 04:24:59187 GetResourceEntryCallback callback,
satorux1e04b422015-01-29 07:50:53188 google_apis::DriveApiErrorCode gdata_error,
dchengf42750232016-04-12 04:12:27189 std::unique_ptr<google_apis::FileList> file_list);
[email protected]d14c29b2013-04-01 09:44:18190
[email protected]e50af7652013-06-20 06:39:31191 DriveServiceInterface* drive_service_; // Not owned.
[email protected]7e8cd6e32013-04-22 08:01:01192 base::ScopedTempDir cache_dir_;
[email protected]d7752262013-03-26 12:56:59193
194 // Note: This should remain the last member so it'll be destroyed and
195 // invalidate the weak pointers before any other members are destroyed.
[email protected]ec837782013-05-01 07:20:24196 base::WeakPtrFactory<FakeFileSystem> weak_ptr_factory_;
[email protected]d7752262013-03-26 12:56:59197
[email protected]ec837782013-05-01 07:20:24198 DISALLOW_COPY_AND_ASSIGN(FakeFileSystem);
[email protected]88e15d2e2013-02-15 10:53:47199};
200
201} // namespace test_util
202} // namespace drive
203
yawano3513e142016-04-20 00:42:42204#endif // COMPONENTS_DRIVE_CHROMEOS_FAKE_FILE_SYSTEM_H_