blob: a32a8faec3ef2543c6fc29e004eba4cebc1a424f [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
[email protected]ec837782013-05-01 07:20:245#ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FAKE_FILE_SYSTEM_H_
6#define CHROME_BROWSER_CHROMEOS_DRIVE_FAKE_FILE_SYSTEM_H_
[email protected]88e15d2e2013-02-15 10:53:477
8#include <string>
9
10#include "base/basictypes.h"
[email protected]d7752262013-03-26 12:56:5911#include "base/callback_forward.h"
[email protected]7e8cd6e32013-04-22 08:01:0112#include "base/files/scoped_temp_dir.h"
[email protected]88e15d2e2013-02-15 10:53:4713#include "base/memory/scoped_ptr.h"
[email protected]78a158b2013-04-23 06:57:4914#include "chrome/browser/chromeos/drive/file_errors.h"
[email protected]976309f12013-05-02 01:19:1515#include "chrome/browser/chromeos/drive/file_system_interface.h"
[email protected]e196bef32013-12-03 05:33:1316#include "google_apis/drive/gdata_errorcode.h"
[email protected]88e15d2e2013-02-15 10:53:4717
18namespace google_apis {
19
[email protected]d7752262013-03-26 12:56:5920class AboutResource;
[email protected]31258442014-06-05 03:37:4121class FileResource;
[email protected]88e15d2e2013-02-15 10:53:4722
23} // namespace google_apis
24
25namespace drive {
26
[email protected]e50af7652013-06-20 06:39:3127class DriveServiceInterface;
[email protected]43309dd92013-04-25 07:28:0328class FileSystemObserver;
[email protected]67241b832013-05-02 04:55:5229class ResourceEntry;
[email protected]88e15d2e2013-02-15 10:53:4730
31namespace test_util {
32
[email protected]0d52ed52013-05-01 08:21:2133// This class implements a fake FileSystem which acts like a real Drive
[email protected]88e15d2e2013-02-15 10:53:4734// 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]976309f12013-05-02 01:19:1539class FakeFileSystem : public FileSystemInterface {
[email protected]88e15d2e2013-02-15 10:53:4740 public:
[email protected]e50af7652013-06-20 06:39:3141 explicit FakeFileSystem(DriveServiceInterface* drive_service);
[email protected]ec837782013-05-01 07:20:2442 virtual ~FakeFileSystem();
[email protected]88e15d2e2013-02-15 10:53:4743
[email protected]976309f12013-05-02 01:19:1544 // FileSystemInterface Overrides.
mostynb9108efb92014-10-03 23:46:1545 virtual void AddObserver(FileSystemObserver* observer) override;
46 virtual void RemoveObserver(FileSystemObserver* observer) override;
47 virtual void CheckForUpdates() override;
[email protected]88e15d2e2013-02-15 10:53:4748 virtual void TransferFileFromLocalToRemote(
49 const base::FilePath& local_src_file_path,
50 const base::FilePath& remote_dest_file_path,
mostynb9108efb92014-10-03 23:46:1551 const FileOperationCallback& callback) override;
[email protected]88e15d2e2013-02-15 10:53:4752 virtual void OpenFile(const base::FilePath& file_path,
[email protected]6966445f2013-07-11 09:33:5953 OpenMode open_mode,
[email protected]b570b7b2013-08-21 14:59:3654 const std::string& mime_type,
mostynb9108efb92014-10-03 23:46:1555 const OpenFileCallback& callback) override;
[email protected]88e15d2e2013-02-15 10:53:4756 virtual void Copy(const base::FilePath& src_file_path,
57 const base::FilePath& dest_file_path,
[email protected]1f4696c2013-09-25 08:08:1858 bool preserve_last_modified,
mostynb9108efb92014-10-03 23:46:1559 const FileOperationCallback& callback) override;
[email protected]88e15d2e2013-02-15 10:53:4760 virtual void Move(const base::FilePath& src_file_path,
61 const base::FilePath& dest_file_path,
mostynb9108efb92014-10-03 23:46:1562 const FileOperationCallback& callback) override;
[email protected]88e15d2e2013-02-15 10:53:4763 virtual void Remove(const base::FilePath& file_path,
64 bool is_recursive,
mostynb9108efb92014-10-03 23:46:1565 const FileOperationCallback& callback) override;
[email protected]88e15d2e2013-02-15 10:53:4766 virtual void CreateDirectory(const base::FilePath& directory_path,
67 bool is_exclusive,
68 bool is_recursive,
mostynb9108efb92014-10-03 23:46:1569 const FileOperationCallback& callback) override;
[email protected]88e15d2e2013-02-15 10:53:4770 virtual void CreateFile(const base::FilePath& file_path,
71 bool is_exclusive,
[email protected]b570b7b2013-08-21 14:59:3672 const std::string& mime_type,
mostynb9108efb92014-10-03 23:46:1573 const FileOperationCallback& callback) override;
[email protected]8c2476c22013-05-22 17:50:1074 virtual void TouchFile(const base::FilePath& file_path,
75 const base::Time& last_access_time,
76 const base::Time& last_modified_time,
mostynb9108efb92014-10-03 23:46:1577 const FileOperationCallback& callback) override;
[email protected]33539ec2013-07-01 11:02:1078 virtual void TruncateFile(const base::FilePath& file_path,
79 int64 length,
mostynb9108efb92014-10-03 23:46:1580 const FileOperationCallback& callback) override;
[email protected]378b6132013-04-19 18:05:1881 virtual void Pin(const base::FilePath& file_path,
mostynb9108efb92014-10-03 23:46:1582 const FileOperationCallback& callback) override;
[email protected]378b6132013-04-19 18:05:1883 virtual void Unpin(const base::FilePath& file_path,
mostynb9108efb92014-10-03 23:46:1584 const FileOperationCallback& callback) override;
[email protected]6297d0a2013-11-07 14:06:1485 virtual void GetFile(const base::FilePath& file_path,
mostynb9108efb92014-10-03 23:46:1586 const GetFileCallback& callback) override;
[email protected]6297d0a2013-11-07 14:06:1487 virtual void GetFileForSaving(const base::FilePath& file_path,
mostynb9108efb92014-10-03 23:46:1588 const GetFileCallback& callback) override;
[email protected]0167ff02014-03-28 17:22:2389 virtual base::Closure GetFileContent(
[email protected]8e6e51f82013-04-16 05:04:0090 const base::FilePath& file_path,
91 const GetFileContentInitializedCallback& initialized_callback,
92 const google_apis::GetContentCallback& get_content_callback,
mostynb9108efb92014-10-03 23:46:1593 const FileOperationCallback& completion_callback) override;
[email protected]6297d0a2013-11-07 14:06:1494 virtual void GetResourceEntry(
[email protected]88e15d2e2013-02-15 10:53:4795 const base::FilePath& file_path,
mostynb9108efb92014-10-03 23:46:1596 const GetResourceEntryCallback& callback) override;
[email protected]6297d0a2013-11-07 14:06:1497 virtual void ReadDirectory(
[email protected]88e15d2e2013-02-15 10:53:4798 const base::FilePath& file_path,
[email protected]f173c6d2014-04-14 10:49:5099 const ReadDirectoryEntriesCallback& entries_callback,
mostynb9108efb92014-10-03 23:46:15100 const FileOperationCallback& completion_callback) override;
[email protected]88e15d2e2013-02-15 10:53:47101 virtual void Search(const std::string& search_query,
[email protected]b5f98182013-09-04 12:43:53102 const GURL& next_link,
mostynb9108efb92014-10-03 23:46:15103 const SearchCallback& callback) override;
[email protected]14b69c52013-03-27 09:48:47104 virtual void SearchMetadata(const std::string& query,
[email protected]48c884ca2013-04-09 12:40:01105 int options,
[email protected]14b69c52013-03-27 09:48:47106 int at_most_num_matches,
mostynb9108efb92014-10-03 23:46:15107 const SearchMetadataCallback& callback) override;
[email protected]88e15d2e2013-02-15 10:53:47108 virtual void GetAvailableSpace(
mostynb9108efb92014-10-03 23:46:15109 const GetAvailableSpaceCallback& callback) override;
[email protected]ac6260e2013-07-24 10:31:12110 virtual void GetShareUrl(
111 const base::FilePath& file_path,
[email protected]3144bbf2013-07-25 06:46:18112 const GURL& embed_origin,
mostynb9108efb92014-10-03 23:46:15113 const GetShareUrlCallback& callback) override;
[email protected]88e15d2e2013-02-15 10:53:47114 virtual void GetMetadata(
mostynb9108efb92014-10-03 23:46:15115 const GetFilesystemMetadataCallback& callback) override;
[email protected]48348d5c2013-04-22 17:44:22116 virtual void MarkCacheFileAsMounted(
117 const base::FilePath& drive_file_path,
mostynb9108efb92014-10-03 23:46:15118 const MarkMountedCallback& callback) override;
[email protected]48348d5c2013-04-22 17:44:22119 virtual void MarkCacheFileAsUnmounted(
120 const base::FilePath& cache_file_path,
mostynb9108efb92014-10-03 23:46:15121 const FileOperationCallback& callback) override;
[email protected]dd4a26f2014-03-20 14:25:32122 virtual void AddPermission(const base::FilePath& drive_file_path,
123 const std::string& email,
124 google_apis::drive::PermissionRole role,
mostynb9108efb92014-10-03 23:46:15125 const FileOperationCallback& callback) override;
126 virtual void Reset(const FileOperationCallback& callback) override;
[email protected]87a14512014-03-24 12:34:03127 virtual void GetPathFromResourceId(const std::string& resource_id,
128 const GetFilePathCallback& callback)
mostynb9108efb92014-10-03 23:46:15129 override;
[email protected]88e15d2e2013-02-15 10:53:47130
131 private:
[email protected]6297d0a2013-11-07 14:06:14132 // Helpers of GetFileContent.
[email protected]7e8cd6e32013-04-22 08:01:01133 // How the method works:
[email protected]67241b832013-05-02 04:55:52134 // 1) Gets ResourceEntry of the path.
[email protected]7e8cd6e32013-04-22 08:01:01135 // 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]6297d0a2013-11-07 14:06:14138 void GetFileContentAfterGetResourceEntry(
[email protected]7e8cd6e32013-04-22 08:01:01139 const GetFileContentInitializedCallback& initialized_callback,
140 const google_apis::GetContentCallback& get_content_callback,
141 const FileOperationCallback& completion_callback,
[email protected]78a158b2013-04-23 06:57:49142 FileError error,
[email protected]67241b832013-05-02 04:55:52143 scoped_ptr<ResourceEntry> entry);
[email protected]31258442014-06-05 03:37:41144 void GetFileContentAfterGetFileResource(
[email protected]5b82c9d2013-05-10 03:06:27145 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]31258442014-06-05 03:37:41149 scoped_ptr<google_apis::FileResource> gdata_entry);
[email protected]6297d0a2013-11-07 14:06:14150 void GetFileContentAfterDownloadFile(
[email protected]7e8cd6e32013-04-22 08:01:01151 const FileOperationCallback& completion_callback,
152 google_apis::GDataErrorCode gdata_error,
153 const base::FilePath& temp_file);
154
[email protected]6297d0a2013-11-07 14:06:14155 // Helpers of GetResourceEntry.
[email protected]d14c29b2013-04-01 09:44:18156 // How the method works:
157 // 1) If the path is root, gets AboutResrouce from the drive service
[email protected]67241b832013-05-02 04:55:52158 // and create ResourceEntry.
159 // 2-1) Otherwise, gets the parent's ResourceEntry by recursive call.
[email protected]d14c29b2013-04-01 09:44:18160 // 2-2) Then, gets the resource list by restricting the parent with its id.
[email protected]67241b832013-05-02 04:55:52161 // 2-3) Search the results based on title, and return the ResourceEntry.
[email protected]d14c29b2013-04-01 09:44:18162 // Note that adding suffix (e.g. " (2)") for files sharing a same name is
[email protected]ec837782013-05-01 07:20:24163 // not supported in FakeFileSystem. Thus, even if the server has
[email protected]d14c29b2013-04-01 09:44:18164 // files sharing the same name under a directory, the second (or later)
165 // file cannot be taken with the suffixed name.
[email protected]6297d0a2013-11-07 14:06:14166 void GetResourceEntryAfterGetAboutResource(
[email protected]0e196712013-05-14 05:26:17167 const GetResourceEntryCallback& callback,
[email protected]d14c29b2013-04-01 09:44:18168 google_apis::GDataErrorCode gdata_error,
169 scoped_ptr<google_apis::AboutResource> about_resource);
[email protected]6297d0a2013-11-07 14:06:14170 void GetResourceEntryAfterGetParentEntryInfo(
[email protected]d14c29b2013-04-01 09:44:18171 const base::FilePath& base_name,
[email protected]0e196712013-05-14 05:26:17172 const GetResourceEntryCallback& callback,
[email protected]78a158b2013-04-23 06:57:49173 FileError error,
[email protected]67241b832013-05-02 04:55:52174 scoped_ptr<ResourceEntry> parent_entry);
[email protected]2d3f7352014-06-02 05:51:54175 void GetResourceEntryAfterGetFileList(
[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]d14c29b2013-04-01 09:44:18178 google_apis::GDataErrorCode gdata_error,
[email protected]2d3f7352014-06-02 05:51:54179 scoped_ptr<google_apis::FileList> file_list);
[email protected]d14c29b2013-04-01 09:44:18180
[email protected]e50af7652013-06-20 06:39:31181 DriveServiceInterface* drive_service_; // Not owned.
[email protected]7e8cd6e32013-04-22 08:01:01182 base::ScopedTempDir cache_dir_;
[email protected]d7752262013-03-26 12:56:59183
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]ec837782013-05-01 07:20:24186 base::WeakPtrFactory<FakeFileSystem> weak_ptr_factory_;
[email protected]d7752262013-03-26 12:56:59187
[email protected]ec837782013-05-01 07:20:24188 DISALLOW_COPY_AND_ASSIGN(FakeFileSystem);
[email protected]88e15d2e2013-02-15 10:53:47189};
190
191} // namespace test_util
192} // namespace drive
193
[email protected]ec837782013-05-01 07:20:24194#endif // CHROME_BROWSER_CHROMEOS_DRIVE_FAKE_FILE_SYSTEM_H_