1 // Copyright 2014 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_FILE_SYSTEM_PROVIDER_FAKE_PROVIDED_FILE_SYSTEM_H_
6 #define CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FAKE_PROVIDED_FILE_SYSTEM_H_
11 #include "base/memory/weak_ptr.h"
12 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
13 #include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h"
26 namespace file_system_provider {
30 // Path of a sample fake file, which is added to the fake file system by
32 extern const char kFakeFilePath[];
34 // Represents a file or a directory on a fake file system.
38 FakeEntry(const EntryMetadata& metadata, const std::string& contents)
39 : metadata(metadata), contents(contents) {}
41 virtual ~FakeEntry() {}
43 EntryMetadata metadata;
47 // Fake provided file system implementation. Does not communicate with target
48 // extensions. Used for unit tests.
49 class FakeProvidedFileSystem : public ProvidedFileSystemInterface {
51 explicit FakeProvidedFileSystem(
52 const ProvidedFileSystemInfo& file_system_info);
53 virtual ~FakeProvidedFileSystem();
55 // Adds a fake entry to the fake file system.
56 void AddEntry(const base::FilePath& entry_path,
58 const std::string& name,
60 base::Time modification_time,
61 std::string mime_type,
62 std::string contents);
64 // Fetches a pointer to a fake entry registered in the fake file system. If
65 // found, then the result is written to |fake_entry| and true is returned.
66 // Otherwise, false is returned. |fake_entry| must not be NULL.
67 bool GetEntry(const base::FilePath& entry_path, FakeEntry* fake_entry) const;
69 // ProvidedFileSystemInterface overrides.
70 virtual void RequestUnmount(
71 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
72 virtual void GetMetadata(
73 const base::FilePath& entry_path,
74 const ProvidedFileSystemInterface::GetMetadataCallback& callback)
76 virtual void ReadDirectory(
77 const base::FilePath& directory_path,
78 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) OVERRIDE;
79 virtual void OpenFile(const base::FilePath& file_path,
81 const OpenFileCallback& callback) OVERRIDE;
82 virtual void CloseFile(
84 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
85 virtual void ReadFile(int file_handle,
86 net::IOBuffer* buffer,
89 const ReadChunkReceivedCallback& callback) OVERRIDE;
90 virtual void CreateDirectory(
91 const base::FilePath& directory_path,
94 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
95 virtual void DeleteEntry(
96 const base::FilePath& entry_path,
98 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
99 virtual void CreateFile(
100 const base::FilePath& file_path,
101 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
102 virtual void CopyEntry(
103 const base::FilePath& source_path,
104 const base::FilePath& target_path,
105 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
106 virtual void MoveEntry(
107 const base::FilePath& source_path,
108 const base::FilePath& target_path,
109 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
110 virtual void Truncate(
111 const base::FilePath& file_path,
113 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
114 virtual void WriteFile(
116 net::IOBuffer* buffer,
119 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE;
120 virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const OVERRIDE;
121 virtual RequestManager* GetRequestManager() OVERRIDE;
122 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() OVERRIDE;
124 // Factory callback, to be used in Service::SetFileSystemFactory(). The
125 // |event_router| argument can be NULL.
126 static ProvidedFileSystemInterface* Create(
128 const ProvidedFileSystemInfo& file_system_info);
131 typedef std::map<base::FilePath, FakeEntry> Entries;
132 typedef std::map<int, base::FilePath> OpenedFilesMap;
134 ProvidedFileSystemInfo file_system_info_;
136 OpenedFilesMap opened_files_;
137 int last_file_handle_;
139 base::WeakPtrFactory<ProvidedFileSystemInterface> weak_ptr_factory_;
140 DISALLOW_COPY_AND_ASSIGN(FakeProvidedFileSystem);
143 } // namespace file_system_provider
144 } // namespace chromeos
146 #endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FAKE_PROVIDED_FILE_SYSTEM_H_