// Copyright 2013 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. // // This file provides the core implementation of fileapi methods. // The functions should be called on UI thread. // Note that most method invocation of fileapi is done on IO thread. The gap is // filled by FileSystemProxy. // Also, the order of arguments for the functions which take FileSystemInterface // at the last is intentional. The instance of FileSystemInterface should be // accessible only on UI thread, but arguments are passed on IO thread. // So, here is an intended use case: // 1) Bind arguments on IO thread. Then a callback instance whose type is // Callback is created. // 2) Post the task to the UI thread. // 3) On UI thread, check if the instance of FileSystemInterface is alive or // not. If yes, Run the callback with it. #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_FILEAPI_WORKER_H_ #define CHROME_BROWSER_CHROMEOS_DRIVE_FILEAPI_WORKER_H_ #include #include "base/basictypes.h" #include "base/callback_forward.h" #include "base/memory/weak_ptr.h" #include "base/platform_file.h" #include "chrome/browser/chromeos/drive/file_errors.h" #include "webkit/common/blob/scoped_file.h" namespace base { class FilePath; } // namespace base namespace fileapi { struct DirectoryEntry; } // namespace fileapi namespace drive { class FileSystemInterface; namespace fileapi_internal { typedef base::Callback< void(base::PlatformFileError result)> StatusCallback; typedef base::Callback< void(base::PlatformFileError result, const base::PlatformFileInfo& file_info)> GetFileInfoCallback; typedef base::Callback< void(base::PlatformFileError result, const std::vector& file_list, bool has_more)> ReadDirectoryCallback; typedef base::Callback< void(base::PlatformFileError result, const base::PlatformFileInfo& file_info, const base::FilePath& snapshot_file_path, webkit_blob::ScopedFile::ScopeOutPolicy scope_out_policy)> CreateSnapshotFileCallback; typedef base::Callback< void(base::PlatformFileError result, base::PlatformFile platform_file)> OpenFileCallback; // Returns the metadata info of the file at |file_path|. // Called from FileSystemProxy::GetFileInfo(). void GetFileInfo(const base::FilePath& file_path, const GetFileInfoCallback& callback, FileSystemInterface* file_system); // Copies a file from |src_file_path| to |dest_file_path|. // Called from FileSystemProxy::Copy(). void Copy(const base::FilePath& src_file_path, const base::FilePath& dest_file_path, const StatusCallback& callback, FileSystemInterface* file_system); // Moves a file from |src_file_path| to |dest_file_path|. // Called from FileSystemProxy::Move(). void Move(const base::FilePath& src_file_path, const base::FilePath& dest_file_path, const StatusCallback& callback, FileSystemInterface* file_system); // Reads the contents of the directory at |file_path|. // Called from FileSystemProxy::ReadDirectory(). void ReadDirectory(const base::FilePath& file_path, const ReadDirectoryCallback& callback, FileSystemInterface* file_system); // Removes a file at |file_path|. Called from FileSystemProxy::Remove(). void Remove(const base::FilePath& file_path, bool is_recursive, const StatusCallback& callback, FileSystemInterface* file_system); // Creates a new directory at |file_path|. // Called from FileSystemProxy::CreateDirectory(). void CreateDirectory(const base::FilePath& file_path, bool is_exclusive, bool is_recursive, const StatusCallback& callback, FileSystemInterface* file_system); // Creates a new file at |file_path|. // Called from FileSystemProxy::CreateFile(). void CreateFile(const base::FilePath& file_path, bool is_exclusive, const StatusCallback& callback, FileSystemInterface* file_system); // Truncates the file at |file_path| to |length| bytes. // Called from FileSystemProxy::Truncate(). void Truncate(const base::FilePath& file_path, int64 length, const StatusCallback& callback, FileSystemInterface* file_system); // Creates a snapshot for the file at |file_path|. // Called from FileSystemProxy::CreateSnapshotFile(). void CreateSnapshotFile(const base::FilePath& file_path, const CreateSnapshotFileCallback& callback, FileSystemInterface* file_system); // Opens the file at |file_path| with options |file_flags|. // Called from FileSystemProxy::OpenFile. void OpenFile(const base::FilePath& file_path, int file_flags, const OpenFileCallback& callback, FileSystemInterface* file_system); // Closes the file at |file_path|. // Called from FileSystemProxy::NotifyCloseFile and // FileSystemProxy::CloseWRitableSnapshotFile. void CloseFile(const base::FilePath& file_path, FileSystemInterface* file_system); // Changes timestamp of the file at |file_path| to |last_access_time| and // |last_modified_time|. Called from FileSystemProxy::TouchFile(). void TouchFile(const base::FilePath& file_path, const base::Time& last_access_time, const base::Time& last_modified_time, const StatusCallback& callback, FileSystemInterface* file_system); } // namespace fileapi_internal } // namespace drive #endif // CHROME_BROWSER_CHROMEOS_DRIVE_FILEAPI_WORKER_H_