| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ |
| 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ |
| 7 | 7 |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "webkit/browser/fileapi/async_file_util.h" | 10 #include "webkit/browser/fileapi/async_file_util.h" |
| 11 | 11 |
| 12 namespace chrome { | 12 namespace chrome { |
| 13 | 13 |
| 14 // This class handles native file system operations with media type filtering. | 14 // This class handles native file system operations with media type filtering. |
| 15 // To support virtual file systems it implements the AsyncFileUtil interface | 15 // To support virtual file systems it implements the AsyncFileUtil interface |
| 16 // from scratch and provides synchronous override points. | 16 // from scratch and provides synchronous override points. |
| 17 class NativeMediaFileUtil : public fileapi::AsyncFileUtil { | 17 class NativeMediaFileUtil : public fileapi::AsyncFileUtil { |
| 18 public: | 18 public: |
| 19 NativeMediaFileUtil(); | 19 NativeMediaFileUtil(); |
| 20 virtual ~NativeMediaFileUtil(); | 20 virtual ~NativeMediaFileUtil(); |
| 21 | 21 |
| 22 // Uses the MIME sniffer code, which actually looks into the file, |
| 23 // to determine if it is really a media file (to avoid exposing |
| 24 // non-media files with a media file extension.) |
| 25 static base::PlatformFileError IsMediaFile(const base::FilePath& path); |
| 26 |
| 22 // AsyncFileUtil overrides. | 27 // AsyncFileUtil overrides. |
| 23 virtual bool CreateOrOpen( | 28 virtual bool CreateOrOpen( |
| 24 fileapi::FileSystemOperationContext* context, | 29 fileapi::FileSystemOperationContext* context, |
| 25 const fileapi::FileSystemURL& url, | 30 const fileapi::FileSystemURL& url, |
| 26 int file_flags, | 31 int file_flags, |
| 27 const CreateOrOpenCallback& callback) OVERRIDE; | 32 const CreateOrOpenCallback& callback) OVERRIDE; |
| 28 virtual bool EnsureFileExists( | 33 virtual bool EnsureFileExists( |
| 29 fileapi::FileSystemOperationContext* context, | 34 fileapi::FileSystemOperationContext* context, |
| 30 const fileapi::FileSystemURL& url, | 35 const fileapi::FileSystemURL& url, |
| 31 const EnsureFileExistsCallback& callback) OVERRIDE; | 36 const EnsureFileExistsCallback& callback) OVERRIDE; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 const StatusCallback& callback) OVERRIDE; | 80 const StatusCallback& callback) OVERRIDE; |
| 76 virtual bool DeleteDirectory( | 81 virtual bool DeleteDirectory( |
| 77 fileapi::FileSystemOperationContext* context, | 82 fileapi::FileSystemOperationContext* context, |
| 78 const fileapi::FileSystemURL& url, | 83 const fileapi::FileSystemURL& url, |
| 79 const StatusCallback& callback) OVERRIDE; | 84 const StatusCallback& callback) OVERRIDE; |
| 80 virtual bool CreateSnapshotFile( | 85 virtual bool CreateSnapshotFile( |
| 81 fileapi::FileSystemOperationContext* context, | 86 fileapi::FileSystemOperationContext* context, |
| 82 const fileapi::FileSystemURL& url, | 87 const fileapi::FileSystemURL& url, |
| 83 const CreateSnapshotFileCallback& callback) OVERRIDE; | 88 const CreateSnapshotFileCallback& callback) OVERRIDE; |
| 84 | 89 |
| 85 // Uses the MIME sniffer code, which actually looks into the file, | 90 protected: |
| 86 // to determine if it is really a media file (to avoid exposing | 91 virtual void CreateDirectoryOnTaskRunnerThread( |
| 87 // non-media files with a media file extension.) | 92 fileapi::FileSystemOperationContext* context, |
| 88 static base::PlatformFileError IsMediaFile(const base::FilePath& path); | 93 const fileapi::FileSystemURL& url, |
| 94 bool exclusive, |
| 95 bool recursive, |
| 96 const StatusCallback& callback); |
| 97 virtual void GetFileInfoOnTaskRunnerThread( |
| 98 fileapi::FileSystemOperationContext* context, |
| 99 const fileapi::FileSystemURL& url, |
| 100 const GetFileInfoCallback& callback); |
| 101 virtual void ReadDirectoryOnTaskRunnerThread( |
| 102 fileapi::FileSystemOperationContext* context, |
| 103 const fileapi::FileSystemURL& url, |
| 104 const ReadDirectoryCallback& callback); |
| 105 virtual void CopyOrMoveFileLocalOnTaskRunnerThread( |
| 106 fileapi::FileSystemOperationContext* context, |
| 107 const fileapi::FileSystemURL& src_url, |
| 108 const fileapi::FileSystemURL& dest_url, |
| 109 bool copy, |
| 110 const StatusCallback& callback); |
| 111 virtual void CopyInForeignFileOnTaskRunnerThread( |
| 112 fileapi::FileSystemOperationContext* context, |
| 113 const base::FilePath& src_file_path, |
| 114 const fileapi::FileSystemURL& dest_url, |
| 115 const StatusCallback& callback); |
| 116 virtual void DeleteDirectoryOnTaskRunnerThread( |
| 117 fileapi::FileSystemOperationContext* context, |
| 118 const fileapi::FileSystemURL& url, |
| 119 const StatusCallback& callback); |
| 120 virtual void CreateSnapshotFileOnTaskRunnerThread( |
| 121 fileapi::FileSystemOperationContext* context, |
| 122 const fileapi::FileSystemURL& url, |
| 123 const CreateSnapshotFileCallback& callback); |
| 89 | 124 |
| 90 protected: | |
| 91 // The following methods should only be called on the task runner thread. | 125 // The following methods should only be called on the task runner thread. |
| 92 | 126 |
| 93 // Necessary for copy/move to succeed. | 127 // Necessary for copy/move to succeed. |
| 94 virtual base::PlatformFileError CreateDirectorySync( | 128 virtual base::PlatformFileError CreateDirectorySync( |
| 95 fileapi::FileSystemOperationContext* context, | 129 fileapi::FileSystemOperationContext* context, |
| 96 const fileapi::FileSystemURL& url, | 130 const fileapi::FileSystemURL& url, |
| 97 bool exclusive, | 131 bool exclusive, |
| 98 bool recursive); | 132 bool recursive); |
| 99 virtual base::PlatformFileError CopyOrMoveFileSync( | 133 virtual base::PlatformFileError CopyOrMoveFileSync( |
| 100 fileapi::FileSystemOperationContext* context, | 134 fileapi::FileSystemOperationContext* context, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // If |local_file_path| is a file, then take media_path_filter() into | 179 // If |local_file_path| is a file, then take media_path_filter() into |
| 146 // consideration. | 180 // consideration. |
| 147 // If the media_path_filter() check fails, return |failure_error|. | 181 // If the media_path_filter() check fails, return |failure_error|. |
| 148 // If |local_file_path| is a directory, return PLATFORM_FILE_OK. | 182 // If |local_file_path| is a directory, return PLATFORM_FILE_OK. |
| 149 base::PlatformFileError GetFilteredLocalFilePathForExistingFileOrDirectory( | 183 base::PlatformFileError GetFilteredLocalFilePathForExistingFileOrDirectory( |
| 150 fileapi::FileSystemOperationContext* context, | 184 fileapi::FileSystemOperationContext* context, |
| 151 const fileapi::FileSystemURL& file_system_url, | 185 const fileapi::FileSystemURL& file_system_url, |
| 152 base::PlatformFileError failure_error, | 186 base::PlatformFileError failure_error, |
| 153 base::FilePath* local_file_path); | 187 base::FilePath* local_file_path); |
| 154 | 188 |
| 155 virtual void CreateDirectoryOnTaskRunnerThread( | |
| 156 fileapi::FileSystemOperationContext* context, | |
| 157 const fileapi::FileSystemURL& url, | |
| 158 bool exclusive, | |
| 159 bool recursive, | |
| 160 const StatusCallback& callback); | |
| 161 virtual void GetFileInfoOnTaskRunnerThread( | |
| 162 fileapi::FileSystemOperationContext* context, | |
| 163 const fileapi::FileSystemURL& url, | |
| 164 const GetFileInfoCallback& callback); | |
| 165 virtual void ReadDirectoryOnTaskRunnerThread( | |
| 166 fileapi::FileSystemOperationContext* context, | |
| 167 const fileapi::FileSystemURL& url, | |
| 168 const ReadDirectoryCallback& callback); | |
| 169 virtual void CopyOrMoveFileLocalOnTaskRunnerThread( | |
| 170 fileapi::FileSystemOperationContext* context, | |
| 171 const fileapi::FileSystemURL& src_url, | |
| 172 const fileapi::FileSystemURL& dest_url, | |
| 173 bool copy, | |
| 174 const StatusCallback& callback); | |
| 175 virtual void CopyInForeignFileOnTaskRunnerThread( | |
| 176 fileapi::FileSystemOperationContext* context, | |
| 177 const base::FilePath& src_file_path, | |
| 178 const fileapi::FileSystemURL& dest_url, | |
| 179 const StatusCallback& callback); | |
| 180 virtual void DeleteDirectoryOnTaskRunnerThread( | |
| 181 fileapi::FileSystemOperationContext* context, | |
| 182 const fileapi::FileSystemURL& url, | |
| 183 const StatusCallback& callback); | |
| 184 virtual void CreateSnapshotFileOnTaskRunnerThread( | |
| 185 fileapi::FileSystemOperationContext* context, | |
| 186 const fileapi::FileSystemURL& url, | |
| 187 const CreateSnapshotFileCallback& callback); | |
| 188 | 189 |
| 189 base::WeakPtrFactory<NativeMediaFileUtil> weak_factory_; | 190 base::WeakPtrFactory<NativeMediaFileUtil> weak_factory_; |
| 190 | 191 |
| 191 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtil); | 192 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtil); |
| 192 }; | 193 }; |
| 193 | 194 |
| 194 } // namespace chrome | 195 } // namespace chrome |
| 195 | 196 |
| 196 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ | 197 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ |
| OLD | NEW |