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 "webkit/browser/fileapi/async_file_util.h" |
10 | 10 |
11 namespace chrome { | 11 namespace chrome { |
12 | 12 |
13 // This class handles native file system operations with media type filtering | 13 // This class handles native file system operations with media type filtering |
14 // which is passed to each method via fileapi::FileSystemOperationContext as | 14 // which is passed to each method via fileapi::FileSystemOperationContext as |
15 // MediaPathFilter. | 15 // MediaPathFilter. |
16 class NativeMediaFileUtil : public fileapi::IsolatedFileUtil { | 16 class NativeMediaFileUtil : public fileapi::AsyncFileUtil { |
17 public: | 17 public: |
18 NativeMediaFileUtil(); | 18 NativeMediaFileUtil(); |
19 | 19 |
20 virtual base::PlatformFileError CreateOrOpen( | 20 // AsyncFileUtil overrides. |
| 21 virtual bool CreateOrOpen( |
21 fileapi::FileSystemOperationContext* context, | 22 fileapi::FileSystemOperationContext* context, |
22 const fileapi::FileSystemURL& url, | 23 const fileapi::FileSystemURL& url, |
23 int file_flags, | 24 int file_flags, |
24 base::PlatformFile* file_handle, | 25 const CreateOrOpenCallback& callback) OVERRIDE; |
25 bool* created) OVERRIDE; | 26 virtual bool EnsureFileExists( |
26 virtual base::PlatformFileError EnsureFileExists( | |
27 fileapi::FileSystemOperationContext* context, | 27 fileapi::FileSystemOperationContext* context, |
28 const fileapi::FileSystemURL& url, bool* created) OVERRIDE; | 28 const fileapi::FileSystemURL& url, |
29 virtual scoped_ptr<AbstractFileEnumerator> CreateFileEnumerator( | 29 const EnsureFileExistsCallback& callback) OVERRIDE; |
| 30 virtual bool CreateDirectory( |
30 fileapi::FileSystemOperationContext* context, | 31 fileapi::FileSystemOperationContext* context, |
31 const fileapi::FileSystemURL& root_url) OVERRIDE; | 32 const fileapi::FileSystemURL& url, |
32 virtual base::PlatformFileError Touch( | 33 bool exclusive, |
| 34 bool recursive, |
| 35 const StatusCallback& callback) OVERRIDE; |
| 36 virtual bool GetFileInfo( |
| 37 fileapi::FileSystemOperationContext* context, |
| 38 const fileapi::FileSystemURL& url, |
| 39 const GetFileInfoCallback& callback) OVERRIDE; |
| 40 virtual bool ReadDirectory( |
| 41 fileapi::FileSystemOperationContext* context, |
| 42 const fileapi::FileSystemURL& url, |
| 43 const ReadDirectoryCallback& callback) OVERRIDE; |
| 44 virtual bool Touch( |
33 fileapi::FileSystemOperationContext* context, | 45 fileapi::FileSystemOperationContext* context, |
34 const fileapi::FileSystemURL& url, | 46 const fileapi::FileSystemURL& url, |
35 const base::Time& last_access_time, | 47 const base::Time& last_access_time, |
36 const base::Time& last_modified_time) OVERRIDE; | 48 const base::Time& last_modified_time, |
37 virtual base::PlatformFileError Truncate( | 49 const StatusCallback& callback) OVERRIDE; |
| 50 virtual bool Truncate( |
38 fileapi::FileSystemOperationContext* context, | 51 fileapi::FileSystemOperationContext* context, |
39 const fileapi::FileSystemURL& url, | 52 const fileapi::FileSystemURL& url, |
40 int64 length) OVERRIDE; | 53 int64 length, |
41 virtual base::PlatformFileError CopyOrMoveFile( | 54 const StatusCallback& callback) OVERRIDE; |
| 55 virtual bool CopyFileLocal( |
42 fileapi::FileSystemOperationContext* context, | 56 fileapi::FileSystemOperationContext* context, |
43 const fileapi::FileSystemURL& src_url, | 57 const fileapi::FileSystemURL& src_url, |
44 const fileapi::FileSystemURL& dest_url, | 58 const fileapi::FileSystemURL& dest_url, |
45 bool copy) OVERRIDE; | 59 const StatusCallback& callback) OVERRIDE; |
46 virtual base::PlatformFileError CopyInForeignFile( | 60 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, | 61 fileapi::FileSystemOperationContext* context, |
52 const fileapi::FileSystemURL& url) OVERRIDE; | 62 const fileapi::FileSystemURL& src_url, |
53 virtual base::PlatformFileError GetFileInfo( | 63 const fileapi::FileSystemURL& dest_url, |
| 64 const StatusCallback& callback) OVERRIDE; |
| 65 virtual bool CopyInForeignFile( |
| 66 fileapi::FileSystemOperationContext* context, |
| 67 const base::FilePath& src_file_path, |
| 68 const fileapi::FileSystemURL& dest_url, |
| 69 const StatusCallback& callback) OVERRIDE; |
| 70 virtual bool DeleteFile( |
54 fileapi::FileSystemOperationContext* context, | 71 fileapi::FileSystemOperationContext* context, |
55 const fileapi::FileSystemURL& url, | 72 const fileapi::FileSystemURL& url, |
56 base::PlatformFileInfo* file_info, | 73 const StatusCallback& callback) OVERRIDE; |
57 base::FilePath* platform_path) OVERRIDE; | 74 virtual bool DeleteDirectory( |
58 virtual webkit_blob::ScopedFile CreateSnapshotFile( | |
59 fileapi::FileSystemOperationContext* context, | 75 fileapi::FileSystemOperationContext* context, |
60 const fileapi::FileSystemURL& url, | 76 const fileapi::FileSystemURL& url, |
61 base::PlatformFileError* error, | 77 const StatusCallback& callback) OVERRIDE; |
62 base::PlatformFileInfo* file_info, | 78 virtual bool CreateSnapshotFile( |
63 base::FilePath* platform_path) OVERRIDE; | 79 fileapi::FileSystemOperationContext* context, |
| 80 const fileapi::FileSystemURL& url, |
| 81 const CreateSnapshotFileCallback& callback) OVERRIDE; |
64 | 82 |
65 // Uses the MIME sniffer code, which actually looks into the file, | 83 // Uses the MIME sniffer code, which actually looks into the file, |
66 // to determine if it is really a media file (to avoid exposing | 84 // to determine if it is really a media file (to avoid exposing |
67 // non-media files with a media file extension.) | 85 // non-media files with a media file extension.) |
68 static base::PlatformFileError IsMediaFile(const base::FilePath& path); | 86 static base::PlatformFileError IsMediaFile(const base::FilePath& path); |
69 | 87 |
| 88 protected: |
| 89 // Necessary for copy/move to succeed. |
| 90 virtual base::PlatformFileError CreateDirectorySync( |
| 91 fileapi::FileSystemOperationContext* context, |
| 92 const fileapi::FileSystemURL& url, |
| 93 bool exclusive, |
| 94 bool recursive); |
| 95 // Used by MoveFile and CopyFile. |
| 96 virtual base::PlatformFileError CopyOrMoveFileSync( |
| 97 fileapi::FileSystemOperationContext* context, |
| 98 const fileapi::FileSystemURL& src_url, |
| 99 const fileapi::FileSystemURL& dest_url, |
| 100 bool copy); |
| 101 // Used by CopyInForeignFile |
| 102 virtual base::PlatformFileError CopyInForeignFileSync( |
| 103 fileapi::FileSystemOperationContext* context, |
| 104 const base::FilePath& src_file_path, |
| 105 const fileapi::FileSystemURL& dest_url); |
| 106 // Synchronous for convenience reasons. Call only on the task runner thread. |
| 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 // Posted by ReadDirectory onto the task runner thread. |
| 119 virtual base::PlatformFileError ReadDirectorySync( |
| 120 fileapi::FileSystemOperationContext* context, |
| 121 const fileapi::FileSystemURL& url, |
| 122 EntryList* file_list); |
| 123 // Necessary for copy/move to succeed. |
| 124 virtual base::PlatformFileError DeleteDirectorySync( |
| 125 fileapi::FileSystemOperationContext* context, |
| 126 const fileapi::FileSystemURL& url); |
| 127 virtual base::PlatformFileError CreateSnapshotFileSync( |
| 128 fileapi::FileSystemOperationContext* context, |
| 129 const fileapi::FileSystemURL& url, |
| 130 base::PlatformFileInfo* file_info, |
| 131 base::FilePath* platform_path, |
| 132 scoped_refptr<webkit_blob::ShareableFileReference>* file_ref); |
| 133 |
70 private: | 134 private: |
71 // Like GetLocalFilePath(), but always take media_path_filter() into | 135 // Like GetLocalFilePath(), but always take media_path_filter() into |
72 // consideration. If the media_path_filter() check fails, return | 136 // consideration. If the media_path_filter() check fails, return |
73 // PLATFORM_FILE_ERROR_SECURITY. |local_file_path| does not have to exist. | 137 // PLATFORM_FILE_ERROR_SECURITY. |local_file_path| does not have to exist. |
74 base::PlatformFileError GetFilteredLocalFilePath( | 138 base::PlatformFileError GetFilteredLocalFilePath( |
75 fileapi::FileSystemOperationContext* context, | 139 fileapi::FileSystemOperationContext* context, |
76 const fileapi::FileSystemURL& file_system_url, | 140 const fileapi::FileSystemURL& file_system_url, |
77 base::FilePath* local_file_path); | 141 base::FilePath* local_file_path); |
78 | 142 |
79 // Like GetLocalFilePath(), but if the file does not exist, then return | 143 // Like GetLocalFilePath(), but if the file does not exist, then return |
80 // |failure_error|. | 144 // |failure_error|. |
81 // If |local_file_path| is a file, then take media_path_filter() into | 145 // If |local_file_path| is a file, then take media_path_filter() into |
82 // consideration. | 146 // consideration. |
83 // If the media_path_filter() check fails, return |failure_error|. | 147 // If the media_path_filter() check fails, return |failure_error|. |
84 // If |local_file_path| is a directory, return PLATFORM_FILE_OK. | 148 // If |local_file_path| is a directory, return PLATFORM_FILE_OK. |
85 base::PlatformFileError GetFilteredLocalFilePathForExistingFileOrDirectory( | 149 base::PlatformFileError GetFilteredLocalFilePathForExistingFileOrDirectory( |
86 fileapi::FileSystemOperationContext* context, | 150 fileapi::FileSystemOperationContext* context, |
87 const fileapi::FileSystemURL& file_system_url, | 151 const fileapi::FileSystemURL& file_system_url, |
88 base::PlatformFileError failure_error, | 152 base::PlatformFileError failure_error, |
89 base::FilePath* local_file_path); | 153 base::FilePath* local_file_path); |
90 | 154 |
91 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtil); | 155 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtil); |
92 }; | 156 }; |
93 | 157 |
94 } // namespace chrome | 158 } // namespace chrome |
95 | 159 |
96 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ | 160 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ |
OLD | NEW |