| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef WEBKIT_BROWSER_FILEAPI_ASYNC_FILE_UTIL_ADAPTER_H_ | 5 #ifndef WEBKIT_BROWSER_FILEAPI_ASYNC_FILE_UTIL_ADAPTER_H_ |
| 6 #define WEBKIT_BROWSER_FILEAPI_ASYNC_FILE_UTIL_ADAPTER_H_ | 6 #define WEBKIT_BROWSER_FILEAPI_ASYNC_FILE_UTIL_ADAPTER_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "webkit/browser/fileapi/async_file_util.h" | 9 #include "webkit/browser/fileapi/async_file_util.h" |
| 10 | 10 |
| 11 namespace fileapi { | 11 namespace fileapi { |
| 12 | 12 |
| 13 class FileSystemFileUtil; | 13 class FileSystemFileUtil; |
| 14 | 14 |
| 15 // An adapter class for FileSystemFileUtil classes to provide asynchronous | 15 // An adapter class for FileSystemFileUtil classes to provide asynchronous |
| 16 // interface. | 16 // interface. |
| 17 // | 17 // |
| 18 // A filesystem can do either: | 18 // A filesystem can do either: |
| 19 // - implement a synchronous version of FileUtil by extending | 19 // - implement a synchronous version of FileUtil by extending |
| 20 // FileSystemFileUtil and atach it to this adapter, or | 20 // FileSystemFileUtil and atach it to this adapter, or |
| 21 // - directly implement AsyncFileUtil. | 21 // - directly implement AsyncFileUtil. |
| 22 // | 22 // |
| 23 // This instance (as thus this->sync_file_util_) is guaranteed to be alive |
| 24 // as far as FileSystemOperationContext given to each operation is kept alive. |
| 23 class WEBKIT_STORAGE_EXPORT_PRIVATE AsyncFileUtilAdapter | 25 class WEBKIT_STORAGE_EXPORT_PRIVATE AsyncFileUtilAdapter |
| 24 : public AsyncFileUtil { | 26 : public AsyncFileUtil { |
| 25 public: | 27 public: |
| 26 // Creates a new AsyncFileUtil for |sync_file_util|. This takes the | 28 // Creates a new AsyncFileUtil for |sync_file_util|. This takes the |
| 27 // ownership of |sync_file_util|. (This doesn't take scoped_ptr<> just | 29 // ownership of |sync_file_util|. (This doesn't take scoped_ptr<> just |
| 28 // to save extra make_scoped_ptr; in all use cases a new fresh FileUtil is | 30 // to save extra make_scoped_ptr; in all use cases a new fresh FileUtil is |
| 29 // created only for this adapter.) | 31 // created only for this adapter.) |
| 30 explicit AsyncFileUtilAdapter(FileSystemFileUtil* sync_file_util); | 32 explicit AsyncFileUtilAdapter(FileSystemFileUtil* sync_file_util); |
| 31 | 33 |
| 32 virtual ~AsyncFileUtilAdapter(); | 34 virtual ~AsyncFileUtilAdapter(); |
| 33 | 35 |
| 34 FileSystemFileUtil* sync_file_util() { | 36 FileSystemFileUtil* sync_file_util() { |
| 35 return sync_file_util_.get(); | 37 return sync_file_util_.get(); |
| 36 } | 38 } |
| 37 | 39 |
| 38 // AsyncFileUtil overrides. | 40 // AsyncFileUtil overrides. |
| 39 virtual bool CreateOrOpen( | 41 virtual bool CreateOrOpen( |
| 40 FileSystemOperationContext* context, | 42 scoped_ptr<FileSystemOperationContext> context, |
| 41 const FileSystemURL& url, | 43 const FileSystemURL& url, |
| 42 int file_flags, | 44 int file_flags, |
| 43 const CreateOrOpenCallback& callback) OVERRIDE; | 45 const CreateOrOpenCallback& callback) OVERRIDE; |
| 44 virtual bool EnsureFileExists( | 46 virtual bool EnsureFileExists( |
| 45 FileSystemOperationContext* context, | 47 scoped_ptr<FileSystemOperationContext> context, |
| 46 const FileSystemURL& url, | 48 const FileSystemURL& url, |
| 47 const EnsureFileExistsCallback& callback) OVERRIDE; | 49 const EnsureFileExistsCallback& callback) OVERRIDE; |
| 48 virtual bool CreateDirectory( | 50 virtual bool CreateDirectory( |
| 49 FileSystemOperationContext* context, | 51 scoped_ptr<FileSystemOperationContext> context, |
| 50 const FileSystemURL& url, | 52 const FileSystemURL& url, |
| 51 bool exclusive, | 53 bool exclusive, |
| 52 bool recursive, | 54 bool recursive, |
| 53 const StatusCallback& callback) OVERRIDE; | 55 const StatusCallback& callback) OVERRIDE; |
| 54 virtual bool GetFileInfo( | 56 virtual bool GetFileInfo( |
| 55 FileSystemOperationContext* context, | 57 scoped_ptr<FileSystemOperationContext> context, |
| 56 const FileSystemURL& url, | 58 const FileSystemURL& url, |
| 57 const GetFileInfoCallback& callback) OVERRIDE; | 59 const GetFileInfoCallback& callback) OVERRIDE; |
| 58 virtual bool ReadDirectory( | 60 virtual bool ReadDirectory( |
| 59 FileSystemOperationContext* context, | 61 scoped_ptr<FileSystemOperationContext> context, |
| 60 const FileSystemURL& url, | 62 const FileSystemURL& url, |
| 61 const ReadDirectoryCallback& callback) OVERRIDE; | 63 const ReadDirectoryCallback& callback) OVERRIDE; |
| 62 virtual bool Touch( | 64 virtual bool Touch( |
| 63 FileSystemOperationContext* context, | 65 scoped_ptr<FileSystemOperationContext> context, |
| 64 const FileSystemURL& url, | 66 const FileSystemURL& url, |
| 65 const base::Time& last_access_time, | 67 const base::Time& last_access_time, |
| 66 const base::Time& last_modified_time, | 68 const base::Time& last_modified_time, |
| 67 const StatusCallback& callback) OVERRIDE; | 69 const StatusCallback& callback) OVERRIDE; |
| 68 virtual bool Truncate( | 70 virtual bool Truncate( |
| 69 FileSystemOperationContext* context, | 71 scoped_ptr<FileSystemOperationContext> context, |
| 70 const FileSystemURL& url, | 72 const FileSystemURL& url, |
| 71 int64 length, | 73 int64 length, |
| 72 const StatusCallback& callback) OVERRIDE; | 74 const StatusCallback& callback) OVERRIDE; |
| 73 virtual bool CopyFileLocal( | 75 virtual bool CopyFileLocal( |
| 74 FileSystemOperationContext* context, | 76 scoped_ptr<FileSystemOperationContext> context, |
| 75 const FileSystemURL& src_url, | 77 const FileSystemURL& src_url, |
| 76 const FileSystemURL& dest_url, | 78 const FileSystemURL& dest_url, |
| 77 const StatusCallback& callback) OVERRIDE; | 79 const StatusCallback& callback) OVERRIDE; |
| 78 virtual bool MoveFileLocal( | 80 virtual bool MoveFileLocal( |
| 79 FileSystemOperationContext* context, | 81 scoped_ptr<FileSystemOperationContext> context, |
| 80 const FileSystemURL& src_url, | 82 const FileSystemURL& src_url, |
| 81 const FileSystemURL& dest_url, | 83 const FileSystemURL& dest_url, |
| 82 const StatusCallback& callback) OVERRIDE; | 84 const StatusCallback& callback) OVERRIDE; |
| 83 virtual bool CopyInForeignFile( | 85 virtual bool CopyInForeignFile( |
| 84 FileSystemOperationContext* context, | 86 scoped_ptr<FileSystemOperationContext> context, |
| 85 const base::FilePath& src_file_path, | 87 const base::FilePath& src_file_path, |
| 86 const FileSystemURL& dest_url, | 88 const FileSystemURL& dest_url, |
| 87 const StatusCallback& callback) OVERRIDE; | 89 const StatusCallback& callback) OVERRIDE; |
| 88 virtual bool DeleteFile( | 90 virtual bool DeleteFile( |
| 89 FileSystemOperationContext* context, | 91 scoped_ptr<FileSystemOperationContext> context, |
| 90 const FileSystemURL& url, | 92 const FileSystemURL& url, |
| 91 const StatusCallback& callback) OVERRIDE; | 93 const StatusCallback& callback) OVERRIDE; |
| 92 virtual bool DeleteDirectory( | 94 virtual bool DeleteDirectory( |
| 93 FileSystemOperationContext* context, | 95 scoped_ptr<FileSystemOperationContext> context, |
| 94 const FileSystemURL& url, | 96 const FileSystemURL& url, |
| 95 const StatusCallback& callback) OVERRIDE; | 97 const StatusCallback& callback) OVERRIDE; |
| 96 virtual bool CreateSnapshotFile( | 98 virtual bool CreateSnapshotFile( |
| 97 FileSystemOperationContext* context, | 99 scoped_ptr<FileSystemOperationContext> context, |
| 98 const FileSystemURL& url, | 100 const FileSystemURL& url, |
| 99 const CreateSnapshotFileCallback& callback) OVERRIDE; | 101 const CreateSnapshotFileCallback& callback) OVERRIDE; |
| 100 | 102 |
| 101 private: | 103 private: |
| 102 scoped_ptr<FileSystemFileUtil> sync_file_util_; | 104 scoped_ptr<FileSystemFileUtil> sync_file_util_; |
| 103 | 105 |
| 104 DISALLOW_COPY_AND_ASSIGN(AsyncFileUtilAdapter); | 106 DISALLOW_COPY_AND_ASSIGN(AsyncFileUtilAdapter); |
| 105 }; | 107 }; |
| 106 | 108 |
| 107 } // namespace fileapi | 109 } // namespace fileapi |
| 108 | 110 |
| 109 #endif // WEBKIT_BROWSER_FILEAPI_ASYNC_FILE_UTIL_ADAPTER_H_ | 111 #endif // WEBKIT_BROWSER_FILEAPI_ASYNC_FILE_UTIL_ADAPTER_H_ |
| OLD | NEW |