syncable_file_system_operation.h revision 1320f92c476a1ad9d19dba2a48c72b75566198e9
1// Copyright 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 5#ifndef CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_SYNCABLE_FILE_SYSTEM_OPERATION_H_ 6#define CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_SYNCABLE_FILE_SYSTEM_OPERATION_H_ 7 8#include <vector> 9 10#include "base/callback.h" 11#include "base/memory/ref_counted.h" 12#include "base/memory/scoped_ptr.h" 13#include "base/memory/weak_ptr.h" 14#include "base/threading/non_thread_safe.h" 15#include "storage/browser/fileapi/file_system_operation.h" 16#include "storage/browser/fileapi/file_system_url.h" 17 18namespace storage { 19class FileSystemContext; 20class FileSystemOperationContext; 21} 22 23namespace sync_file_system { 24 25class SyncableFileOperationRunner; 26 27// A wrapper class of FileSystemOperation for syncable file system. 28class SyncableFileSystemOperation 29 : public NON_EXPORTED_BASE(storage::FileSystemOperation), 30 public base::NonThreadSafe { 31 public: 32 virtual ~SyncableFileSystemOperation(); 33 34 // storage::FileSystemOperation overrides. 35 virtual void CreateFile(const storage::FileSystemURL& url, 36 bool exclusive, 37 const StatusCallback& callback) OVERRIDE; 38 virtual void CreateDirectory(const storage::FileSystemURL& url, 39 bool exclusive, 40 bool recursive, 41 const StatusCallback& callback) OVERRIDE; 42 virtual void Copy(const storage::FileSystemURL& src_url, 43 const storage::FileSystemURL& dest_url, 44 CopyOrMoveOption option, 45 const CopyProgressCallback& progress_callback, 46 const StatusCallback& callback) OVERRIDE; 47 virtual void Move(const storage::FileSystemURL& src_url, 48 const storage::FileSystemURL& dest_url, 49 CopyOrMoveOption option, 50 const StatusCallback& callback) OVERRIDE; 51 virtual void DirectoryExists(const storage::FileSystemURL& url, 52 const StatusCallback& callback) OVERRIDE; 53 virtual void FileExists(const storage::FileSystemURL& url, 54 const StatusCallback& callback) OVERRIDE; 55 virtual void GetMetadata(const storage::FileSystemURL& url, 56 const GetMetadataCallback& callback) OVERRIDE; 57 virtual void ReadDirectory(const storage::FileSystemURL& url, 58 const ReadDirectoryCallback& callback) OVERRIDE; 59 virtual void Remove(const storage::FileSystemURL& url, 60 bool recursive, 61 const StatusCallback& callback) OVERRIDE; 62 virtual void Write(const storage::FileSystemURL& url, 63 scoped_ptr<storage::FileWriterDelegate> writer_delegate, 64 scoped_ptr<net::URLRequest> blob_request, 65 const WriteCallback& callback) OVERRIDE; 66 virtual void Truncate(const storage::FileSystemURL& url, 67 int64 length, 68 const StatusCallback& callback) OVERRIDE; 69 virtual void TouchFile(const storage::FileSystemURL& url, 70 const base::Time& last_access_time, 71 const base::Time& last_modified_time, 72 const StatusCallback& callback) OVERRIDE; 73 virtual void OpenFile(const storage::FileSystemURL& url, 74 int file_flags, 75 const OpenFileCallback& callback) OVERRIDE; 76 virtual void Cancel(const StatusCallback& cancel_callback) OVERRIDE; 77 virtual void CreateSnapshotFile( 78 const storage::FileSystemURL& path, 79 const SnapshotFileCallback& callback) OVERRIDE; 80 virtual void CopyInForeignFile(const base::FilePath& src_local_disk_path, 81 const storage::FileSystemURL& dest_url, 82 const StatusCallback& callback) OVERRIDE; 83 virtual void RemoveFile(const storage::FileSystemURL& url, 84 const StatusCallback& callback) OVERRIDE; 85 virtual void RemoveDirectory(const storage::FileSystemURL& url, 86 const StatusCallback& callback) OVERRIDE; 87 virtual void CopyFileLocal(const storage::FileSystemURL& src_url, 88 const storage::FileSystemURL& dest_url, 89 CopyOrMoveOption option, 90 const CopyFileProgressCallback& progress_callback, 91 const StatusCallback& callback) OVERRIDE; 92 virtual void MoveFileLocal(const storage::FileSystemURL& src_url, 93 const storage::FileSystemURL& dest_url, 94 CopyOrMoveOption option, 95 const StatusCallback& callback) OVERRIDE; 96 virtual base::File::Error SyncGetPlatformPath( 97 const storage::FileSystemURL& url, 98 base::FilePath* platform_path) OVERRIDE; 99 100 private: 101 typedef SyncableFileSystemOperation self; 102 class QueueableTask; 103 104 // Only SyncFileSystemBackend can create a new operation directly. 105 friend class SyncFileSystemBackend; 106 107 SyncableFileSystemOperation( 108 const storage::FileSystemURL& url, 109 storage::FileSystemContext* file_system_context, 110 scoped_ptr<storage::FileSystemOperationContext> operation_context); 111 112 void DidFinish(base::File::Error status); 113 void DidWrite(const WriteCallback& callback, 114 base::File::Error result, 115 int64 bytes, 116 bool complete); 117 118 void OnCancelled(); 119 120 const storage::FileSystemURL url_; 121 122 scoped_ptr<storage::FileSystemOperation> impl_; 123 base::WeakPtr<SyncableFileOperationRunner> operation_runner_; 124 std::vector<storage::FileSystemURL> target_paths_; 125 126 StatusCallback completion_callback_; 127 128 base::WeakPtrFactory<SyncableFileSystemOperation> weak_factory_; 129 130 DISALLOW_COPY_AND_ASSIGN(SyncableFileSystemOperation); 131}; 132 133} // namespace sync_file_system 134 135#endif // CHROME_BROWSER_SYNC_FILE_SYSTEM_LOCAL_SYNCABLE_FILE_SYSTEM_OPERATION_H_ 136