blob: 88d1aef24e7dd47d517001555abf6f46bea04b46 [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,
107 const SearchMetadataCallback& callback) override;
hirono87acdc62015-01-23 03:18:21108 void SearchByHashes(const std::set<std::string>& hashes,
dchengfe773302015-01-22 19:45:52109 const SearchByHashesCallback& callback) override;
110 void GetAvailableSpace(const GetAvailableSpaceCallback& callback) override;
111 void GetShareUrl(const base::FilePath& file_path,
112 const GURL& embed_origin,
113 const GetShareUrlCallback& callback) override;
114 void GetMetadata(const GetFilesystemMetadataCallback& callback) override;
115 void MarkCacheFileAsMounted(const base::FilePath& drive_file_path,
116 const MarkMountedCallback& callback) override;
117 void MarkCacheFileAsUnmounted(const base::FilePath& cache_file_path,
118 const FileOperationCallback& callback) override;
119 void AddPermission(const base::FilePath& drive_file_path,
120 const std::string& email,
121 google_apis::drive::PermissionRole role,
122 const FileOperationCallback& callback) override;
mtomasz163271c2015-02-24 10:50:19123 void SetProperty(const base::FilePath& drive_file_path,
124 google_apis::drive::Property::Visibility visibility,
125 const std::string& key,
126 const std::string& value,
127 const FileOperationCallback& callback) override;
dchengfe773302015-01-22 19:45:52128 void Reset(const FileOperationCallback& callback) override;
129 void GetPathFromResourceId(const std::string& resource_id,
130 const GetFilePathCallback& callback) override;
avibc5337b2015-12-25 23:16:33131 void FreeDiskSpaceIfNeededFor(int64_t num_bytes,
hironod727d872015-02-17 09:32:51132 const FreeDiskSpaceCallback& callback) override;
yawano8578abf2015-08-26 09:15:50133 void CalculateEvictableCacheSize(
134 const EvictableCacheSizeCallback& callback) override;
[email protected]88e15d2e2013-02-15 10:53:47135
136 private:
[email protected]6297d0a2013-11-07 14:06:14137 // Helpers of GetFileContent.
[email protected]7e8cd6e32013-04-22 08:01:01138 // How the method works:
[email protected]67241b832013-05-02 04:55:52139 // 1) Gets ResourceEntry of the path.
[email protected]7e8cd6e32013-04-22 08:01:01140 // 2) Look at if there is a cache file or not. If found return it.
141 // 3) Otherwise start DownloadFile.
142 // 4) Runs the |completion_callback| upon the download completion.
[email protected]6297d0a2013-11-07 14:06:14143 void GetFileContentAfterGetResourceEntry(
[email protected]7e8cd6e32013-04-22 08:01:01144 const GetFileContentInitializedCallback& initialized_callback,
145 const google_apis::GetContentCallback& get_content_callback,
146 const FileOperationCallback& completion_callback,
[email protected]78a158b2013-04-23 06:57:49147 FileError error,
dchengf42750232016-04-12 04:12:27148 std::unique_ptr<ResourceEntry> entry);
[email protected]31258442014-06-05 03:37:41149 void GetFileContentAfterGetFileResource(
[email protected]5b82c9d2013-05-10 03:06:27150 const GetFileContentInitializedCallback& initialized_callback,
151 const google_apis::GetContentCallback& get_content_callback,
152 const FileOperationCallback& completion_callback,
satorux1e04b422015-01-29 07:50:53153 google_apis::DriveApiErrorCode gdata_error,
dchengf42750232016-04-12 04:12:27154 std::unique_ptr<google_apis::FileResource> gdata_entry);
[email protected]6297d0a2013-11-07 14:06:14155 void GetFileContentAfterDownloadFile(
[email protected]7e8cd6e32013-04-22 08:01:01156 const FileOperationCallback& completion_callback,
satorux1e04b422015-01-29 07:50:53157 google_apis::DriveApiErrorCode gdata_error,
[email protected]7e8cd6e32013-04-22 08:01:01158 const base::FilePath& temp_file);
159
[email protected]6297d0a2013-11-07 14:06:14160 // Helpers of GetResourceEntry.
[email protected]d14c29b2013-04-01 09:44:18161 // How the method works:
162 // 1) If the path is root, gets AboutResrouce from the drive service
[email protected]67241b832013-05-02 04:55:52163 // and create ResourceEntry.
164 // 2-1) Otherwise, gets the parent's ResourceEntry by recursive call.
[email protected]d14c29b2013-04-01 09:44:18165 // 2-2) Then, gets the resource list by restricting the parent with its id.
[email protected]67241b832013-05-02 04:55:52166 // 2-3) Search the results based on title, and return the ResourceEntry.
[email protected]d14c29b2013-04-01 09:44:18167 // Note that adding suffix (e.g. " (2)") for files sharing a same name is
[email protected]ec837782013-05-01 07:20:24168 // not supported in FakeFileSystem. Thus, even if the server has
[email protected]d14c29b2013-04-01 09:44:18169 // files sharing the same name under a directory, the second (or later)
170 // file cannot be taken with the suffixed name.
[email protected]6297d0a2013-11-07 14:06:14171 void GetResourceEntryAfterGetAboutResource(
[email protected]0e196712013-05-14 05:26:17172 const GetResourceEntryCallback& callback,
satorux1e04b422015-01-29 07:50:53173 google_apis::DriveApiErrorCode gdata_error,
dchengf42750232016-04-12 04:12:27174 std::unique_ptr<google_apis::AboutResource> about_resource);
[email protected]6297d0a2013-11-07 14:06:14175 void GetResourceEntryAfterGetParentEntryInfo(
[email protected]d14c29b2013-04-01 09:44:18176 const base::FilePath& base_name,
[email protected]0e196712013-05-14 05:26:17177 const GetResourceEntryCallback& callback,
[email protected]78a158b2013-04-23 06:57:49178 FileError error,
dchengf42750232016-04-12 04:12:27179 std::unique_ptr<ResourceEntry> parent_entry);
[email protected]2d3f7352014-06-02 05:51:54180 void GetResourceEntryAfterGetFileList(
[email protected]d14c29b2013-04-01 09:44:18181 const base::FilePath& base_name,
[email protected]0e196712013-05-14 05:26:17182 const GetResourceEntryCallback& callback,
satorux1e04b422015-01-29 07:50:53183 google_apis::DriveApiErrorCode gdata_error,
dchengf42750232016-04-12 04:12:27184 std::unique_ptr<google_apis::FileList> file_list);
[email protected]d14c29b2013-04-01 09:44:18185
[email protected]e50af7652013-06-20 06:39:31186 DriveServiceInterface* drive_service_; // Not owned.
[email protected]7e8cd6e32013-04-22 08:01:01187 base::ScopedTempDir cache_dir_;
[email protected]d7752262013-03-26 12:56:59188
189 // Note: This should remain the last member so it'll be destroyed and
190 // invalidate the weak pointers before any other members are destroyed.
[email protected]ec837782013-05-01 07:20:24191 base::WeakPtrFactory<FakeFileSystem> weak_ptr_factory_;
[email protected]d7752262013-03-26 12:56:59192
[email protected]ec837782013-05-01 07:20:24193 DISALLOW_COPY_AND_ASSIGN(FakeFileSystem);
[email protected]88e15d2e2013-02-15 10:53:47194};
195
196} // namespace test_util
197} // namespace drive
198
yawano3513e142016-04-20 00:42:42199#endif // COMPONENTS_DRIVE_CHROMEOS_FAKE_FILE_SYSTEM_H_