blob: f39b72ada89943e09c97c50060c1e7ff38a68a20 [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>
[email protected]88e15d2e2013-02-15 10:53:4711#include <string>
12
[email protected]d7752262013-03-26 12:56:5913#include "base/callback_forward.h"
[email protected]7e8cd6e32013-04-22 08:01:0114#include "base/files/scoped_temp_dir.h"
avibc5337b2015-12-25 23:16:3315#include "base/macros.h"
yawano3513e142016-04-20 00:42:4216#include "components/drive/chromeos/file_system_interface.h"
lukasza76b4a982015-08-08 00:36:3917#include "components/drive/file_errors.h"
satorux1e04b422015-01-29 07:50:5318#include "google_apis/drive/drive_api_error_codes.h"
[email protected]88e15d2e2013-02-15 10:53:4719
20namespace google_apis {
21
[email protected]d7752262013-03-26 12:56:5922class AboutResource;
[email protected]31258442014-06-05 03:37:4123class FileResource;
[email protected]88e15d2e2013-02-15 10:53:4724
25} // namespace google_apis
26
27namespace drive {
28
[email protected]e50af7652013-06-20 06:39:3129class DriveServiceInterface;
[email protected]43309dd92013-04-25 07:28:0330class FileSystemObserver;
[email protected]67241b832013-05-02 04:55:5231class ResourceEntry;
[email protected]88e15d2e2013-02-15 10:53:4732
33namespace test_util {
34
[email protected]0d52ed52013-05-01 08:21:2135// This class implements a fake FileSystem which acts like a real Drive
[email protected]88e15d2e2013-02-15 10:53:4736// file system with FakeDriveService, for testing purpose.
37// Note that this class doesn't support "caching" at the moment, so the number
38// of interactions to the FakeDriveService may be bigger than the real
39// implementation.
40// Currently most methods are empty (not implemented).
[email protected]976309f12013-05-02 01:19:1541class FakeFileSystem : public FileSystemInterface {
[email protected]88e15d2e2013-02-15 10:53:4742 public:
[email protected]e50af7652013-06-20 06:39:3143 explicit FakeFileSystem(DriveServiceInterface* drive_service);
dchengfe773302015-01-22 19:45:5244 ~FakeFileSystem() override;
[email protected]88e15d2e2013-02-15 10:53:4745
[email protected]976309f12013-05-02 01:19:1546 // FileSystemInterface Overrides.
dchengfe773302015-01-22 19:45:5247 void AddObserver(FileSystemObserver* observer) override;
48 void RemoveObserver(FileSystemObserver* observer) override;
49 void CheckForUpdates() override;
50 void TransferFileFromLocalToRemote(
[email protected]88e15d2e2013-02-15 10:53:4751 const base::FilePath& local_src_file_path,
52 const base::FilePath& remote_dest_file_path,
mostynb9108efb92014-10-03 23:46:1553 const FileOperationCallback& callback) override;
dchengfe773302015-01-22 19:45:5254 void OpenFile(const base::FilePath& file_path,
55 OpenMode open_mode,
56 const std::string& mime_type,
57 const OpenFileCallback& callback) override;
58 void Copy(const base::FilePath& src_file_path,
59 const base::FilePath& dest_file_path,
60 bool preserve_last_modified,
61 const FileOperationCallback& callback) override;
62 void Move(const base::FilePath& src_file_path,
63 const base::FilePath& dest_file_path,
64 const FileOperationCallback& callback) override;
65 void Remove(const base::FilePath& file_path,
66 bool is_recursive,
67 const FileOperationCallback& callback) override;
68 void CreateDirectory(const base::FilePath& directory_path,
69 bool is_exclusive,
70 bool is_recursive,
71 const FileOperationCallback& callback) override;
72 void CreateFile(const base::FilePath& file_path,
73 bool is_exclusive,
74 const std::string& mime_type,
75 const FileOperationCallback& callback) override;
76 void TouchFile(const base::FilePath& file_path,
77 const base::Time& last_access_time,
78 const base::Time& last_modified_time,
79 const FileOperationCallback& callback) override;
80 void TruncateFile(const base::FilePath& file_path,
avibc5337b2015-12-25 23:16:3381 int64_t length,
mostynb9108efb92014-10-03 23:46:1582 const FileOperationCallback& callback) override;
dchengfe773302015-01-22 19:45:5283 void Pin(const base::FilePath& file_path,
84 const FileOperationCallback& callback) override;
85 void Unpin(const base::FilePath& file_path,
86 const FileOperationCallback& callback) override;
87 void GetFile(const base::FilePath& file_path,
Stuart Langleybd8b7ee12018-08-27 01:24:4488 GetFileCallback callback) override;
dchengfe773302015-01-22 19:45:5289 void GetFileForSaving(const base::FilePath& file_path,
Stuart Langleybd8b7ee12018-08-27 01:24:4490 GetFileCallback callback) override;
dchengfe773302015-01-22 19:45:5291 base::Closure GetFileContent(
[email protected]8e6e51f82013-04-16 05:04:0092 const base::FilePath& file_path,
93 const GetFileContentInitializedCallback& initialized_callback,
94 const google_apis::GetContentCallback& get_content_callback,
mostynb9108efb92014-10-03 23:46:1595 const FileOperationCallback& completion_callback) override;
dchengfe773302015-01-22 19:45:5296 void GetResourceEntry(const base::FilePath& file_path,
Stuart Langleyd3b602022018-08-27 04:24:5997 GetResourceEntryCallback callback) override;
dchengfe773302015-01-22 19:45:5298 void ReadDirectory(const base::FilePath& file_path,
Stuart Langley4819fdb2018-08-27 00:12:2899 ReadDirectoryEntriesCallback entries_callback,
dchengfe773302015-01-22 19:45:52100 const FileOperationCallback& completion_callback) override;
101 void Search(const std::string& search_query,
102 const GURL& next_link,
103 const SearchCallback& callback) override;
104 void SearchMetadata(const std::string& query,
105 int options,
106 int at_most_num_matches,
Shuhei Takahashi5459d1be2017-08-16 08:47:54107 MetadataSearchOrder order,
dchengfe773302015-01-22 19:45:52108 const SearchMetadataCallback& callback) override;
hirono87acdc62015-01-23 03:18:21109 void SearchByHashes(const std::set<std::string>& hashes,
dchengfe773302015-01-22 19:45:52110 const SearchByHashesCallback& callback) override;
111 void GetAvailableSpace(const GetAvailableSpaceCallback& callback) override;
112 void GetShareUrl(const base::FilePath& file_path,
113 const GURL& embed_origin,
114 const GetShareUrlCallback& callback) override;
Stuart Langley4819fdb2018-08-27 00:12:28115 void GetMetadata(GetFilesystemMetadataCallback callback) override;
dchengfe773302015-01-22 19:45:52116 void MarkCacheFileAsMounted(const base::FilePath& drive_file_path,
117 const MarkMountedCallback& callback) override;
118 void MarkCacheFileAsUnmounted(const base::FilePath& cache_file_path,
119 const FileOperationCallback& callback) override;
Tatsuhisa Yamaguchi48101282018-03-20 02:18:39120 void IsCacheFileMarkedAsMounted(const base::FilePath& drive_file_path,
121 const IsMountedCallback& callback) override;
dchengfe773302015-01-22 19:45:52122 void AddPermission(const base::FilePath& drive_file_path,
123 const std::string& email,
124 google_apis::drive::PermissionRole role,
125 const FileOperationCallback& callback) override;
mtomasz163271c2015-02-24 10:50:19126 void SetProperty(const base::FilePath& drive_file_path,
127 google_apis::drive::Property::Visibility visibility,
128 const std::string& key,
129 const std::string& value,
130 const FileOperationCallback& callback) override;
dchengfe773302015-01-22 19:45:52131 void Reset(const FileOperationCallback& callback) override;
132 void GetPathFromResourceId(const std::string& resource_id,
133 const GetFilePathCallback& callback) override;
avibc5337b2015-12-25 23:16:33134 void FreeDiskSpaceIfNeededFor(int64_t num_bytes,
hironod727d872015-02-17 09:32:51135 const FreeDiskSpaceCallback& callback) override;
fukino6380c07c2016-06-09 07:28:29136 void CalculateCacheSize(const CacheSizeCallback& callback) override;
137 void CalculateEvictableCacheSize(const CacheSizeCallback& callback) override;
[email protected]88e15d2e2013-02-15 10:53:47138
139 private:
[email protected]6297d0a2013-11-07 14:06:14140 // Helpers of GetFileContent.
[email protected]7e8cd6e32013-04-22 08:01:01141 // How the method works:
[email protected]67241b832013-05-02 04:55:52142 // 1) Gets ResourceEntry of the path.
[email protected]7e8cd6e32013-04-22 08:01:01143 // 2) Look at if there is a cache file or not. If found return it.
144 // 3) Otherwise start DownloadFile.
145 // 4) Runs the |completion_callback| upon the download completion.
[email protected]6297d0a2013-11-07 14:06:14146 void GetFileContentAfterGetResourceEntry(
[email protected]7e8cd6e32013-04-22 08:01:01147 const GetFileContentInitializedCallback& initialized_callback,
148 const google_apis::GetContentCallback& get_content_callback,
149 const FileOperationCallback& completion_callback,
[email protected]78a158b2013-04-23 06:57:49150 FileError error,
dchengf42750232016-04-12 04:12:27151 std::unique_ptr<ResourceEntry> entry);
[email protected]31258442014-06-05 03:37:41152 void GetFileContentAfterGetFileResource(
[email protected]5b82c9d2013-05-10 03:06:27153 const GetFileContentInitializedCallback& initialized_callback,
154 const google_apis::GetContentCallback& get_content_callback,
155 const FileOperationCallback& completion_callback,
satorux1e04b422015-01-29 07:50:53156 google_apis::DriveApiErrorCode gdata_error,
dchengf42750232016-04-12 04:12:27157 std::unique_ptr<google_apis::FileResource> gdata_entry);
[email protected]6297d0a2013-11-07 14:06:14158 void GetFileContentAfterDownloadFile(
[email protected]7e8cd6e32013-04-22 08:01:01159 const FileOperationCallback& completion_callback,
satorux1e04b422015-01-29 07:50:53160 google_apis::DriveApiErrorCode gdata_error,
[email protected]7e8cd6e32013-04-22 08:01:01161 const base::FilePath& temp_file);
162
[email protected]6297d0a2013-11-07 14:06:14163 // Helpers of GetResourceEntry.
[email protected]d14c29b2013-04-01 09:44:18164 // How the method works:
165 // 1) If the path is root, gets AboutResrouce from the drive service
[email protected]67241b832013-05-02 04:55:52166 // and create ResourceEntry.
167 // 2-1) Otherwise, gets the parent's ResourceEntry by recursive call.
[email protected]d14c29b2013-04-01 09:44:18168 // 2-2) Then, gets the resource list by restricting the parent with its id.
[email protected]67241b832013-05-02 04:55:52169 // 2-3) Search the results based on title, and return the ResourceEntry.
[email protected]d14c29b2013-04-01 09:44:18170 // Note that adding suffix (e.g. " (2)") for files sharing a same name is
[email protected]ec837782013-05-01 07:20:24171 // not supported in FakeFileSystem. Thus, even if the server has
[email protected]d14c29b2013-04-01 09:44:18172 // files sharing the same name under a directory, the second (or later)
173 // file cannot be taken with the suffixed name.
[email protected]6297d0a2013-11-07 14:06:14174 void GetResourceEntryAfterGetAboutResource(
Stuart Langleyd3b602022018-08-27 04:24:59175 GetResourceEntryCallback callback,
satorux1e04b422015-01-29 07:50:53176 google_apis::DriveApiErrorCode gdata_error,
dchengf42750232016-04-12 04:12:27177 std::unique_ptr<google_apis::AboutResource> about_resource);
[email protected]6297d0a2013-11-07 14:06:14178 void GetResourceEntryAfterGetParentEntryInfo(
[email protected]d14c29b2013-04-01 09:44:18179 const base::FilePath& base_name,
Stuart Langleyd3b602022018-08-27 04:24:59180 GetResourceEntryCallback callback,
[email protected]78a158b2013-04-23 06:57:49181 FileError error,
dchengf42750232016-04-12 04:12:27182 std::unique_ptr<ResourceEntry> parent_entry);
[email protected]2d3f7352014-06-02 05:51:54183 void GetResourceEntryAfterGetFileList(
[email protected]d14c29b2013-04-01 09:44:18184 const base::FilePath& base_name,
Stuart Langleyd3b602022018-08-27 04:24:59185 GetResourceEntryCallback callback,
satorux1e04b422015-01-29 07:50:53186 google_apis::DriveApiErrorCode gdata_error,
dchengf42750232016-04-12 04:12:27187 std::unique_ptr<google_apis::FileList> file_list);
[email protected]d14c29b2013-04-01 09:44:18188
[email protected]e50af7652013-06-20 06:39:31189 DriveServiceInterface* drive_service_; // Not owned.
[email protected]7e8cd6e32013-04-22 08:01:01190 base::ScopedTempDir cache_dir_;
[email protected]d7752262013-03-26 12:56:59191
192 // Note: This should remain the last member so it'll be destroyed and
193 // invalidate the weak pointers before any other members are destroyed.
[email protected]ec837782013-05-01 07:20:24194 base::WeakPtrFactory<FakeFileSystem> weak_ptr_factory_;
[email protected]d7752262013-03-26 12:56:59195
[email protected]ec837782013-05-01 07:20:24196 DISALLOW_COPY_AND_ASSIGN(FakeFileSystem);
[email protected]88e15d2e2013-02-15 10:53:47197};
198
199} // namespace test_util
200} // namespace drive
201
yawano3513e142016-04-20 00:42:42202#endif // COMPONENTS_DRIVE_CHROMEOS_FAKE_FILE_SYSTEM_H_