[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 1 | // 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 | |
[email protected] | ec83778 | 2013-05-01 07:20:24 | [diff] [blame] | 5 | #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FAKE_FILE_SYSTEM_H_ |
| 6 | #define CHROME_BROWSER_CHROMEOS_DRIVE_FAKE_FILE_SYSTEM_H_ |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/basictypes.h" |
[email protected] | d775226 | 2013-03-26 12:56:59 | [diff] [blame] | 11 | #include "base/callback_forward.h" |
[email protected] | 7e8cd6e3 | 2013-04-22 08:01:01 | [diff] [blame] | 12 | #include "base/files/scoped_temp_dir.h" |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 13 | #include "base/memory/scoped_ptr.h" |
[email protected] | 78a158b | 2013-04-23 06:57:49 | [diff] [blame] | 14 | #include "chrome/browser/chromeos/drive/file_errors.h" |
[email protected] | 976309f1 | 2013-05-02 01:19:15 | [diff] [blame] | 15 | #include "chrome/browser/chromeos/drive/file_system_interface.h" |
[email protected] | e196bef3 | 2013-12-03 05:33:13 | [diff] [blame] | 16 | #include "google_apis/drive/gdata_errorcode.h" |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 17 | |
| 18 | namespace google_apis { |
| 19 | |
[email protected] | d775226 | 2013-03-26 12:56:59 | [diff] [blame] | 20 | class AboutResource; |
[email protected] | 3125844 | 2014-06-05 03:37:41 | [diff] [blame] | 21 | class FileResource; |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 22 | |
| 23 | } // namespace google_apis |
| 24 | |
| 25 | namespace drive { |
| 26 | |
[email protected] | e50af765 | 2013-06-20 06:39:31 | [diff] [blame] | 27 | class DriveServiceInterface; |
[email protected] | 43309dd9 | 2013-04-25 07:28:03 | [diff] [blame] | 28 | class FileSystemObserver; |
[email protected] | 67241b83 | 2013-05-02 04:55:52 | [diff] [blame] | 29 | class ResourceEntry; |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 30 | |
| 31 | namespace test_util { |
| 32 | |
[email protected] | 0d52ed5 | 2013-05-01 08:21:21 | [diff] [blame] | 33 | // This class implements a fake FileSystem which acts like a real Drive |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 34 | // file system with FakeDriveService, for testing purpose. |
| 35 | // Note that this class doesn't support "caching" at the moment, so the number |
| 36 | // of interactions to the FakeDriveService may be bigger than the real |
| 37 | // implementation. |
| 38 | // Currently most methods are empty (not implemented). |
[email protected] | 976309f1 | 2013-05-02 01:19:15 | [diff] [blame] | 39 | class FakeFileSystem : public FileSystemInterface { |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 40 | public: |
[email protected] | e50af765 | 2013-06-20 06:39:31 | [diff] [blame] | 41 | explicit FakeFileSystem(DriveServiceInterface* drive_service); |
[email protected] | ec83778 | 2013-05-01 07:20:24 | [diff] [blame] | 42 | virtual ~FakeFileSystem(); |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 43 | |
[email protected] | 976309f1 | 2013-05-02 01:19:15 | [diff] [blame] | 44 | // FileSystemInterface Overrides. |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 45 | virtual void AddObserver(FileSystemObserver* observer) override; |
| 46 | virtual void RemoveObserver(FileSystemObserver* observer) override; |
| 47 | virtual void CheckForUpdates() override; |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 48 | virtual void TransferFileFromLocalToRemote( |
| 49 | const base::FilePath& local_src_file_path, |
| 50 | const base::FilePath& remote_dest_file_path, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 51 | const FileOperationCallback& callback) override; |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 52 | virtual void OpenFile(const base::FilePath& file_path, |
[email protected] | 6966445f | 2013-07-11 09:33:59 | [diff] [blame] | 53 | OpenMode open_mode, |
[email protected] | b570b7b | 2013-08-21 14:59:36 | [diff] [blame] | 54 | const std::string& mime_type, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 55 | const OpenFileCallback& callback) override; |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 56 | virtual void Copy(const base::FilePath& src_file_path, |
| 57 | const base::FilePath& dest_file_path, |
[email protected] | 1f4696c | 2013-09-25 08:08:18 | [diff] [blame] | 58 | bool preserve_last_modified, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 59 | const FileOperationCallback& callback) override; |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 60 | virtual void Move(const base::FilePath& src_file_path, |
| 61 | const base::FilePath& dest_file_path, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 62 | const FileOperationCallback& callback) override; |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 63 | virtual void Remove(const base::FilePath& file_path, |
| 64 | bool is_recursive, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 65 | const FileOperationCallback& callback) override; |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 66 | virtual void CreateDirectory(const base::FilePath& directory_path, |
| 67 | bool is_exclusive, |
| 68 | bool is_recursive, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 69 | const FileOperationCallback& callback) override; |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 70 | virtual void CreateFile(const base::FilePath& file_path, |
| 71 | bool is_exclusive, |
[email protected] | b570b7b | 2013-08-21 14:59:36 | [diff] [blame] | 72 | const std::string& mime_type, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 73 | const FileOperationCallback& callback) override; |
[email protected] | 8c2476c2 | 2013-05-22 17:50:10 | [diff] [blame] | 74 | virtual void TouchFile(const base::FilePath& file_path, |
| 75 | const base::Time& last_access_time, |
| 76 | const base::Time& last_modified_time, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 77 | const FileOperationCallback& callback) override; |
[email protected] | 33539ec | 2013-07-01 11:02:10 | [diff] [blame] | 78 | virtual void TruncateFile(const base::FilePath& file_path, |
| 79 | int64 length, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 80 | const FileOperationCallback& callback) override; |
[email protected] | 378b613 | 2013-04-19 18:05:18 | [diff] [blame] | 81 | virtual void Pin(const base::FilePath& file_path, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 82 | const FileOperationCallback& callback) override; |
[email protected] | 378b613 | 2013-04-19 18:05:18 | [diff] [blame] | 83 | virtual void Unpin(const base::FilePath& file_path, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 84 | const FileOperationCallback& callback) override; |
[email protected] | 6297d0a | 2013-11-07 14:06:14 | [diff] [blame] | 85 | virtual void GetFile(const base::FilePath& file_path, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 86 | const GetFileCallback& callback) override; |
[email protected] | 6297d0a | 2013-11-07 14:06:14 | [diff] [blame] | 87 | virtual void GetFileForSaving(const base::FilePath& file_path, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 88 | const GetFileCallback& callback) override; |
[email protected] | 0167ff0 | 2014-03-28 17:22:23 | [diff] [blame] | 89 | virtual base::Closure GetFileContent( |
[email protected] | 8e6e51f8 | 2013-04-16 05:04:00 | [diff] [blame] | 90 | const base::FilePath& file_path, |
| 91 | const GetFileContentInitializedCallback& initialized_callback, |
| 92 | const google_apis::GetContentCallback& get_content_callback, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 93 | const FileOperationCallback& completion_callback) override; |
[email protected] | 6297d0a | 2013-11-07 14:06:14 | [diff] [blame] | 94 | virtual void GetResourceEntry( |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 95 | const base::FilePath& file_path, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 96 | const GetResourceEntryCallback& callback) override; |
[email protected] | 6297d0a | 2013-11-07 14:06:14 | [diff] [blame] | 97 | virtual void ReadDirectory( |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 98 | const base::FilePath& file_path, |
[email protected] | f173c6d | 2014-04-14 10:49:50 | [diff] [blame] | 99 | const ReadDirectoryEntriesCallback& entries_callback, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 100 | const FileOperationCallback& completion_callback) override; |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 101 | virtual void Search(const std::string& search_query, |
[email protected] | b5f9818 | 2013-09-04 12:43:53 | [diff] [blame] | 102 | const GURL& next_link, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 103 | const SearchCallback& callback) override; |
[email protected] | 14b69c5 | 2013-03-27 09:48:47 | [diff] [blame] | 104 | virtual void SearchMetadata(const std::string& query, |
[email protected] | 48c884ca | 2013-04-09 12:40:01 | [diff] [blame] | 105 | int options, |
[email protected] | 14b69c5 | 2013-03-27 09:48:47 | [diff] [blame] | 106 | int at_most_num_matches, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 107 | const SearchMetadataCallback& callback) override; |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 108 | virtual void GetAvailableSpace( |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 109 | const GetAvailableSpaceCallback& callback) override; |
[email protected] | ac6260e | 2013-07-24 10:31:12 | [diff] [blame] | 110 | virtual void GetShareUrl( |
| 111 | const base::FilePath& file_path, |
[email protected] | 3144bbf | 2013-07-25 06:46:18 | [diff] [blame] | 112 | const GURL& embed_origin, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 113 | const GetShareUrlCallback& callback) override; |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 114 | virtual void GetMetadata( |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 115 | const GetFilesystemMetadataCallback& callback) override; |
[email protected] | 48348d5c | 2013-04-22 17:44:22 | [diff] [blame] | 116 | virtual void MarkCacheFileAsMounted( |
| 117 | const base::FilePath& drive_file_path, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 118 | const MarkMountedCallback& callback) override; |
[email protected] | 48348d5c | 2013-04-22 17:44:22 | [diff] [blame] | 119 | virtual void MarkCacheFileAsUnmounted( |
| 120 | const base::FilePath& cache_file_path, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 121 | const FileOperationCallback& callback) override; |
[email protected] | dd4a26f | 2014-03-20 14:25:32 | [diff] [blame] | 122 | virtual void AddPermission(const base::FilePath& drive_file_path, |
| 123 | const std::string& email, |
| 124 | google_apis::drive::PermissionRole role, |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 125 | const FileOperationCallback& callback) override; |
| 126 | virtual void Reset(const FileOperationCallback& callback) override; |
[email protected] | 87a1451 | 2014-03-24 12:34:03 | [diff] [blame] | 127 | virtual void GetPathFromResourceId(const std::string& resource_id, |
| 128 | const GetFilePathCallback& callback) |
mostynb | 9108efb9 | 2014-10-03 23:46:15 | [diff] [blame^] | 129 | override; |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 130 | |
| 131 | private: |
[email protected] | 6297d0a | 2013-11-07 14:06:14 | [diff] [blame] | 132 | // Helpers of GetFileContent. |
[email protected] | 7e8cd6e3 | 2013-04-22 08:01:01 | [diff] [blame] | 133 | // How the method works: |
[email protected] | 67241b83 | 2013-05-02 04:55:52 | [diff] [blame] | 134 | // 1) Gets ResourceEntry of the path. |
[email protected] | 7e8cd6e3 | 2013-04-22 08:01:01 | [diff] [blame] | 135 | // 2) Look at if there is a cache file or not. If found return it. |
| 136 | // 3) Otherwise start DownloadFile. |
| 137 | // 4) Runs the |completion_callback| upon the download completion. |
[email protected] | 6297d0a | 2013-11-07 14:06:14 | [diff] [blame] | 138 | void GetFileContentAfterGetResourceEntry( |
[email protected] | 7e8cd6e3 | 2013-04-22 08:01:01 | [diff] [blame] | 139 | const GetFileContentInitializedCallback& initialized_callback, |
| 140 | const google_apis::GetContentCallback& get_content_callback, |
| 141 | const FileOperationCallback& completion_callback, |
[email protected] | 78a158b | 2013-04-23 06:57:49 | [diff] [blame] | 142 | FileError error, |
[email protected] | 67241b83 | 2013-05-02 04:55:52 | [diff] [blame] | 143 | scoped_ptr<ResourceEntry> entry); |
[email protected] | 3125844 | 2014-06-05 03:37:41 | [diff] [blame] | 144 | void GetFileContentAfterGetFileResource( |
[email protected] | 5b82c9d | 2013-05-10 03:06:27 | [diff] [blame] | 145 | const GetFileContentInitializedCallback& initialized_callback, |
| 146 | const google_apis::GetContentCallback& get_content_callback, |
| 147 | const FileOperationCallback& completion_callback, |
| 148 | google_apis::GDataErrorCode gdata_error, |
[email protected] | 3125844 | 2014-06-05 03:37:41 | [diff] [blame] | 149 | scoped_ptr<google_apis::FileResource> gdata_entry); |
[email protected] | 6297d0a | 2013-11-07 14:06:14 | [diff] [blame] | 150 | void GetFileContentAfterDownloadFile( |
[email protected] | 7e8cd6e3 | 2013-04-22 08:01:01 | [diff] [blame] | 151 | const FileOperationCallback& completion_callback, |
| 152 | google_apis::GDataErrorCode gdata_error, |
| 153 | const base::FilePath& temp_file); |
| 154 | |
[email protected] | 6297d0a | 2013-11-07 14:06:14 | [diff] [blame] | 155 | // Helpers of GetResourceEntry. |
[email protected] | d14c29b | 2013-04-01 09:44:18 | [diff] [blame] | 156 | // How the method works: |
| 157 | // 1) If the path is root, gets AboutResrouce from the drive service |
[email protected] | 67241b83 | 2013-05-02 04:55:52 | [diff] [blame] | 158 | // and create ResourceEntry. |
| 159 | // 2-1) Otherwise, gets the parent's ResourceEntry by recursive call. |
[email protected] | d14c29b | 2013-04-01 09:44:18 | [diff] [blame] | 160 | // 2-2) Then, gets the resource list by restricting the parent with its id. |
[email protected] | 67241b83 | 2013-05-02 04:55:52 | [diff] [blame] | 161 | // 2-3) Search the results based on title, and return the ResourceEntry. |
[email protected] | d14c29b | 2013-04-01 09:44:18 | [diff] [blame] | 162 | // Note that adding suffix (e.g. " (2)") for files sharing a same name is |
[email protected] | ec83778 | 2013-05-01 07:20:24 | [diff] [blame] | 163 | // not supported in FakeFileSystem. Thus, even if the server has |
[email protected] | d14c29b | 2013-04-01 09:44:18 | [diff] [blame] | 164 | // files sharing the same name under a directory, the second (or later) |
| 165 | // file cannot be taken with the suffixed name. |
[email protected] | 6297d0a | 2013-11-07 14:06:14 | [diff] [blame] | 166 | void GetResourceEntryAfterGetAboutResource( |
[email protected] | 0e19671 | 2013-05-14 05:26:17 | [diff] [blame] | 167 | const GetResourceEntryCallback& callback, |
[email protected] | d14c29b | 2013-04-01 09:44:18 | [diff] [blame] | 168 | google_apis::GDataErrorCode gdata_error, |
| 169 | scoped_ptr<google_apis::AboutResource> about_resource); |
[email protected] | 6297d0a | 2013-11-07 14:06:14 | [diff] [blame] | 170 | void GetResourceEntryAfterGetParentEntryInfo( |
[email protected] | d14c29b | 2013-04-01 09:44:18 | [diff] [blame] | 171 | const base::FilePath& base_name, |
[email protected] | 0e19671 | 2013-05-14 05:26:17 | [diff] [blame] | 172 | const GetResourceEntryCallback& callback, |
[email protected] | 78a158b | 2013-04-23 06:57:49 | [diff] [blame] | 173 | FileError error, |
[email protected] | 67241b83 | 2013-05-02 04:55:52 | [diff] [blame] | 174 | scoped_ptr<ResourceEntry> parent_entry); |
[email protected] | 2d3f735 | 2014-06-02 05:51:54 | [diff] [blame] | 175 | void GetResourceEntryAfterGetFileList( |
[email protected] | d14c29b | 2013-04-01 09:44:18 | [diff] [blame] | 176 | const base::FilePath& base_name, |
[email protected] | 0e19671 | 2013-05-14 05:26:17 | [diff] [blame] | 177 | const GetResourceEntryCallback& callback, |
[email protected] | d14c29b | 2013-04-01 09:44:18 | [diff] [blame] | 178 | google_apis::GDataErrorCode gdata_error, |
[email protected] | 2d3f735 | 2014-06-02 05:51:54 | [diff] [blame] | 179 | scoped_ptr<google_apis::FileList> file_list); |
[email protected] | d14c29b | 2013-04-01 09:44:18 | [diff] [blame] | 180 | |
[email protected] | e50af765 | 2013-06-20 06:39:31 | [diff] [blame] | 181 | DriveServiceInterface* drive_service_; // Not owned. |
[email protected] | 7e8cd6e3 | 2013-04-22 08:01:01 | [diff] [blame] | 182 | base::ScopedTempDir cache_dir_; |
[email protected] | d775226 | 2013-03-26 12:56:59 | [diff] [blame] | 183 | |
| 184 | // Note: This should remain the last member so it'll be destroyed and |
| 185 | // invalidate the weak pointers before any other members are destroyed. |
[email protected] | ec83778 | 2013-05-01 07:20:24 | [diff] [blame] | 186 | base::WeakPtrFactory<FakeFileSystem> weak_ptr_factory_; |
[email protected] | d775226 | 2013-03-26 12:56:59 | [diff] [blame] | 187 | |
[email protected] | ec83778 | 2013-05-01 07:20:24 | [diff] [blame] | 188 | DISALLOW_COPY_AND_ASSIGN(FakeFileSystem); |
[email protected] | 88e15d2e | 2013-02-15 10:53:47 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | } // namespace test_util |
| 192 | } // namespace drive |
| 193 | |
[email protected] | ec83778 | 2013-05-01 07:20:24 | [diff] [blame] | 194 | #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FAKE_FILE_SYSTEM_H_ |