Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / fake_file_system.h
blobe84d339f928af5bf1f2d371c1bcac472ce22b427
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.
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FAKE_FILE_SYSTEM_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_FAKE_FILE_SYSTEM_H_
8 #include <string>
10 #include "base/basictypes.h"
11 #include "base/callback_forward.h"
12 #include "base/files/scoped_temp_dir.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "chrome/browser/chromeos/drive/file_errors.h"
15 #include "chrome/browser/chromeos/drive/file_system_interface.h"
16 #include "google_apis/drive/drive_api_error_codes.h"
18 namespace google_apis {
20 class AboutResource;
21 class FileResource;
23 } // namespace google_apis
25 namespace drive {
27 class DriveServiceInterface;
28 class FileSystemObserver;
29 class ResourceEntry;
31 namespace test_util {
33 // This class implements a fake FileSystem which acts like a real Drive
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).
39 class FakeFileSystem : public FileSystemInterface {
40 public:
41 explicit FakeFileSystem(DriveServiceInterface* drive_service);
42 ~FakeFileSystem() override;
44 // FileSystemInterface Overrides.
45 void AddObserver(FileSystemObserver* observer) override;
46 void RemoveObserver(FileSystemObserver* observer) override;
47 void CheckForUpdates() override;
48 void TransferFileFromLocalToRemote(
49 const base::FilePath& local_src_file_path,
50 const base::FilePath& remote_dest_file_path,
51 const FileOperationCallback& callback) override;
52 void OpenFile(const base::FilePath& file_path,
53 OpenMode open_mode,
54 const std::string& mime_type,
55 const OpenFileCallback& callback) override;
56 void Copy(const base::FilePath& src_file_path,
57 const base::FilePath& dest_file_path,
58 bool preserve_last_modified,
59 const FileOperationCallback& callback) override;
60 void Move(const base::FilePath& src_file_path,
61 const base::FilePath& dest_file_path,
62 const FileOperationCallback& callback) override;
63 void Remove(const base::FilePath& file_path,
64 bool is_recursive,
65 const FileOperationCallback& callback) override;
66 void CreateDirectory(const base::FilePath& directory_path,
67 bool is_exclusive,
68 bool is_recursive,
69 const FileOperationCallback& callback) override;
70 void CreateFile(const base::FilePath& file_path,
71 bool is_exclusive,
72 const std::string& mime_type,
73 const FileOperationCallback& callback) override;
74 void TouchFile(const base::FilePath& file_path,
75 const base::Time& last_access_time,
76 const base::Time& last_modified_time,
77 const FileOperationCallback& callback) override;
78 void TruncateFile(const base::FilePath& file_path,
79 int64 length,
80 const FileOperationCallback& callback) override;
81 void Pin(const base::FilePath& file_path,
82 const FileOperationCallback& callback) override;
83 void Unpin(const base::FilePath& file_path,
84 const FileOperationCallback& callback) override;
85 void GetFile(const base::FilePath& file_path,
86 const GetFileCallback& callback) override;
87 void GetFileForSaving(const base::FilePath& file_path,
88 const GetFileCallback& callback) override;
89 base::Closure GetFileContent(
90 const base::FilePath& file_path,
91 const GetFileContentInitializedCallback& initialized_callback,
92 const google_apis::GetContentCallback& get_content_callback,
93 const FileOperationCallback& completion_callback) override;
94 void GetResourceEntry(const base::FilePath& file_path,
95 const GetResourceEntryCallback& callback) override;
96 void ReadDirectory(const base::FilePath& file_path,
97 const ReadDirectoryEntriesCallback& entries_callback,
98 const FileOperationCallback& completion_callback) override;
99 void Search(const std::string& search_query,
100 const GURL& next_link,
101 const SearchCallback& callback) override;
102 void SearchMetadata(const std::string& query,
103 int options,
104 int at_most_num_matches,
105 const SearchMetadataCallback& callback) override;
106 void SearchByHashes(const std::set<std::string>& hashes,
107 const SearchByHashesCallback& callback) override;
108 void GetAvailableSpace(const GetAvailableSpaceCallback& callback) override;
109 void GetShareUrl(const base::FilePath& file_path,
110 const GURL& embed_origin,
111 const GetShareUrlCallback& callback) override;
112 void GetMetadata(const GetFilesystemMetadataCallback& callback) override;
113 void MarkCacheFileAsMounted(const base::FilePath& drive_file_path,
114 const MarkMountedCallback& callback) override;
115 void MarkCacheFileAsUnmounted(const base::FilePath& cache_file_path,
116 const FileOperationCallback& callback) override;
117 void AddPermission(const base::FilePath& drive_file_path,
118 const std::string& email,
119 google_apis::drive::PermissionRole role,
120 const FileOperationCallback& callback) override;
121 void SetProperty(const base::FilePath& drive_file_path,
122 google_apis::drive::Property::Visibility visibility,
123 const std::string& key,
124 const std::string& value,
125 const FileOperationCallback& callback) override;
126 void Reset(const FileOperationCallback& callback) override;
127 void GetPathFromResourceId(const std::string& resource_id,
128 const GetFilePathCallback& callback) override;
129 void FreeDiskSpaceIfNeededFor(int64 num_bytes,
130 const FreeDiskSpaceCallback& callback) override;
132 private:
133 // Helpers of GetFileContent.
134 // How the method works:
135 // 1) Gets ResourceEntry of the path.
136 // 2) Look at if there is a cache file or not. If found return it.
137 // 3) Otherwise start DownloadFile.
138 // 4) Runs the |completion_callback| upon the download completion.
139 void GetFileContentAfterGetResourceEntry(
140 const GetFileContentInitializedCallback& initialized_callback,
141 const google_apis::GetContentCallback& get_content_callback,
142 const FileOperationCallback& completion_callback,
143 FileError error,
144 scoped_ptr<ResourceEntry> entry);
145 void GetFileContentAfterGetFileResource(
146 const GetFileContentInitializedCallback& initialized_callback,
147 const google_apis::GetContentCallback& get_content_callback,
148 const FileOperationCallback& completion_callback,
149 google_apis::DriveApiErrorCode gdata_error,
150 scoped_ptr<google_apis::FileResource> gdata_entry);
151 void GetFileContentAfterDownloadFile(
152 const FileOperationCallback& completion_callback,
153 google_apis::DriveApiErrorCode gdata_error,
154 const base::FilePath& temp_file);
156 // Helpers of GetResourceEntry.
157 // How the method works:
158 // 1) If the path is root, gets AboutResrouce from the drive service
159 // and create ResourceEntry.
160 // 2-1) Otherwise, gets the parent's ResourceEntry by recursive call.
161 // 2-2) Then, gets the resource list by restricting the parent with its id.
162 // 2-3) Search the results based on title, and return the ResourceEntry.
163 // Note that adding suffix (e.g. " (2)") for files sharing a same name is
164 // not supported in FakeFileSystem. Thus, even if the server has
165 // files sharing the same name under a directory, the second (or later)
166 // file cannot be taken with the suffixed name.
167 void GetResourceEntryAfterGetAboutResource(
168 const GetResourceEntryCallback& callback,
169 google_apis::DriveApiErrorCode gdata_error,
170 scoped_ptr<google_apis::AboutResource> about_resource);
171 void GetResourceEntryAfterGetParentEntryInfo(
172 const base::FilePath& base_name,
173 const GetResourceEntryCallback& callback,
174 FileError error,
175 scoped_ptr<ResourceEntry> parent_entry);
176 void GetResourceEntryAfterGetFileList(
177 const base::FilePath& base_name,
178 const GetResourceEntryCallback& callback,
179 google_apis::DriveApiErrorCode gdata_error,
180 scoped_ptr<google_apis::FileList> file_list);
182 DriveServiceInterface* drive_service_; // Not owned.
183 base::ScopedTempDir cache_dir_;
185 // Note: This should remain the last member so it'll be destroyed and
186 // invalidate the weak pointers before any other members are destroyed.
187 base::WeakPtrFactory<FakeFileSystem> weak_ptr_factory_;
189 DISALLOW_COPY_AND_ASSIGN(FakeFileSystem);
192 } // namespace test_util
193 } // namespace drive
195 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FAKE_FILE_SYSTEM_H_