Chromium Code Reviews| 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 "webkit/browser/fileapi/isolated_file_util.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "webkit/browser/fileapi/async_file_util.h" | |
| 10 | 11 |
| 11 namespace chrome { | 12 namespace chrome { |
| 12 | 13 |
| 13 // This class handles native file system operations with media type filtering | 14 // This class handles native file system operations with media type filtering |
|
Lei Zhang
2013/06/03 22:42:20
One last thing: This description is out of date. C
vandebo (ex-Chrome)
2013/06/03 23:13:03
Done.
| |
| 14 // which is passed to each method via fileapi::FileSystemOperationContext as | 15 // which is passed to each method via fileapi::FileSystemOperationContext as |
| 15 // MediaPathFilter. | 16 // MediaPathFilter. |
| 16 class NativeMediaFileUtil : public fileapi::IsolatedFileUtil { | 17 class NativeMediaFileUtil : public fileapi::AsyncFileUtil { |
| 17 public: | 18 public: |
| 18 NativeMediaFileUtil(); | 19 NativeMediaFileUtil(); |
| 19 | 20 |
| 20 virtual base::PlatformFileError CreateOrOpen( | 21 // AsyncFileUtil overrides. |
| 22 virtual bool CreateOrOpen( | |
| 21 fileapi::FileSystemOperationContext* context, | 23 fileapi::FileSystemOperationContext* context, |
| 22 const fileapi::FileSystemURL& url, | 24 const fileapi::FileSystemURL& url, |
| 23 int file_flags, | 25 int file_flags, |
| 24 base::PlatformFile* file_handle, | 26 const CreateOrOpenCallback& callback) OVERRIDE; |
| 25 bool* created) OVERRIDE; | 27 virtual bool EnsureFileExists( |
| 26 virtual base::PlatformFileError EnsureFileExists( | |
| 27 fileapi::FileSystemOperationContext* context, | 28 fileapi::FileSystemOperationContext* context, |
| 28 const fileapi::FileSystemURL& url, bool* created) OVERRIDE; | 29 const fileapi::FileSystemURL& url, |
| 29 virtual scoped_ptr<AbstractFileEnumerator> CreateFileEnumerator( | 30 const EnsureFileExistsCallback& callback) OVERRIDE; |
| 31 virtual bool CreateDirectory( | |
| 30 fileapi::FileSystemOperationContext* context, | 32 fileapi::FileSystemOperationContext* context, |
| 31 const fileapi::FileSystemURL& root_url) OVERRIDE; | 33 const fileapi::FileSystemURL& url, |
| 32 virtual base::PlatformFileError Touch( | 34 bool exclusive, |
| 35 bool recursive, | |
| 36 const StatusCallback& callback) OVERRIDE; | |
| 37 virtual bool GetFileInfo( | |
| 38 fileapi::FileSystemOperationContext* context, | |
| 39 const fileapi::FileSystemURL& url, | |
| 40 const GetFileInfoCallback& callback) OVERRIDE; | |
| 41 virtual bool ReadDirectory( | |
| 42 fileapi::FileSystemOperationContext* context, | |
| 43 const fileapi::FileSystemURL& url, | |
| 44 const ReadDirectoryCallback& callback) OVERRIDE; | |
| 45 virtual bool Touch( | |
| 33 fileapi::FileSystemOperationContext* context, | 46 fileapi::FileSystemOperationContext* context, |
| 34 const fileapi::FileSystemURL& url, | 47 const fileapi::FileSystemURL& url, |
| 35 const base::Time& last_access_time, | 48 const base::Time& last_access_time, |
| 36 const base::Time& last_modified_time) OVERRIDE; | 49 const base::Time& last_modified_time, |
| 37 virtual base::PlatformFileError Truncate( | 50 const StatusCallback& callback) OVERRIDE; |
| 51 virtual bool Truncate( | |
| 38 fileapi::FileSystemOperationContext* context, | 52 fileapi::FileSystemOperationContext* context, |
| 39 const fileapi::FileSystemURL& url, | 53 const fileapi::FileSystemURL& url, |
| 40 int64 length) OVERRIDE; | 54 int64 length, |
| 41 virtual base::PlatformFileError CopyOrMoveFile( | 55 const StatusCallback& callback) OVERRIDE; |
| 56 virtual bool CopyFileLocal( | |
| 42 fileapi::FileSystemOperationContext* context, | 57 fileapi::FileSystemOperationContext* context, |
| 43 const fileapi::FileSystemURL& src_url, | 58 const fileapi::FileSystemURL& src_url, |
| 44 const fileapi::FileSystemURL& dest_url, | 59 const fileapi::FileSystemURL& dest_url, |
| 45 bool copy) OVERRIDE; | 60 const StatusCallback& callback) OVERRIDE; |
| 46 virtual base::PlatformFileError CopyInForeignFile( | 61 virtual bool MoveFileLocal( |
| 47 fileapi::FileSystemOperationContext* context, | |
| 48 const base::FilePath& src_file_path, | |
| 49 const fileapi::FileSystemURL& dest_url) OVERRIDE; | |
| 50 virtual base::PlatformFileError DeleteFile( | |
| 51 fileapi::FileSystemOperationContext* context, | 62 fileapi::FileSystemOperationContext* context, |
| 52 const fileapi::FileSystemURL& url) OVERRIDE; | 63 const fileapi::FileSystemURL& src_url, |
| 53 virtual base::PlatformFileError GetFileInfo( | 64 const fileapi::FileSystemURL& dest_url, |
| 65 const StatusCallback& callback) OVERRIDE; | |
| 66 virtual bool CopyInForeignFile( | |
| 67 fileapi::FileSystemOperationContext* context, | |
| 68 const base::FilePath& src_file_path, | |
| 69 const fileapi::FileSystemURL& dest_url, | |
| 70 const StatusCallback& callback) OVERRIDE; | |
| 71 virtual bool DeleteFile( | |
| 54 fileapi::FileSystemOperationContext* context, | 72 fileapi::FileSystemOperationContext* context, |
| 55 const fileapi::FileSystemURL& url, | 73 const fileapi::FileSystemURL& url, |
| 56 base::PlatformFileInfo* file_info, | 74 const StatusCallback& callback) OVERRIDE; |
| 57 base::FilePath* platform_path) OVERRIDE; | 75 virtual bool DeleteDirectory( |
| 58 virtual webkit_blob::ScopedFile CreateSnapshotFile( | |
| 59 fileapi::FileSystemOperationContext* context, | 76 fileapi::FileSystemOperationContext* context, |
| 60 const fileapi::FileSystemURL& url, | 77 const fileapi::FileSystemURL& url, |
| 61 base::PlatformFileError* error, | 78 const StatusCallback& callback) OVERRIDE; |
| 62 base::PlatformFileInfo* file_info, | 79 virtual bool CreateSnapshotFile( |
| 63 base::FilePath* platform_path) OVERRIDE; | 80 fileapi::FileSystemOperationContext* context, |
| 81 const fileapi::FileSystemURL& url, | |
| 82 const CreateSnapshotFileCallback& callback) OVERRIDE; | |
| 64 | 83 |
| 65 // Uses the MIME sniffer code, which actually looks into the file, | 84 // Uses the MIME sniffer code, which actually looks into the file, |
| 66 // to determine if it is really a media file (to avoid exposing | 85 // to determine if it is really a media file (to avoid exposing |
| 67 // non-media files with a media file extension.) | 86 // non-media files with a media file extension.) |
| 68 static base::PlatformFileError IsMediaFile(const base::FilePath& path); | 87 static base::PlatformFileError IsMediaFile(const base::FilePath& path); |
| 69 | 88 |
| 89 protected: | |
| 90 // The following methods should only be called on the task runner thread. | |
| 91 | |
| 92 // Necessary for copy/move to succeed. | |
| 93 virtual base::PlatformFileError CreateDirectorySync( | |
| 94 fileapi::FileSystemOperationContext* context, | |
| 95 const fileapi::FileSystemURL& url, | |
| 96 bool exclusive, | |
| 97 bool recursive); | |
| 98 virtual base::PlatformFileError CopyOrMoveFileSync( | |
| 99 fileapi::FileSystemOperationContext* context, | |
| 100 const fileapi::FileSystemURL& src_url, | |
| 101 const fileapi::FileSystemURL& dest_url, | |
| 102 bool copy); | |
| 103 virtual base::PlatformFileError CopyInForeignFileSync( | |
| 104 fileapi::FileSystemOperationContext* context, | |
| 105 const base::FilePath& src_file_path, | |
| 106 const fileapi::FileSystemURL& dest_url); | |
| 107 virtual base::PlatformFileError GetFileInfoSync( | |
| 108 fileapi::FileSystemOperationContext* context, | |
| 109 const fileapi::FileSystemURL& url, | |
| 110 base::PlatformFileInfo* file_info, | |
| 111 base::FilePath* platform_path); | |
| 112 // Called by GetFileInfoSync. Meant to be overridden by subclasses that | |
| 113 // have special mappings from URLs to platform paths (virtual filesystems). | |
| 114 virtual base::PlatformFileError GetLocalFilePath( | |
| 115 fileapi::FileSystemOperationContext* context, | |
| 116 const fileapi::FileSystemURL& file_system_url, | |
| 117 base::FilePath* local_file_path); | |
| 118 virtual base::PlatformFileError ReadDirectorySync( | |
| 119 fileapi::FileSystemOperationContext* context, | |
| 120 const fileapi::FileSystemURL& url, | |
| 121 EntryList* file_list); | |
| 122 // Necessary for move to succeed. | |
| 123 virtual base::PlatformFileError DeleteDirectorySync( | |
| 124 fileapi::FileSystemOperationContext* context, | |
| 125 const fileapi::FileSystemURL& url); | |
| 126 virtual base::PlatformFileError CreateSnapshotFileSync( | |
| 127 fileapi::FileSystemOperationContext* context, | |
| 128 const fileapi::FileSystemURL& url, | |
| 129 base::PlatformFileInfo* file_info, | |
| 130 base::FilePath* platform_path, | |
| 131 scoped_refptr<webkit_blob::ShareableFileReference>* file_ref); | |
| 132 | |
| 70 private: | 133 private: |
| 71 // Like GetLocalFilePath(), but always take media_path_filter() into | 134 // Like GetLocalFilePath(), but always take media_path_filter() into |
| 72 // consideration. If the media_path_filter() check fails, return | 135 // consideration. If the media_path_filter() check fails, return |
| 73 // PLATFORM_FILE_ERROR_SECURITY. |local_file_path| does not have to exist. | 136 // PLATFORM_FILE_ERROR_SECURITY. |local_file_path| does not have to exist. |
| 74 base::PlatformFileError GetFilteredLocalFilePath( | 137 base::PlatformFileError GetFilteredLocalFilePath( |
| 75 fileapi::FileSystemOperationContext* context, | 138 fileapi::FileSystemOperationContext* context, |
| 76 const fileapi::FileSystemURL& file_system_url, | 139 const fileapi::FileSystemURL& file_system_url, |
| 77 base::FilePath* local_file_path); | 140 base::FilePath* local_file_path); |
| 78 | 141 |
| 79 // Like GetLocalFilePath(), but if the file does not exist, then return | 142 // Like GetLocalFilePath(), but if the file does not exist, then return |
| 80 // |failure_error|. | 143 // |failure_error|. |
| 81 // If |local_file_path| is a file, then take media_path_filter() into | 144 // If |local_file_path| is a file, then take media_path_filter() into |
| 82 // consideration. | 145 // consideration. |
| 83 // If the media_path_filter() check fails, return |failure_error|. | 146 // If the media_path_filter() check fails, return |failure_error|. |
| 84 // If |local_file_path| is a directory, return PLATFORM_FILE_OK. | 147 // If |local_file_path| is a directory, return PLATFORM_FILE_OK. |
| 85 base::PlatformFileError GetFilteredLocalFilePathForExistingFileOrDirectory( | 148 base::PlatformFileError GetFilteredLocalFilePathForExistingFileOrDirectory( |
| 86 fileapi::FileSystemOperationContext* context, | 149 fileapi::FileSystemOperationContext* context, |
| 87 const fileapi::FileSystemURL& file_system_url, | 150 const fileapi::FileSystemURL& file_system_url, |
| 88 base::PlatformFileError failure_error, | 151 base::PlatformFileError failure_error, |
| 89 base::FilePath* local_file_path); | 152 base::FilePath* local_file_path); |
| 90 | 153 |
| 154 virtual void CreateDirectoryOnTaskRunnerThread( | |
| 155 fileapi::FileSystemOperationContext* context, | |
| 156 const fileapi::FileSystemURL& url, | |
| 157 bool exclusive, | |
| 158 bool recursive, | |
| 159 const StatusCallback& callback); | |
| 160 virtual void GetFileInfoOnTaskRunnerThread( | |
| 161 fileapi::FileSystemOperationContext* context, | |
| 162 const fileapi::FileSystemURL& url, | |
| 163 const GetFileInfoCallback& callback); | |
| 164 virtual void ReadDirectoryOnTaskRunnerThread( | |
| 165 fileapi::FileSystemOperationContext* context, | |
| 166 const fileapi::FileSystemURL& url, | |
| 167 const ReadDirectoryCallback& callback); | |
| 168 virtual void CopyOrMoveFileLocalOnTaskRunnerThread( | |
| 169 fileapi::FileSystemOperationContext* context, | |
| 170 const fileapi::FileSystemURL& src_url, | |
| 171 const fileapi::FileSystemURL& dest_url, | |
| 172 bool copy, | |
| 173 const StatusCallback& callback); | |
| 174 virtual void CopyInForeignFileOnTaskRunnerThread( | |
| 175 fileapi::FileSystemOperationContext* context, | |
| 176 const base::FilePath& src_file_path, | |
| 177 const fileapi::FileSystemURL& dest_url, | |
| 178 const StatusCallback& callback); | |
| 179 virtual void DeleteDirectoryOnTaskRunnerThread( | |
| 180 fileapi::FileSystemOperationContext* context, | |
| 181 const fileapi::FileSystemURL& url, | |
| 182 const StatusCallback& callback); | |
| 183 virtual void CreateSnapshotFileOnTaskRunnerThread( | |
| 184 fileapi::FileSystemOperationContext* context, | |
| 185 const fileapi::FileSystemURL& url, | |
| 186 const CreateSnapshotFileCallback& callback); | |
| 187 | |
| 188 base::WeakPtrFactory<NativeMediaFileUtil> weak_factory_; | |
| 189 | |
| 91 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtil); | 190 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtil); |
| 92 }; | 191 }; |
| 93 | 192 |
| 94 } // namespace chrome | 193 } // namespace chrome |
| 95 | 194 |
| 96 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ | 195 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ |
| OLD | NEW |