fake_provided_file_system.h revision cedac228d2dd51db4b79ea1e72c7f249408ee061
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. 4 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_ 7 8#include <map> 9 10#include "base/memory/weak_ptr.h" 11#include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h" 12#include "chrome/browser/chromeos/file_system_provider/provided_file_system_interface.h" 13 14namespace net { 15class IOBuffer; 16} // namespace net 17 18namespace extensions { 19class EventRouter; 20} // namespace extensions 21 22namespace chromeos { 23namespace file_system_provider { 24 25class RequestManager; 26 27extern const char kFakeFileName[]; 28extern const char kFakeFilePath[]; 29extern const char kFakeFileText[]; 30extern const size_t kFakeFileSize; 31 32// Fake provided file system implementation. Does not communicate with target 33// extensions. Used for unit tests. 34class FakeProvidedFileSystem : public ProvidedFileSystemInterface { 35 public: 36 explicit FakeProvidedFileSystem( 37 const ProvidedFileSystemInfo& file_system_info); 38 virtual ~FakeProvidedFileSystem(); 39 40 // ProvidedFileSystemInterface overrides. 41 virtual void RequestUnmount( 42 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE; 43 virtual void GetMetadata( 44 const base::FilePath& entry_path, 45 const fileapi::AsyncFileUtil::GetFileInfoCallback& callback) OVERRIDE; 46 virtual void ReadDirectory( 47 const base::FilePath& directory_path, 48 const fileapi::AsyncFileUtil::ReadDirectoryCallback& callback) OVERRIDE; 49 virtual void OpenFile(const base::FilePath& file_path, 50 OpenFileMode mode, 51 bool create, 52 const OpenFileCallback& callback) OVERRIDE; 53 virtual void CloseFile( 54 int file_handle, 55 const fileapi::AsyncFileUtil::StatusCallback& callback) OVERRIDE; 56 virtual void ReadFile(int file_handle, 57 net::IOBuffer* buffer, 58 int64 offset, 59 int length, 60 const ReadChunkReceivedCallback& callback) OVERRIDE; 61 virtual const ProvidedFileSystemInfo& GetFileSystemInfo() const OVERRIDE; 62 virtual RequestManager* GetRequestManager() OVERRIDE; 63 virtual base::WeakPtr<ProvidedFileSystemInterface> GetWeakPtr() OVERRIDE; 64 65 // Factory callback, to be used in Service::SetFileSystemFactory(). The 66 // |event_router| argument can be NULL. 67 static ProvidedFileSystemInterface* Create( 68 extensions::EventRouter* event_router, 69 const ProvidedFileSystemInfo& file_system_info); 70 71 private: 72 typedef std::map<int, base::FilePath> OpenedFilesMap; 73 74 ProvidedFileSystemInfo file_system_info_; 75 OpenedFilesMap opened_files_; 76 int last_file_handle_; 77 78 base::WeakPtrFactory<ProvidedFileSystemInterface> weak_ptr_factory_; 79 DISALLOW_COPY_AND_ASSIGN(FakeProvidedFileSystem); 80}; 81 82} // namespace file_system_provider 83} // namespace chromeos 84 85#endif // CHROME_BROWSER_CHROMEOS_FILE_SYSTEM_PROVIDER_FAKE_PROVIDED_FILE_SYSTEM_H_ 86