blob: 558b37ff21ef2017671cd62e9eb29f75024cd75d [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]d7752262013-03-26 12:56:5916#include "chrome/browser/google_apis/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]88e15d2e2013-02-15 10:53:4721class ResourceEntry;
[email protected]2a051402013-06-06 09:59:4022class ResourceList;
[email protected]88e15d2e2013-02-15 10:53:4723
24} // namespace google_apis
25
26namespace drive {
27
[email protected]e50af7652013-06-20 06:39:3128class DriveServiceInterface;
[email protected]43309dd92013-04-25 07:28:0329class FileSystemObserver;
[email protected]67241b832013-05-02 04:55:5230class ResourceEntry;
[email protected]88e15d2e2013-02-15 10:53:4731
32namespace test_util {
33
[email protected]0d52ed52013-05-01 08:21:2134// This class implements a fake FileSystem which acts like a real Drive
[email protected]88e15d2e2013-02-15 10:53:4735// file system with FakeDriveService, for testing purpose.
36// Note that this class doesn't support "caching" at the moment, so the number
37// of interactions to the FakeDriveService may be bigger than the real
38// implementation.
39// Currently most methods are empty (not implemented).
[email protected]976309f12013-05-02 01:19:1540class FakeFileSystem : public FileSystemInterface {
[email protected]88e15d2e2013-02-15 10:53:4741 public:
[email protected]e50af7652013-06-20 06:39:3142 explicit FakeFileSystem(DriveServiceInterface* drive_service);
[email protected]ec837782013-05-01 07:20:2443 virtual ~FakeFileSystem();
[email protected]88e15d2e2013-02-15 10:53:4744
[email protected]7e8cd6e32013-04-22 08:01:0145 // Initialization for testing. This can be called instead of Initialize
46 // for testing purpose. Returns true for success.
47 bool InitializeForTesting();
48
[email protected]976309f12013-05-02 01:19:1549 // FileSystemInterface Overrides.
[email protected]88e15d2e2013-02-15 10:53:4750 virtual void Initialize() OVERRIDE;
[email protected]43309dd92013-04-25 07:28:0351 virtual void AddObserver(FileSystemObserver* observer) OVERRIDE;
52 virtual void RemoveObserver(FileSystemObserver* observer) OVERRIDE;
[email protected]88e15d2e2013-02-15 10:53:4753 virtual void CheckForUpdates() OVERRIDE;
[email protected]4df437d2013-05-14 07:20:4154 virtual void GetResourceEntryById(
[email protected]88e15d2e2013-02-15 10:53:4755 const std::string& resource_id,
[email protected]bed5c4b2013-05-30 05:00:5856 const GetResourceEntryCallback& callback) OVERRIDE;
[email protected]88e15d2e2013-02-15 10:53:4757 virtual void TransferFileFromRemoteToLocal(
58 const base::FilePath& remote_src_file_path,
59 const base::FilePath& local_dest_file_path,
60 const FileOperationCallback& callback) OVERRIDE;
61 virtual void TransferFileFromLocalToRemote(
62 const base::FilePath& local_src_file_path,
63 const base::FilePath& remote_dest_file_path,
64 const FileOperationCallback& callback) OVERRIDE;
65 virtual void OpenFile(const base::FilePath& file_path,
66 const OpenFileCallback& callback) OVERRIDE;
67 virtual void CloseFile(const base::FilePath& file_path,
68 const FileOperationCallback& callback) OVERRIDE;
69 virtual void Copy(const base::FilePath& src_file_path,
70 const base::FilePath& dest_file_path,
71 const FileOperationCallback& callback) OVERRIDE;
72 virtual void Move(const base::FilePath& src_file_path,
73 const base::FilePath& dest_file_path,
74 const FileOperationCallback& callback) OVERRIDE;
75 virtual void Remove(const base::FilePath& file_path,
76 bool is_recursive,
77 const FileOperationCallback& callback) OVERRIDE;
78 virtual void CreateDirectory(const base::FilePath& directory_path,
79 bool is_exclusive,
80 bool is_recursive,
81 const FileOperationCallback& callback) OVERRIDE;
82 virtual void CreateFile(const base::FilePath& file_path,
83 bool is_exclusive,
84 const FileOperationCallback& callback) OVERRIDE;
[email protected]8c2476c22013-05-22 17:50:1085 virtual void TouchFile(const base::FilePath& file_path,
86 const base::Time& last_access_time,
87 const base::Time& last_modified_time,
88 const FileOperationCallback& callback) OVERRIDE;
[email protected]378b6132013-04-19 18:05:1889 virtual void Pin(const base::FilePath& file_path,
90 const FileOperationCallback& callback) OVERRIDE;
91 virtual void Unpin(const base::FilePath& file_path,
92 const FileOperationCallback& callback) OVERRIDE;
[email protected]88e15d2e2013-02-15 10:53:4793 virtual void GetFileByPath(const base::FilePath& file_path,
94 const GetFileCallback& callback) OVERRIDE;
95 virtual void GetFileByResourceId(
96 const std::string& resource_id,
[email protected]2a5a40e2013-05-29 04:15:2597 const ClientContext& context,
[email protected]88e15d2e2013-02-15 10:53:4798 const GetFileCallback& get_file_callback,
99 const google_apis::GetContentCallback& get_content_callback) OVERRIDE;
[email protected]8e6e51f82013-04-16 05:04:00100 virtual void GetFileContentByPath(
101 const base::FilePath& file_path,
102 const GetFileContentInitializedCallback& initialized_callback,
103 const google_apis::GetContentCallback& get_content_callback,
104 const FileOperationCallback& completion_callback) OVERRIDE;
[email protected]88e15d2e2013-02-15 10:53:47105 virtual void UpdateFileByResourceId(
106 const std::string& resource_id,
[email protected]2a5a40e2013-05-29 04:15:25107 const ClientContext& context,
[email protected]88e15d2e2013-02-15 10:53:47108 const FileOperationCallback& callback) OVERRIDE;
[email protected]4df437d2013-05-14 07:20:41109 virtual void GetResourceEntryByPath(
[email protected]88e15d2e2013-02-15 10:53:47110 const base::FilePath& file_path,
[email protected]0e196712013-05-14 05:26:17111 const GetResourceEntryCallback& callback) OVERRIDE;
[email protected]88e15d2e2013-02-15 10:53:47112 virtual void ReadDirectoryByPath(
113 const base::FilePath& file_path,
114 const ReadDirectoryWithSettingCallback& callback) OVERRIDE;
[email protected]6d77798882013-03-06 01:25:24115 virtual void RefreshDirectory(
116 const base::FilePath& file_path,
117 const FileOperationCallback& callback) OVERRIDE;
[email protected]88e15d2e2013-02-15 10:53:47118 virtual void Search(const std::string& search_query,
[email protected]6bb1c762013-06-03 08:36:56119 const GURL& next_url,
[email protected]88e15d2e2013-02-15 10:53:47120 const SearchCallback& callback) OVERRIDE;
[email protected]14b69c52013-03-27 09:48:47121 virtual void SearchMetadata(const std::string& query,
[email protected]48c884ca2013-04-09 12:40:01122 int options,
[email protected]14b69c52013-03-27 09:48:47123 int at_most_num_matches,
124 const SearchMetadataCallback& callback) OVERRIDE;
[email protected]88e15d2e2013-02-15 10:53:47125 virtual void GetAvailableSpace(
126 const GetAvailableSpaceCallback& callback) OVERRIDE;
[email protected]88e15d2e2013-02-15 10:53:47127 virtual void GetMetadata(
128 const GetFilesystemMetadataCallback& callback) OVERRIDE;
[email protected]48348d5c2013-04-22 17:44:22129 virtual void MarkCacheFileAsMounted(
130 const base::FilePath& drive_file_path,
131 const OpenFileCallback& callback) OVERRIDE;
132 virtual void MarkCacheFileAsUnmounted(
133 const base::FilePath& cache_file_path,
134 const FileOperationCallback& callback) OVERRIDE;
[email protected]45dff6d2013-04-23 17:47:31135 virtual void GetCacheEntryByResourceId(
136 const std::string& resource_id,
137 const std::string& md5,
138 const GetCacheEntryCallback& callback) OVERRIDE;
[email protected]88e15d2e2013-02-15 10:53:47139 virtual void Reload() OVERRIDE;
140
141 private:
[email protected]bed5c4b2013-05-30 05:00:58142 // Helper of GetResourceEntryById.
[email protected]4df437d2013-05-14 07:20:41143 void GetResourceEntryByIdAfterGetResourceEntry(
[email protected]bed5c4b2013-05-30 05:00:58144 const GetResourceEntryCallback& callback,
[email protected]d7752262013-03-26 12:56:59145 google_apis::GDataErrorCode error_in,
146 scoped_ptr<google_apis::ResourceEntry> resource_entry);
[email protected]d7752262013-03-26 12:56:59147
[email protected]7e8cd6e32013-04-22 08:01:01148 // Helpers of GetFileContentByPath.
149 // How the method works:
[email protected]67241b832013-05-02 04:55:52150 // 1) Gets ResourceEntry of the path.
[email protected]7e8cd6e32013-04-22 08:01:01151 // 2) Look at if there is a cache file or not. If found return it.
152 // 3) Otherwise start DownloadFile.
153 // 4) Runs the |completion_callback| upon the download completion.
[email protected]4df437d2013-05-14 07:20:41154 void GetFileContentByPathAfterGetResourceEntry(
[email protected]7e8cd6e32013-04-22 08:01:01155 const base::FilePath& file_path,
156 const GetFileContentInitializedCallback& initialized_callback,
157 const google_apis::GetContentCallback& get_content_callback,
158 const FileOperationCallback& completion_callback,
[email protected]78a158b2013-04-23 06:57:49159 FileError error,
[email protected]67241b832013-05-02 04:55:52160 scoped_ptr<ResourceEntry> entry);
[email protected]4df437d2013-05-14 07:20:41161 void GetFileContentByPathAfterGetWapiResourceEntry(
[email protected]5b82c9d2013-05-10 03:06:27162 const base::FilePath& file_path,
163 const GetFileContentInitializedCallback& initialized_callback,
164 const google_apis::GetContentCallback& get_content_callback,
165 const FileOperationCallback& completion_callback,
166 google_apis::GDataErrorCode gdata_error,
167 scoped_ptr<google_apis::ResourceEntry> gdata_entry);
[email protected]7e8cd6e32013-04-22 08:01:01168 void GetFileContentByPathAfterDownloadFile(
169 const FileOperationCallback& completion_callback,
170 google_apis::GDataErrorCode gdata_error,
171 const base::FilePath& temp_file);
172
[email protected]4df437d2013-05-14 07:20:41173 // Helpers of GetResourceEntryByPath.
[email protected]d14c29b2013-04-01 09:44:18174 // How the method works:
175 // 1) If the path is root, gets AboutResrouce from the drive service
[email protected]67241b832013-05-02 04:55:52176 // and create ResourceEntry.
177 // 2-1) Otherwise, gets the parent's ResourceEntry by recursive call.
[email protected]d14c29b2013-04-01 09:44:18178 // 2-2) Then, gets the resource list by restricting the parent with its id.
[email protected]67241b832013-05-02 04:55:52179 // 2-3) Search the results based on title, and return the ResourceEntry.
[email protected]d14c29b2013-04-01 09:44:18180 // Note that adding suffix (e.g. " (2)") for files sharing a same name is
[email protected]ec837782013-05-01 07:20:24181 // not supported in FakeFileSystem. Thus, even if the server has
[email protected]d14c29b2013-04-01 09:44:18182 // files sharing the same name under a directory, the second (or later)
183 // file cannot be taken with the suffixed name.
[email protected]4df437d2013-05-14 07:20:41184 void GetResourceEntryByPathAfterGetAboutResource(
[email protected]0e196712013-05-14 05:26:17185 const GetResourceEntryCallback& callback,
[email protected]d14c29b2013-04-01 09:44:18186 google_apis::GDataErrorCode gdata_error,
187 scoped_ptr<google_apis::AboutResource> about_resource);
[email protected]4df437d2013-05-14 07:20:41188 void GetResourceEntryByPathAfterGetParentEntryInfo(
[email protected]d14c29b2013-04-01 09:44:18189 const base::FilePath& base_name,
[email protected]0e196712013-05-14 05:26:17190 const GetResourceEntryCallback& callback,
[email protected]78a158b2013-04-23 06:57:49191 FileError error,
[email protected]67241b832013-05-02 04:55:52192 scoped_ptr<ResourceEntry> parent_entry);
[email protected]4df437d2013-05-14 07:20:41193 void GetResourceEntryByPathAfterGetResourceList(
[email protected]d14c29b2013-04-01 09:44:18194 const base::FilePath& base_name,
[email protected]0e196712013-05-14 05:26:17195 const GetResourceEntryCallback& callback,
[email protected]d14c29b2013-04-01 09:44:18196 google_apis::GDataErrorCode gdata_error,
197 scoped_ptr<google_apis::ResourceList> resource_list);
198
[email protected]e50af7652013-06-20 06:39:31199 DriveServiceInterface* drive_service_; // Not owned.
[email protected]7e8cd6e32013-04-22 08:01:01200 base::ScopedTempDir cache_dir_;
[email protected]d7752262013-03-26 12:56:59201
202 // Note: This should remain the last member so it'll be destroyed and
203 // invalidate the weak pointers before any other members are destroyed.
[email protected]ec837782013-05-01 07:20:24204 base::WeakPtrFactory<FakeFileSystem> weak_ptr_factory_;
[email protected]d7752262013-03-26 12:56:59205
[email protected]ec837782013-05-01 07:20:24206 DISALLOW_COPY_AND_ASSIGN(FakeFileSystem);
[email protected]88e15d2e2013-02-15 10:53:47207};
208
209} // namespace test_util
210} // namespace drive
211
[email protected]ec837782013-05-01 07:20:24212#endif // CHROME_BROWSER_CHROMEOS_DRIVE_FAKE_FILE_SYSTEM_H_