blob: e892bd9ac8e410b9a80bec2731b11e649caeb473 [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,
88 const GetFileCallback& callback) override;
89 void GetFileForSaving(const base::FilePath& file_path,
90 const GetFileCallback& callback) override;
91 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,
97 const GetResourceEntryCallback& callback) override;
98 void ReadDirectory(const base::FilePath& file_path,
99 const ReadDirectoryEntriesCallback& entries_callback,
100 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;
115 void GetMetadata(const GetFilesystemMetadataCallback& callback) override;
116 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;
120 void AddPermission(const base::FilePath& drive_file_path,
121 const std::string& email,
122 google_apis::drive::PermissionRole role,
123 const FileOperationCallback& callback) override;
mtomasz163271c2015-02-24 10:50:19124 void SetProperty(const base::FilePath& drive_file_path,
125 google_apis::drive::Property::Visibility visibility,
126 const std::string& key,
127 const std::string& value,
128 const FileOperationCallback& callback) override;
dchengfe773302015-01-22 19:45:52129 void Reset(const FileOperationCallback& callback) override;
130 void GetPathFromResourceId(const std::string& resource_id,
131 const GetFilePathCallback& callback) override;
avibc5337b2015-12-25 23:16:33132 void FreeDiskSpaceIfNeededFor(int64_t num_bytes,
hironod727d872015-02-17 09:32:51133 const FreeDiskSpaceCallback& callback) override;
fukino6380c07c2016-06-09 07:28:29134 void CalculateCacheSize(const CacheSizeCallback& callback) override;
135 void CalculateEvictableCacheSize(const CacheSizeCallback& callback) override;
[email protected]88e15d2e2013-02-15 10:53:47136
137 private:
[email protected]6297d0a2013-11-07 14:06:14138 // Helpers of GetFileContent.
[email protected]7e8cd6e32013-04-22 08:01:01139 // How the method works:
[email protected]67241b832013-05-02 04:55:52140 // 1) Gets ResourceEntry of the path.
[email protected]7e8cd6e32013-04-22 08:01:01141 // 2) Look at if there is a cache file or not. If found return it.
142 // 3) Otherwise start DownloadFile.
143 // 4) Runs the |completion_callback| upon the download completion.
[email protected]6297d0a2013-11-07 14:06:14144 void GetFileContentAfterGetResourceEntry(
[email protected]7e8cd6e32013-04-22 08:01:01145 const GetFileContentInitializedCallback& initialized_callback,
146 const google_apis::GetContentCallback& get_content_callback,
147 const FileOperationCallback& completion_callback,
[email protected]78a158b2013-04-23 06:57:49148 FileError error,
dchengf42750232016-04-12 04:12:27149 std::unique_ptr<ResourceEntry> entry);
[email protected]31258442014-06-05 03:37:41150 void GetFileContentAfterGetFileResource(
[email protected]5b82c9d2013-05-10 03:06:27151 const GetFileContentInitializedCallback& initialized_callback,
152 const google_apis::GetContentCallback& get_content_callback,
153 const FileOperationCallback& completion_callback,
satorux1e04b422015-01-29 07:50:53154 google_apis::DriveApiErrorCode gdata_error,
dchengf42750232016-04-12 04:12:27155 std::unique_ptr<google_apis::FileResource> gdata_entry);
[email protected]6297d0a2013-11-07 14:06:14156 void GetFileContentAfterDownloadFile(
[email protected]7e8cd6e32013-04-22 08:01:01157 const FileOperationCallback& completion_callback,
satorux1e04b422015-01-29 07:50:53158 google_apis::DriveApiErrorCode gdata_error,
[email protected]7e8cd6e32013-04-22 08:01:01159 const base::FilePath& temp_file);
160
[email protected]6297d0a2013-11-07 14:06:14161 // Helpers of GetResourceEntry.
[email protected]d14c29b2013-04-01 09:44:18162 // How the method works:
163 // 1) If the path is root, gets AboutResrouce from the drive service
[email protected]67241b832013-05-02 04:55:52164 // and create ResourceEntry.
165 // 2-1) Otherwise, gets the parent's ResourceEntry by recursive call.
[email protected]d14c29b2013-04-01 09:44:18166 // 2-2) Then, gets the resource list by restricting the parent with its id.
[email protected]67241b832013-05-02 04:55:52167 // 2-3) Search the results based on title, and return the ResourceEntry.
[email protected]d14c29b2013-04-01 09:44:18168 // Note that adding suffix (e.g. " (2)") for files sharing a same name is
[email protected]ec837782013-05-01 07:20:24169 // not supported in FakeFileSystem. Thus, even if the server has
[email protected]d14c29b2013-04-01 09:44:18170 // files sharing the same name under a directory, the second (or later)
171 // file cannot be taken with the suffixed name.
[email protected]6297d0a2013-11-07 14:06:14172 void GetResourceEntryAfterGetAboutResource(
[email protected]0e196712013-05-14 05:26:17173 const GetResourceEntryCallback& callback,
satorux1e04b422015-01-29 07:50:53174 google_apis::DriveApiErrorCode gdata_error,
dchengf42750232016-04-12 04:12:27175 std::unique_ptr<google_apis::AboutResource> about_resource);
[email protected]6297d0a2013-11-07 14:06:14176 void GetResourceEntryAfterGetParentEntryInfo(
[email protected]d14c29b2013-04-01 09:44:18177 const base::FilePath& base_name,
[email protected]0e196712013-05-14 05:26:17178 const GetResourceEntryCallback& callback,
[email protected]78a158b2013-04-23 06:57:49179 FileError error,
dchengf42750232016-04-12 04:12:27180 std::unique_ptr<ResourceEntry> parent_entry);
[email protected]2d3f7352014-06-02 05:51:54181 void GetResourceEntryAfterGetFileList(
[email protected]d14c29b2013-04-01 09:44:18182 const base::FilePath& base_name,
[email protected]0e196712013-05-14 05:26:17183 const GetResourceEntryCallback& callback,
satorux1e04b422015-01-29 07:50:53184 google_apis::DriveApiErrorCode gdata_error,
dchengf42750232016-04-12 04:12:27185 std::unique_ptr<google_apis::FileList> file_list);
[email protected]d14c29b2013-04-01 09:44:18186
[email protected]e50af7652013-06-20 06:39:31187 DriveServiceInterface* drive_service_; // Not owned.
[email protected]7e8cd6e32013-04-22 08:01:01188 base::ScopedTempDir cache_dir_;
[email protected]d7752262013-03-26 12:56:59189
190 // Note: This should remain the last member so it'll be destroyed and
191 // invalidate the weak pointers before any other members are destroyed.
[email protected]ec837782013-05-01 07:20:24192 base::WeakPtrFactory<FakeFileSystem> weak_ptr_factory_;
[email protected]d7752262013-03-26 12:56:59193
[email protected]ec837782013-05-01 07:20:24194 DISALLOW_COPY_AND_ASSIGN(FakeFileSystem);
[email protected]88e15d2e2013-02-15 10:53:47195};
196
197} // namespace test_util
198} // namespace drive
199
yawano3513e142016-04-20 00:42:42200#endif // COMPONENTS_DRIVE_CHROMEOS_FAKE_FILE_SYSTEM_H_