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/device_media_file_util.h" | |
6 | |
7 #include "base/message_loop_proxy.h" | |
8 #include "base/file_util.h" | |
9 #include "base/memory/scoped_ptr.h" | |
10 #include "webkit/blob/shareable_file_reference.h" | |
11 #include "webkit/fileapi/file_system_operation_context.h" | |
12 #include "webkit/fileapi/file_system_url.h" | |
13 #include "webkit/fileapi/isolated_context.h" | |
14 #include "webkit/fileapi/media/media_device_map_service.h" | |
15 #include "webkit/fileapi/media/media_device_interface_impl.h" | |
16 | |
17 using base::PlatformFileError; | |
18 using base::PlatformFileInfo; | |
19 using webkit_blob::ShareableFileReference; | |
20 | |
21 namespace fileapi { | |
22 | |
23 namespace { | |
24 | |
25 const FilePath::CharType kIsolatedMediaFileSystemDir[] = | |
kinuko
2012/07/31 05:35:44
nit: Similarly kIsolatedMediaFileSystemDir should
kmadhusu
2012/07/31 19:47:24
kIsolatedMediaFileSystemDir -> kDeviceMediaFileUti
| |
26 FILE_PATH_LITERAL("DeviceMediaFileSystem"); | |
27 | |
28 } // namespace | |
29 | |
30 DeviceMediaFileUtil::DeviceMediaFileUtil(const FilePath& profile_path) | |
31 : profile_path_(profile_path) { | |
32 } | |
33 | |
34 PlatformFileError DeviceMediaFileUtil::CreateOrOpen( | |
35 FileSystemOperationContext* context, | |
36 const FileSystemURL& url, int file_flags, | |
37 PlatformFile* file_handle, bool* created) { | |
38 return base::PLATFORM_FILE_ERROR_SECURITY; | |
39 } | |
40 | |
41 PlatformFileError DeviceMediaFileUtil::Close( | |
42 FileSystemOperationContext* context, | |
43 PlatformFile file_handle) { | |
44 // We don't allow open thus Close won't be called. | |
45 return base::PLATFORM_FILE_ERROR_SECURITY; | |
46 } | |
47 | |
48 PlatformFileError DeviceMediaFileUtil::EnsureFileExists( | |
49 FileSystemOperationContext* context, | |
50 const FileSystemURL& url, | |
51 bool* created) { | |
52 return base::PLATFORM_FILE_ERROR_SECURITY; | |
53 } | |
54 | |
55 PlatformFileError DeviceMediaFileUtil::CreateDirectory( | |
56 FileSystemOperationContext* context, | |
57 const FileSystemURL& url, | |
58 bool exclusive, | |
59 bool recursive) { | |
60 return base::PLATFORM_FILE_ERROR_SECURITY; | |
61 } | |
62 | |
63 PlatformFileError DeviceMediaFileUtil::GetFileInfo( | |
64 FileSystemOperationContext* context, | |
65 const FileSystemURL& url, | |
66 PlatformFileInfo* file_info, | |
67 FilePath* platform_path) { | |
68 scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device()); | |
kinuko
2012/07/31 05:35:44
nit: to make sure: since now we keep a ref in Oper
kmadhusu
2012/07/31 19:47:24
Done.
| |
69 DCHECK(device.get()); | |
70 return device->GetFileInfo(url.path(), file_info); | |
71 } | |
72 | |
73 FileSystemFileUtil::AbstractFileEnumerator* | |
74 DeviceMediaFileUtil::CreateFileEnumerator( | |
75 FileSystemOperationContext* context, | |
76 const FileSystemURL& url, | |
77 bool recursive) { | |
78 scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device()); | |
79 DCHECK(device.get()); | |
80 return device->CreateFileEnumerator(url.path(), recursive); | |
81 } | |
82 | |
83 PlatformFileError DeviceMediaFileUtil::GetLocalFilePath( | |
84 FileSystemOperationContext* context, | |
85 const FileSystemURL& file_system_url, | |
86 FilePath* local_file_path) { | |
87 return base::PLATFORM_FILE_ERROR_SECURITY; | |
88 } | |
89 | |
90 PlatformFileError DeviceMediaFileUtil::Touch( | |
91 FileSystemOperationContext* context, | |
92 const FileSystemURL& url, | |
93 const base::Time& last_access_time, | |
94 const base::Time& last_modified_time) { | |
95 scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device()); | |
96 DCHECK(device.get()); | |
97 return device->Touch(url.path(), last_access_time, last_modified_time); | |
98 } | |
99 | |
100 PlatformFileError DeviceMediaFileUtil::Truncate( | |
101 FileSystemOperationContext* context, | |
102 const FileSystemURL& url, | |
103 int64 length) { | |
104 return base::PLATFORM_FILE_ERROR_SECURITY; | |
105 } | |
106 | |
107 bool DeviceMediaFileUtil::PathExists( | |
108 FileSystemOperationContext* context, | |
109 const FileSystemURL& url) { | |
110 scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device()); | |
111 DCHECK(device.get()); | |
112 return device->PathExists(url.path()); | |
113 } | |
114 | |
115 bool DeviceMediaFileUtil::DirectoryExists( | |
116 FileSystemOperationContext* context, | |
117 const FileSystemURL& url) { | |
118 scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device()); | |
119 DCHECK(device.get()); | |
120 return device->DirectoryExists(url.path()); | |
121 } | |
122 | |
123 bool DeviceMediaFileUtil::IsDirectoryEmpty( | |
124 FileSystemOperationContext* context, | |
125 const FileSystemURL& url) { | |
126 scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device()); | |
127 DCHECK(device.get()); | |
128 return device->IsDirectoryEmpty(url.path()); | |
129 } | |
130 | |
131 PlatformFileError DeviceMediaFileUtil::CopyOrMoveFile( | |
132 FileSystemOperationContext* context, | |
133 const FileSystemURL& src_url, | |
134 const FileSystemURL& dest_url, | |
135 bool copy) { | |
136 return base::PLATFORM_FILE_ERROR_SECURITY; | |
137 } | |
138 | |
139 PlatformFileError DeviceMediaFileUtil::CopyInForeignFile( | |
140 FileSystemOperationContext* context, | |
141 const FilePath& src_file_path, | |
142 const FileSystemURL& dest_url) { | |
143 return base::PLATFORM_FILE_ERROR_SECURITY; | |
144 } | |
145 | |
146 PlatformFileError DeviceMediaFileUtil::DeleteFile( | |
147 FileSystemOperationContext* context, | |
148 const FileSystemURL& url) { | |
149 return base::PLATFORM_FILE_ERROR_SECURITY; | |
150 } | |
151 | |
152 PlatformFileError DeviceMediaFileUtil::DeleteSingleDirectory( | |
153 FileSystemOperationContext* context, | |
154 const FileSystemURL& url) { | |
155 return base::PLATFORM_FILE_ERROR_SECURITY; | |
156 } | |
157 | |
158 scoped_refptr<ShareableFileReference> DeviceMediaFileUtil::CreateSnapshotFile( | |
159 FileSystemOperationContext* context, | |
160 const FileSystemURL& url, | |
161 base::PlatformFileError* result, | |
162 base::PlatformFileInfo* file_info, | |
163 FilePath* local_path) { | |
164 DCHECK(result); | |
165 DCHECK(file_info); | |
166 DCHECK(local_path); | |
167 | |
168 scoped_refptr<ShareableFileReference> file_ref; | |
169 *result = base::PLATFORM_FILE_ERROR_INVALID_URL; | |
kinuko
2012/07/31 05:35:44
nit: maybe we can simply initialize this to PLATFO
kmadhusu
2012/07/31 19:47:24
Done.
| |
170 | |
171 scoped_refptr<MediaDeviceInterfaceImpl> device(context->media_device()); | |
172 DCHECK(device.get()); | |
173 | |
174 // Create a temp file in "profile_path_/kIsolatedMediaFileSystemDir". | |
175 FilePath isolated_media_file_system_dir_path = | |
176 profile_path_.Append(kIsolatedMediaFileSystemDir); | |
177 bool dir_exists = file_util::DirectoryExists( | |
178 isolated_media_file_system_dir_path); | |
179 if (!dir_exists) { | |
180 if (!file_util::CreateDirectory(isolated_media_file_system_dir_path)) { | |
181 *result = base::PLATFORM_FILE_ERROR_FAILED; | |
182 return file_ref; | |
183 } | |
184 } | |
185 | |
186 bool file_created = file_util::CreateTemporaryFileInDir( | |
187 isolated_media_file_system_dir_path, local_path); | |
188 if (!file_created) { | |
189 *result = base::PLATFORM_FILE_ERROR_FAILED; | |
190 return file_ref; | |
191 } | |
192 | |
193 if (device->CreateSnapshotFile(url.path(), *local_path, file_info)) | |
kinuko
2012/07/31 05:35:44
I think you've changed this method to return Platf
kmadhusu
2012/07/31 19:47:24
Fixed.
| |
194 *result = base::PLATFORM_FILE_OK; | |
195 | |
196 if (*result == base::PLATFORM_FILE_OK) { | |
197 file_ref = ShareableFileReference::GetOrCreate( | |
198 *local_path, | |
199 ShareableFileReference::DELETE_ON_FINAL_RELEASE, | |
200 context->file_task_runner()); | |
201 } | |
202 return file_ref; | |
203 } | |
204 | |
205 } // namespace fileapi | |
OLD | NEW |