OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "webkit/fileapi/media_file_util.h" | |
6 | |
7 #include "base/memory/scoped_ptr.h" | |
8 #include "webkit/blob/shareable_file_reference.h" | |
9 #include "webkit/fileapi/file_system_operation_context.h" | |
10 #include "webkit/fileapi/file_system_url.h" | |
11 #include "webkit/fileapi/media_device_map_service.h" | |
12 #include "webkit/fileapi/isolated_context.h" | |
13 | |
14 #if defined(OS_WIN) | |
15 #include "webkit/fileapi/mtp_device_interface_win.h" | |
16 #elif defined(OS_POSIX) && !defined(OS_MACOSX) | |
17 #include "webkit/fileapi/mtp_device_interface_linux.h" | |
18 #endif | |
19 | |
20 using base::PlatformFileError; | |
21 using base::PlatformFileInfo; | |
22 | |
23 namespace fileapi { | |
24 | |
25 MediaFileUtil::MediaFileUtil() { | |
26 } | |
27 | |
28 PlatformFileError MediaFileUtil::CreateOrOpen( | |
29 FileSystemOperationContext* context, | |
30 const FileSystemURL& url, int file_flags, | |
31 PlatformFile* file_handle, bool* created) { | |
32 return base::PLATFORM_FILE_ERROR_SECURITY; | |
33 } | |
34 | |
35 PlatformFileError MediaFileUtil::Close( | |
36 FileSystemOperationContext* context, | |
37 PlatformFile file_handle) { | |
38 // We don't allow open thus Close won't be called. | |
39 return base::PLATFORM_FILE_ERROR_SECURITY; | |
40 } | |
41 | |
42 PlatformFileError MediaFileUtil::EnsureFileExists( | |
43 FileSystemOperationContext* context, | |
44 const FileSystemURL& url, | |
45 bool* created) { | |
46 return base::PLATFORM_FILE_ERROR_SECURITY; | |
47 } | |
48 | |
49 PlatformFileError MediaFileUtil::CreateDirectory( | |
50 FileSystemOperationContext* context, | |
51 const FileSystemURL& url, | |
52 bool exclusive, | |
53 bool recursive) { | |
54 return base::PLATFORM_FILE_ERROR_SECURITY; | |
55 } | |
56 | |
57 PlatformFileError MediaFileUtil::GetFileInfo( | |
58 FileSystemOperationContext* context, | |
59 const FileSystemURL& url, | |
60 PlatformFileInfo* file_info, | |
61 FilePath* platform_path) { | |
62 if (!GetPlatformPath(url, platform_path)) | |
vandebo (ex-Chrome)
2012/07/24 21:36:55
nit: looks like you could put all of this into the
kmadhusu
2012/07/27 02:13:40
Done
| |
63 return base::PLATFORM_FILE_ERROR_INVALID_URL; | |
64 | |
65 scoped_refptr<MediaDevice> device; | |
66 if (!MediaDeviceMapService::GetInstance()->GetMediaDevice( | |
67 platform_path->value(), &device)) { | |
68 return base::PLATFORM_FILE_ERROR_INVALID_URL; | |
69 } | |
70 return device->GetFileInfo(*platform_path, file_info); | |
71 } | |
72 | |
73 FileSystemFileUtil::AbstractFileEnumerator* | |
74 MediaFileUtil::CreateFileEnumerator( | |
75 FileSystemOperationContext* context, | |
76 const FileSystemURL& root, | |
77 bool recursive) { | |
78 FilePath platform_path; | |
79 if (!GetPlatformPath(root, &platform_path)) | |
80 return new FileSystemFileUtil::EmptyFileEnumerator(); | |
81 | |
82 scoped_refptr<MediaDevice> device; | |
83 if (!MediaDeviceMapService::GetInstance()->GetMediaDevice( | |
84 platform_path.value(), &device)) { | |
85 return new FileSystemFileUtil::EmptyFileEnumerator(); | |
86 } | |
87 return device->CreateFileEnumerator(platform_path, recursive); | |
88 } | |
89 | |
90 PlatformFileError MediaFileUtil::GetLocalFilePath( | |
91 FileSystemOperationContext* context, | |
92 const FileSystemURL& file_system_url, | |
93 FilePath* local_file_path) { | |
94 return base::PLATFORM_FILE_ERROR_SECURITY; | |
95 } | |
96 | |
97 PlatformFileError MediaFileUtil::Touch( | |
98 FileSystemOperationContext* context, | |
99 const FileSystemURL& url, | |
100 const base::Time& last_access_time, | |
101 const base::Time& last_modified_time) { | |
102 FilePath platform_path; | |
103 if (!GetPlatformPath(url, &platform_path)) | |
104 return base::PLATFORM_FILE_ERROR_INVALID_URL; | |
105 | |
106 scoped_refptr<MediaDevice> device; | |
107 if (!MediaDeviceMapService::GetInstance()->GetMediaDevice( | |
108 platform_path.value(), &device)) { | |
109 return base::PLATFORM_FILE_ERROR_INVALID_URL; | |
110 } | |
111 return device->Touch(platform_path, last_access_time, last_modified_time); | |
112 } | |
113 | |
114 PlatformFileError MediaFileUtil::Truncate( | |
115 FileSystemOperationContext* context, | |
116 const FileSystemURL& url, | |
117 int64 length) { | |
118 return base::PLATFORM_FILE_ERROR_SECURITY; | |
119 } | |
120 | |
121 bool MediaFileUtil::PathExists( | |
122 FileSystemOperationContext* context, | |
123 const FileSystemURL& url) { | |
124 FilePath platform_path; | |
125 if (!GetPlatformPath(url, &platform_path)) | |
126 return false; | |
127 | |
128 scoped_refptr<MediaDevice> device; | |
129 if (!MediaDeviceMapService::GetInstance()->GetMediaDevice( | |
130 platform_path.value(), &device)) { | |
131 return false; | |
132 } | |
133 return device->PathExists(platform_path); | |
134 } | |
135 | |
136 bool MediaFileUtil::DirectoryExists( | |
137 FileSystemOperationContext* context, | |
138 const FileSystemURL& url) { | |
139 FilePath platform_path; | |
140 if (!GetPlatformPath(url, &platform_path)) | |
141 return false; | |
142 | |
143 scoped_refptr<MediaDevice> device; | |
144 if (!MediaDeviceMapService::GetInstance()->GetMediaDevice( | |
145 platform_path.value(), &device)) { | |
146 return false; | |
147 } | |
148 return device->DirectoryExists(platform_path); | |
149 } | |
150 | |
151 bool MediaFileUtil::IsDirectoryEmpty( | |
152 FileSystemOperationContext* context, | |
153 const FileSystemURL& url) { | |
154 FilePath platform_path; | |
155 if (!GetPlatformPath(url, &platform_path)) | |
156 return false; | |
157 | |
158 scoped_refptr<MediaDevice> device; | |
159 if (!MediaDeviceMapService::GetInstance()->GetMediaDevice( | |
160 platform_path.value(), &device)) { | |
161 return false; | |
162 } | |
163 return device->IsDirectoryEmpty(platform_path); | |
164 } | |
165 | |
166 PlatformFileError MediaFileUtil::CopyOrMoveFile( | |
167 FileSystemOperationContext* context, | |
168 const FileSystemURL& src_url, | |
169 const FileSystemURL& dest_url, | |
170 bool copy) { | |
171 return base::PLATFORM_FILE_ERROR_SECURITY; | |
172 } | |
173 | |
174 PlatformFileError MediaFileUtil::CopyInForeignFile( | |
175 FileSystemOperationContext* context, | |
176 const FilePath& src_file_path, | |
177 const FileSystemURL& dest_url) { | |
178 return base::PLATFORM_FILE_ERROR_SECURITY; | |
179 } | |
180 | |
181 PlatformFileError MediaFileUtil::DeleteFile( | |
182 FileSystemOperationContext* context, | |
183 const FileSystemURL& url) { | |
184 return base::PLATFORM_FILE_ERROR_SECURITY; | |
185 } | |
186 | |
187 PlatformFileError MediaFileUtil::DeleteSingleDirectory( | |
188 FileSystemOperationContext* context, | |
189 const FileSystemURL& url) { | |
190 return base::PLATFORM_FILE_ERROR_SECURITY; | |
191 } | |
192 | |
193 scoped_refptr<webkit_blob::ShareableFileReference> | |
194 MediaFileUtil::CreateSnapshotFile( | |
195 FileSystemOperationContext* context, | |
196 const FileSystemURL& url, | |
197 base::PlatformFileError* result, | |
198 base::PlatformFileInfo* file_info, | |
199 FilePath* platform_path) { | |
200 return NULL; | |
201 } | |
202 | |
203 bool MediaFileUtil::GetPlatformPath(const FileSystemURL& url, | |
204 FilePath* platform_path) const { | |
205 DCHECK(platform_path); | |
206 std::string filesystem_id; | |
207 if (!IsolatedContext::GetInstance()->CrackIsolatedPath( | |
208 url.path(), &filesystem_id, NULL, platform_path)) | |
209 return false; | |
210 return true; | |
211 } | |
212 | |
213 } // namespace | |
OLD | NEW |