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 "storage/browser/fileapi/async_file_util.h" | 10 #include "storage/browser/fileapi/async_file_util.h" |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 class IOBuffer; | 13 class IOBuffer; |
14 } | 14 } |
15 | 15 |
16 class MediaPathFilter; | 16 class MediaPathFilter; |
17 | 17 |
18 // This class handles native file system operations with media type filtering. | 18 // This class handles native file system operations with media type filtering. |
19 // To support virtual file systems it implements the AsyncFileUtil interface | 19 // To support virtual file systems it implements the AsyncFileUtil interface |
20 // from scratch and provides synchronous override points. | 20 // from scratch and provides synchronous override points. |
21 class NativeMediaFileUtil : public storage::AsyncFileUtil { | 21 class NativeMediaFileUtil : public storage::AsyncFileUtil { |
22 public: | 22 public: |
23 explicit NativeMediaFileUtil(MediaPathFilter* media_path_filter); | 23 explicit NativeMediaFileUtil(MediaPathFilter* media_path_filter); |
24 virtual ~NativeMediaFileUtil(); | 24 ~NativeMediaFileUtil() override; |
25 | 25 |
26 // Uses the MIME sniffer code, which actually looks into the file, | 26 // Uses the MIME sniffer code, which actually looks into the file, |
27 // to determine if it is really a media file (to avoid exposing | 27 // to determine if it is really a media file (to avoid exposing |
28 // non-media files with a media file extension.) | 28 // non-media files with a media file extension.) |
29 static base::File::Error IsMediaFile(const base::FilePath& path); | 29 static base::File::Error IsMediaFile(const base::FilePath& path); |
30 static base::File::Error BufferIsMediaHeader(net::IOBuffer* buf, | 30 static base::File::Error BufferIsMediaHeader(net::IOBuffer* buf, |
31 size_t length); | 31 size_t length); |
32 | 32 |
33 // Methods to support CreateOrOpen. Public so they can be shared with | 33 // Methods to support CreateOrOpen. Public so they can be shared with |
34 // DeviceMediaAsyncFileUtil. | 34 // DeviceMediaAsyncFileUtil. |
35 static void CreatedSnapshotFileForCreateOrOpen( | 35 static void CreatedSnapshotFileForCreateOrOpen( |
36 base::SequencedTaskRunner* media_task_runner, | 36 base::SequencedTaskRunner* media_task_runner, |
37 int file_flags, | 37 int file_flags, |
38 const storage::AsyncFileUtil::CreateOrOpenCallback& callback, | 38 const storage::AsyncFileUtil::CreateOrOpenCallback& callback, |
39 base::File::Error result, | 39 base::File::Error result, |
40 const base::File::Info& file_info, | 40 const base::File::Info& file_info, |
41 const base::FilePath& platform_path, | 41 const base::FilePath& platform_path, |
42 const scoped_refptr<storage::ShareableFileReference>& file_ref); | 42 const scoped_refptr<storage::ShareableFileReference>& file_ref); |
43 | 43 |
44 // AsyncFileUtil overrides. | 44 // AsyncFileUtil overrides. |
45 virtual void CreateOrOpen( | 45 void CreateOrOpen(scoped_ptr<storage::FileSystemOperationContext> context, |
46 scoped_ptr<storage::FileSystemOperationContext> context, | 46 const storage::FileSystemURL& url, |
47 const storage::FileSystemURL& url, | 47 int file_flags, |
48 int file_flags, | 48 const CreateOrOpenCallback& callback) override; |
49 const CreateOrOpenCallback& callback) override; | 49 void EnsureFileExists(scoped_ptr<storage::FileSystemOperationContext> context, |
50 virtual void EnsureFileExists( | 50 const storage::FileSystemURL& url, |
51 scoped_ptr<storage::FileSystemOperationContext> context, | 51 const EnsureFileExistsCallback& callback) override; |
52 const storage::FileSystemURL& url, | 52 void CreateDirectory(scoped_ptr<storage::FileSystemOperationContext> context, |
53 const EnsureFileExistsCallback& callback) override; | 53 const storage::FileSystemURL& url, |
54 virtual void CreateDirectory( | 54 bool exclusive, |
55 scoped_ptr<storage::FileSystemOperationContext> context, | 55 bool recursive, |
56 const storage::FileSystemURL& url, | 56 const StatusCallback& callback) override; |
57 bool exclusive, | 57 void GetFileInfo(scoped_ptr<storage::FileSystemOperationContext> context, |
58 bool recursive, | 58 const storage::FileSystemURL& url, |
59 const StatusCallback& callback) override; | 59 const GetFileInfoCallback& callback) override; |
60 virtual void GetFileInfo( | 60 void ReadDirectory(scoped_ptr<storage::FileSystemOperationContext> context, |
61 scoped_ptr<storage::FileSystemOperationContext> context, | |
62 const storage::FileSystemURL& url, | |
63 const GetFileInfoCallback& callback) override; | |
64 virtual void ReadDirectory( | |
65 scoped_ptr<storage::FileSystemOperationContext> context, | |
66 const storage::FileSystemURL& url, | |
67 const ReadDirectoryCallback& callback) override; | |
68 virtual void Touch(scoped_ptr<storage::FileSystemOperationContext> context, | |
69 const storage::FileSystemURL& url, | 61 const storage::FileSystemURL& url, |
70 const base::Time& last_access_time, | 62 const ReadDirectoryCallback& callback) override; |
71 const base::Time& last_modified_time, | 63 void Touch(scoped_ptr<storage::FileSystemOperationContext> context, |
| 64 const storage::FileSystemURL& url, |
| 65 const base::Time& last_access_time, |
| 66 const base::Time& last_modified_time, |
| 67 const StatusCallback& callback) override; |
| 68 void Truncate(scoped_ptr<storage::FileSystemOperationContext> context, |
| 69 const storage::FileSystemURL& url, |
| 70 int64 length, |
| 71 const StatusCallback& callback) override; |
| 72 void CopyFileLocal(scoped_ptr<storage::FileSystemOperationContext> context, |
| 73 const storage::FileSystemURL& src_url, |
| 74 const storage::FileSystemURL& dest_url, |
| 75 CopyOrMoveOption option, |
| 76 const CopyFileProgressCallback& progress_callback, |
72 const StatusCallback& callback) override; | 77 const StatusCallback& callback) override; |
73 virtual void Truncate(scoped_ptr<storage::FileSystemOperationContext> context, | 78 void MoveFileLocal(scoped_ptr<storage::FileSystemOperationContext> context, |
74 const storage::FileSystemURL& url, | 79 const storage::FileSystemURL& src_url, |
75 int64 length, | 80 const storage::FileSystemURL& dest_url, |
76 const StatusCallback& callback) override; | 81 CopyOrMoveOption option, |
77 virtual void CopyFileLocal( | 82 const StatusCallback& callback) override; |
78 scoped_ptr<storage::FileSystemOperationContext> context, | 83 void CopyInForeignFile( |
79 const storage::FileSystemURL& src_url, | |
80 const storage::FileSystemURL& dest_url, | |
81 CopyOrMoveOption option, | |
82 const CopyFileProgressCallback& progress_callback, | |
83 const StatusCallback& callback) override; | |
84 virtual void MoveFileLocal( | |
85 scoped_ptr<storage::FileSystemOperationContext> context, | |
86 const storage::FileSystemURL& src_url, | |
87 const storage::FileSystemURL& dest_url, | |
88 CopyOrMoveOption option, | |
89 const StatusCallback& callback) override; | |
90 virtual void CopyInForeignFile( | |
91 scoped_ptr<storage::FileSystemOperationContext> context, | 84 scoped_ptr<storage::FileSystemOperationContext> context, |
92 const base::FilePath& src_file_path, | 85 const base::FilePath& src_file_path, |
93 const storage::FileSystemURL& dest_url, | 86 const storage::FileSystemURL& dest_url, |
94 const StatusCallback& callback) override; | 87 const StatusCallback& callback) override; |
95 virtual void DeleteFile( | 88 void DeleteFile(scoped_ptr<storage::FileSystemOperationContext> context, |
| 89 const storage::FileSystemURL& url, |
| 90 const StatusCallback& callback) override; |
| 91 void DeleteDirectory(scoped_ptr<storage::FileSystemOperationContext> context, |
| 92 const storage::FileSystemURL& url, |
| 93 const StatusCallback& callback) override; |
| 94 void DeleteRecursively( |
96 scoped_ptr<storage::FileSystemOperationContext> context, | 95 scoped_ptr<storage::FileSystemOperationContext> context, |
97 const storage::FileSystemURL& url, | 96 const storage::FileSystemURL& url, |
98 const StatusCallback& callback) override; | 97 const StatusCallback& callback) override; |
99 virtual void DeleteDirectory( | 98 void CreateSnapshotFile( |
100 scoped_ptr<storage::FileSystemOperationContext> context, | |
101 const storage::FileSystemURL& url, | |
102 const StatusCallback& callback) override; | |
103 virtual void DeleteRecursively( | |
104 scoped_ptr<storage::FileSystemOperationContext> context, | |
105 const storage::FileSystemURL& url, | |
106 const StatusCallback& callback) override; | |
107 virtual void CreateSnapshotFile( | |
108 scoped_ptr<storage::FileSystemOperationContext> context, | 99 scoped_ptr<storage::FileSystemOperationContext> context, |
109 const storage::FileSystemURL& url, | 100 const storage::FileSystemURL& url, |
110 const CreateSnapshotFileCallback& callback) override; | 101 const CreateSnapshotFileCallback& callback) override; |
111 | 102 |
112 protected: | 103 protected: |
113 virtual void CreateDirectoryOnTaskRunnerThread( | 104 virtual void CreateDirectoryOnTaskRunnerThread( |
114 scoped_ptr<storage::FileSystemOperationContext> context, | 105 scoped_ptr<storage::FileSystemOperationContext> context, |
115 const storage::FileSystemURL& url, | 106 const storage::FileSystemURL& url, |
116 bool exclusive, | 107 bool exclusive, |
117 bool recursive, | 108 bool recursive, |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 214 |
224 // Not owned, owned by the backend which owns this. | 215 // Not owned, owned by the backend which owns this. |
225 MediaPathFilter* const media_path_filter_; | 216 MediaPathFilter* const media_path_filter_; |
226 | 217 |
227 base::WeakPtrFactory<NativeMediaFileUtil> weak_factory_; | 218 base::WeakPtrFactory<NativeMediaFileUtil> weak_factory_; |
228 | 219 |
229 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtil); | 220 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtil); |
230 }; | 221 }; |
231 | 222 |
232 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ | 223 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ |
OLD | NEW |