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 #include "webkit/fileapi/media/device_media_file_util.h" | 5 #include "webkit/fileapi/media/device_media_file_util.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "webkit/blob/shareable_file_reference.h" | |
11 #include "webkit/fileapi/file_system_operation_context.h" | 10 #include "webkit/fileapi/file_system_operation_context.h" |
12 #include "webkit/fileapi/file_system_url.h" | 11 #include "webkit/fileapi/file_system_url.h" |
13 #include "webkit/fileapi/isolated_context.h" | 12 #include "webkit/fileapi/isolated_context.h" |
14 #include "webkit/fileapi/media/media_device_interface_impl.h" | 13 #include "webkit/fileapi/media/media_device_interface_impl.h" |
15 #include "webkit/fileapi/media/media_device_map_service.h" | 14 #include "webkit/fileapi/media/media_device_map_service.h" |
16 | 15 |
17 using base::PlatformFileError; | 16 using base::PlatformFileError; |
18 using base::PlatformFileInfo; | 17 using base::PlatformFileInfo; |
19 using webkit_blob::ShareableFileReference; | |
20 | 18 |
21 namespace fileapi { | 19 namespace fileapi { |
22 | 20 |
23 namespace { | 21 namespace { |
24 | 22 |
25 const FilePath::CharType kDeviceMediaFileUtilTempDir[] = | 23 const FilePath::CharType kDeviceMediaFileUtilTempDir[] = |
26 FILE_PATH_LITERAL("DeviceMediaFileSystem"); | 24 FILE_PATH_LITERAL("DeviceMediaFileSystem"); |
27 | 25 |
28 } // namespace | 26 } // namespace |
29 | 27 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 const FileSystemURL& url) { | 147 const FileSystemURL& url) { |
150 return base::PLATFORM_FILE_ERROR_SECURITY; | 148 return base::PLATFORM_FILE_ERROR_SECURITY; |
151 } | 149 } |
152 | 150 |
153 PlatformFileError DeviceMediaFileUtil::DeleteSingleDirectory( | 151 PlatformFileError DeviceMediaFileUtil::DeleteSingleDirectory( |
154 FileSystemOperationContext* context, | 152 FileSystemOperationContext* context, |
155 const FileSystemURL& url) { | 153 const FileSystemURL& url) { |
156 return base::PLATFORM_FILE_ERROR_SECURITY; | 154 return base::PLATFORM_FILE_ERROR_SECURITY; |
157 } | 155 } |
158 | 156 |
159 scoped_refptr<ShareableFileReference> DeviceMediaFileUtil::CreateSnapshotFile( | 157 base::PlatformFileError DeviceMediaFileUtil::CreateSnapshotFile( |
160 FileSystemOperationContext* context, | 158 FileSystemOperationContext* context, |
161 const FileSystemURL& url, | 159 const FileSystemURL& url, |
162 base::PlatformFileError* result, | |
163 base::PlatformFileInfo* file_info, | 160 base::PlatformFileInfo* file_info, |
164 FilePath* local_path) { | 161 FilePath* local_path, |
165 DCHECK(result); | 162 SnapshotFilePolicy* snapshot_policy) { |
166 DCHECK(file_info); | 163 DCHECK(file_info); |
167 DCHECK(local_path); | 164 DCHECK(local_path); |
| 165 DCHECK(snapshot_policy); |
168 | 166 |
169 scoped_refptr<ShareableFileReference> file_ref; | 167 if (!context->media_device()) |
170 if (!context->media_device()) { | 168 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
171 *result = base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
172 return file_ref; | |
173 } | |
174 | 169 |
175 *result = base::PLATFORM_FILE_ERROR_FAILED; | 170 // We return a temporary file as a snapshot. |
| 171 *snapshot_policy = FileSystemFileUtil::kSnapshotFileTemporary; |
176 | 172 |
177 // Create a temp file in "profile_path_/kDeviceMediaFileUtilTempDir". | 173 // Create a temp file in "profile_path_/kDeviceMediaFileUtilTempDir". |
178 FilePath isolated_media_file_system_dir_path = | 174 FilePath isolated_media_file_system_dir_path = |
179 profile_path_.Append(kDeviceMediaFileUtilTempDir); | 175 profile_path_.Append(kDeviceMediaFileUtilTempDir); |
180 bool dir_exists = file_util::DirectoryExists( | 176 bool dir_exists = file_util::DirectoryExists( |
181 isolated_media_file_system_dir_path); | 177 isolated_media_file_system_dir_path); |
182 if (!dir_exists) { | 178 if (!dir_exists && |
183 if (!file_util::CreateDirectory(isolated_media_file_system_dir_path)) | 179 !file_util::CreateDirectory(isolated_media_file_system_dir_path)) { |
184 return file_ref; | 180 LOG(WARNING) << "Could not create a directory for media snapshot file " |
| 181 << isolated_media_file_system_dir_path.value(); |
| 182 return base::PLATFORM_FILE_ERROR_FAILED; |
185 } | 183 } |
186 | 184 |
187 bool file_created = file_util::CreateTemporaryFileInDir( | 185 bool file_created = file_util::CreateTemporaryFileInDir( |
188 isolated_media_file_system_dir_path, local_path); | 186 isolated_media_file_system_dir_path, local_path); |
189 if (!file_created) | 187 if (!file_created) { |
190 return file_ref; | 188 LOG(WARNING) << "Could not create a temporary file for media snapshot in " |
| 189 << isolated_media_file_system_dir_path.value(); |
| 190 return base::PLATFORM_FILE_ERROR_FAILED; |
| 191 } |
191 | 192 |
192 *result = context->media_device()->CreateSnapshotFile(url.path(), *local_path, | 193 return context->media_device()->CreateSnapshotFile( |
193 file_info); | 194 url.path(), *local_path, file_info); |
194 if (*result == base::PLATFORM_FILE_OK) { | |
195 file_ref = ShareableFileReference::GetOrCreate( | |
196 *local_path, ShareableFileReference::DELETE_ON_FINAL_RELEASE, | |
197 context->file_task_runner()); | |
198 } | |
199 return file_ref; | |
200 } | 195 } |
201 | 196 |
202 } // namespace fileapi | 197 } // namespace fileapi |
OLD | NEW |