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" | |
kinuko
2012/07/25 23:22:28
I think more common pattern is to have a common in
kmadhusu
2012/07/27 02:13:40
Done. Created media_device_interface.h, media_devi
| |
18 #endif | |
19 | |
20 using base::PlatformFileError; | |
21 using base::PlatformFileInfo; | |
22 | |
23 namespace fileapi { | |
24 | |
25 namespace { | |
26 | |
27 bool GetPlatformPathAndDeviceForUrl( | |
28 const FileSystemURL& url, | |
29 FilePath* platform_path, | |
30 scoped_refptr<MediaDeviceInterfaceImpl>* device) { | |
31 DCHECK(platform_path); | |
32 std::string filesystem_id; | |
33 IsolatedContext::FileInfo root; | |
34 if (!IsolatedContext::GetInstance()->CrackIsolatedPath( | |
35 url.path(), &filesystem_id, &root, platform_path)) | |
kinuko
2012/07/25 23:22:28
As we chatted offline can we call IsolatedContext:
kmadhusu
2012/07/27 02:13:40
Done.
| |
36 return false; | |
37 if (!MediaDeviceMapService::GetInstance()->GetMediaDevice(root.path.value(), | |
38 device)) { | |
39 return false; | |
40 } | |
41 return true; | |
42 } | |
43 | |
44 } // namespace | |
45 | |
46 | |
47 MediaFileUtil::MediaFileUtil() { | |
48 } | |
49 | |
50 PlatformFileError MediaFileUtil::CreateOrOpen( | |
51 FileSystemOperationContext* context, | |
52 const FileSystemURL& url, int file_flags, | |
53 PlatformFile* file_handle, bool* created) { | |
54 return base::PLATFORM_FILE_ERROR_SECURITY; | |
55 } | |
56 | |
57 PlatformFileError MediaFileUtil::Close( | |
58 FileSystemOperationContext* context, | |
59 PlatformFile file_handle) { | |
60 // We don't allow open thus Close won't be called. | |
61 return base::PLATFORM_FILE_ERROR_SECURITY; | |
62 } | |
63 | |
64 PlatformFileError MediaFileUtil::EnsureFileExists( | |
65 FileSystemOperationContext* context, | |
66 const FileSystemURL& url, | |
67 bool* created) { | |
68 return base::PLATFORM_FILE_ERROR_SECURITY; | |
69 } | |
70 | |
71 PlatformFileError MediaFileUtil::CreateDirectory( | |
72 FileSystemOperationContext* context, | |
73 const FileSystemURL& url, | |
74 bool exclusive, | |
75 bool recursive) { | |
76 return base::PLATFORM_FILE_ERROR_SECURITY; | |
77 } | |
78 | |
79 PlatformFileError MediaFileUtil::GetFileInfo( | |
80 FileSystemOperationContext* context, | |
81 const FileSystemURL& url, | |
82 PlatformFileInfo* file_info, | |
83 FilePath* platform_path) { | |
84 scoped_refptr<MediaDeviceInterfaceImpl> device; | |
85 if (!GetPlatformPathAndDeviceForUrl(url, platform_path, &device)) | |
kinuko
2012/07/25 23:22:28
after r148440 url.path() will be the platform path
kmadhusu
2012/07/27 02:13:40
Done.
| |
86 return base::PLATFORM_FILE_ERROR_INVALID_URL; | |
87 return device->GetFileInfo(*platform_path, file_info); | |
88 } | |
89 | |
90 FileSystemFileUtil::AbstractFileEnumerator* | |
91 MediaFileUtil::CreateFileEnumerator( | |
92 FileSystemOperationContext* context, | |
93 const FileSystemURL& url, | |
94 bool recursive) { | |
95 FilePath platform_path; | |
96 scoped_refptr<MediaDeviceInterfaceImpl> device; | |
97 if (!GetPlatformPathAndDeviceForUrl(url, &platform_path, &device)) | |
98 return new FileSystemFileUtil::EmptyFileEnumerator(); | |
99 return device->CreateFileEnumerator(platform_path, recursive); | |
100 } | |
101 | |
102 PlatformFileError MediaFileUtil::GetLocalFilePath( | |
103 FileSystemOperationContext* context, | |
104 const FileSystemURL& file_system_url, | |
105 FilePath* local_file_path) { | |
106 return base::PLATFORM_FILE_ERROR_SECURITY; | |
107 } | |
108 | |
109 PlatformFileError MediaFileUtil::Touch( | |
110 FileSystemOperationContext* context, | |
111 const FileSystemURL& url, | |
112 const base::Time& last_access_time, | |
113 const base::Time& last_modified_time) { | |
114 FilePath platform_path; | |
115 scoped_refptr<MediaDeviceInterfaceImpl> device; | |
116 if (!GetPlatformPathAndDeviceForUrl(url, &platform_path, &device)) | |
117 return base::PLATFORM_FILE_ERROR_INVALID_URL; | |
118 return device->Touch(platform_path, last_access_time, last_modified_time); | |
119 } | |
120 | |
121 PlatformFileError MediaFileUtil::Truncate( | |
122 FileSystemOperationContext* context, | |
123 const FileSystemURL& url, | |
124 int64 length) { | |
125 return base::PLATFORM_FILE_ERROR_SECURITY; | |
126 } | |
127 | |
128 bool MediaFileUtil::PathExists( | |
129 FileSystemOperationContext* context, | |
130 const FileSystemURL& url) { | |
131 FilePath platform_path; | |
132 scoped_refptr<MediaDeviceInterfaceImpl> device; | |
133 if (!GetPlatformPathAndDeviceForUrl(url, &platform_path, &device)) | |
134 return false; | |
135 return device->PathExists(platform_path); | |
136 } | |
137 | |
138 bool MediaFileUtil::DirectoryExists( | |
139 FileSystemOperationContext* context, | |
140 const FileSystemURL& url) { | |
141 FilePath platform_path; | |
142 scoped_refptr<MediaDeviceInterfaceImpl> device; | |
143 if (!GetPlatformPathAndDeviceForUrl(url, &platform_path, &device)) | |
144 return false; | |
145 return device->DirectoryExists(platform_path); | |
146 } | |
147 | |
148 bool MediaFileUtil::IsDirectoryEmpty( | |
149 FileSystemOperationContext* context, | |
150 const FileSystemURL& url) { | |
151 FilePath platform_path; | |
152 scoped_refptr<MediaDeviceInterfaceImpl> device; | |
153 if (!GetPlatformPathAndDeviceForUrl(url, &platform_path, &device)) | |
154 return false; | |
kinuko
2012/07/25 23:22:28
Maybe this should rather return true?
kmadhusu
2012/07/27 02:13:40
Done.
| |
155 return device->IsDirectoryEmpty(platform_path); | |
156 } | |
157 | |
158 PlatformFileError MediaFileUtil::CopyOrMoveFile( | |
159 FileSystemOperationContext* context, | |
160 const FileSystemURL& src_url, | |
161 const FileSystemURL& dest_url, | |
162 bool copy) { | |
163 return base::PLATFORM_FILE_ERROR_SECURITY; | |
164 } | |
165 | |
166 PlatformFileError MediaFileUtil::CopyInForeignFile( | |
167 FileSystemOperationContext* context, | |
168 const FilePath& src_file_path, | |
169 const FileSystemURL& dest_url) { | |
170 return base::PLATFORM_FILE_ERROR_SECURITY; | |
171 } | |
172 | |
173 PlatformFileError MediaFileUtil::DeleteFile( | |
174 FileSystemOperationContext* context, | |
175 const FileSystemURL& url) { | |
176 return base::PLATFORM_FILE_ERROR_SECURITY; | |
177 } | |
178 | |
179 PlatformFileError MediaFileUtil::DeleteSingleDirectory( | |
180 FileSystemOperationContext* context, | |
181 const FileSystemURL& url) { | |
182 return base::PLATFORM_FILE_ERROR_SECURITY; | |
183 } | |
184 | |
185 scoped_refptr<webkit_blob::ShareableFileReference> | |
186 MediaFileUtil::CreateSnapshotFile( | |
187 FileSystemOperationContext* context, | |
188 const FileSystemURL& url, | |
189 base::PlatformFileError* result, | |
190 base::PlatformFileInfo* file_info, | |
191 FilePath* platform_path) { | |
192 return NULL; | |
193 } | |
194 | |
195 } // namespace fileapi | |
OLD | NEW |