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/message_loop_proxy.h" | 8 #include "base/message_loop_proxy.h" |
9 #include "webkit/fileapi/file_system_operation_context.h" | 9 #include "webkit/fileapi/file_system_operation_context.h" |
10 #include "webkit/fileapi/file_system_url.h" | 10 #include "webkit/fileapi/file_system_url.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 bool exclusive, | 56 bool exclusive, |
57 bool recursive) { | 57 bool recursive) { |
58 return base::PLATFORM_FILE_ERROR_SECURITY; | 58 return base::PLATFORM_FILE_ERROR_SECURITY; |
59 } | 59 } |
60 | 60 |
61 PlatformFileError DeviceMediaFileUtil::GetFileInfo( | 61 PlatformFileError DeviceMediaFileUtil::GetFileInfo( |
62 FileSystemOperationContext* context, | 62 FileSystemOperationContext* context, |
63 const FileSystemURL& url, | 63 const FileSystemURL& url, |
64 PlatformFileInfo* file_info, | 64 PlatformFileInfo* file_info, |
65 FilePath* platform_path) { | 65 FilePath* platform_path) { |
66 DCHECK(context->mtp_device_delegate()); | 66 if (!context->mtp_device_delegate().get()) |
| 67 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
| 68 |
67 PlatformFileError error = | 69 PlatformFileError error = |
68 context->mtp_device_delegate()->GetFileInfo(url.path(), file_info); | 70 context->mtp_device_delegate()->GetFileInfo(url.path(), file_info); |
69 if (error != base::PLATFORM_FILE_OK) | 71 if (error != base::PLATFORM_FILE_OK) |
70 return error; | 72 return error; |
71 | 73 |
72 if (file_info->is_directory || | 74 if (file_info->is_directory || |
73 context->media_path_filter()->Match(url.path())) | 75 context->media_path_filter()->Match(url.path())) |
74 return base::PLATFORM_FILE_OK; | 76 return base::PLATFORM_FILE_OK; |
75 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 77 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
76 } | 78 } |
77 | 79 |
78 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> | 80 scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator> |
79 DeviceMediaFileUtil::CreateFileEnumerator( | 81 DeviceMediaFileUtil::CreateFileEnumerator( |
80 FileSystemOperationContext* context, | 82 FileSystemOperationContext* context, |
81 const FileSystemURL& url, | 83 const FileSystemURL& url, |
82 bool recursive) { | 84 bool recursive) { |
83 DCHECK(context->mtp_device_delegate()); | 85 if (!context->mtp_device_delegate().get()) { |
| 86 return scoped_ptr<FileSystemFileUtil::AbstractFileEnumerator>( |
| 87 new FileSystemFileUtil::EmptyFileEnumerator()); |
| 88 } |
84 return make_scoped_ptr(new FilteringFileEnumerator( | 89 return make_scoped_ptr(new FilteringFileEnumerator( |
85 context->mtp_device_delegate()->CreateFileEnumerator(url.path(), | 90 context->mtp_device_delegate()->CreateFileEnumerator(url.path(), |
86 recursive), | 91 recursive), |
87 context->media_path_filter())) | 92 context->media_path_filter())) |
88 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); | 93 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); |
89 } | 94 } |
90 | 95 |
91 PlatformFileError DeviceMediaFileUtil::GetLocalFilePath( | 96 PlatformFileError DeviceMediaFileUtil::GetLocalFilePath( |
92 FileSystemOperationContext* context, | 97 FileSystemOperationContext* context, |
93 const FileSystemURL& file_system_url, | 98 const FileSystemURL& file_system_url, |
(...skipping 12 matching lines...) Expand all Loading... |
106 PlatformFileError DeviceMediaFileUtil::Truncate( | 111 PlatformFileError DeviceMediaFileUtil::Truncate( |
107 FileSystemOperationContext* context, | 112 FileSystemOperationContext* context, |
108 const FileSystemURL& url, | 113 const FileSystemURL& url, |
109 int64 length) { | 114 int64 length) { |
110 return base::PLATFORM_FILE_ERROR_FAILED; | 115 return base::PLATFORM_FILE_ERROR_FAILED; |
111 } | 116 } |
112 | 117 |
113 bool DeviceMediaFileUtil::IsDirectoryEmpty( | 118 bool DeviceMediaFileUtil::IsDirectoryEmpty( |
114 FileSystemOperationContext* context, | 119 FileSystemOperationContext* context, |
115 const FileSystemURL& url) { | 120 const FileSystemURL& url) { |
116 DCHECK(context->mtp_device_delegate()); | 121 if (!context->mtp_device_delegate().get()) |
| 122 return false; |
| 123 |
117 scoped_ptr<AbstractFileEnumerator> enumerator( | 124 scoped_ptr<AbstractFileEnumerator> enumerator( |
118 CreateFileEnumerator(context, url, false)); | 125 CreateFileEnumerator(context, url, false)); |
119 FilePath path; | 126 FilePath path; |
120 while (!(path = enumerator->Next()).empty()) { | 127 while (!(path = enumerator->Next()).empty()) { |
121 if (enumerator->IsDirectory() || | 128 if (enumerator->IsDirectory() || |
122 context->media_path_filter()->Match(path)) | 129 context->media_path_filter()->Match(path)) |
123 return false; | 130 return false; |
124 } | 131 } |
125 return true; | 132 return true; |
126 } | 133 } |
(...skipping 27 matching lines...) Expand all Loading... |
154 | 161 |
155 base::PlatformFileError DeviceMediaFileUtil::CreateSnapshotFile( | 162 base::PlatformFileError DeviceMediaFileUtil::CreateSnapshotFile( |
156 FileSystemOperationContext* context, | 163 FileSystemOperationContext* context, |
157 const FileSystemURL& url, | 164 const FileSystemURL& url, |
158 base::PlatformFileInfo* file_info, | 165 base::PlatformFileInfo* file_info, |
159 FilePath* local_path, | 166 FilePath* local_path, |
160 SnapshotFilePolicy* snapshot_policy) { | 167 SnapshotFilePolicy* snapshot_policy) { |
161 DCHECK(file_info); | 168 DCHECK(file_info); |
162 DCHECK(local_path); | 169 DCHECK(local_path); |
163 DCHECK(snapshot_policy); | 170 DCHECK(snapshot_policy); |
164 DCHECK(context->mtp_device_delegate()); | 171 if (!context->mtp_device_delegate().get()) |
| 172 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
165 | 173 |
166 // We return a temporary file as a snapshot. | 174 // We return a temporary file as a snapshot. |
167 *snapshot_policy = FileSystemFileUtil::kSnapshotFileTemporary; | 175 *snapshot_policy = FileSystemFileUtil::kSnapshotFileTemporary; |
168 | 176 |
169 // Create a temp file in "profile_path_/kDeviceMediaFileUtilTempDir". | 177 // Create a temp file in "profile_path_/kDeviceMediaFileUtilTempDir". |
170 FilePath isolated_media_file_system_dir_path = | 178 FilePath isolated_media_file_system_dir_path = |
171 profile_path_.Append(kDeviceMediaFileUtilTempDir); | 179 profile_path_.Append(kDeviceMediaFileUtilTempDir); |
172 bool dir_exists = file_util::DirectoryExists( | 180 bool dir_exists = file_util::DirectoryExists( |
173 isolated_media_file_system_dir_path); | 181 isolated_media_file_system_dir_path); |
174 if (!dir_exists && | 182 if (!dir_exists && |
175 !file_util::CreateDirectory(isolated_media_file_system_dir_path)) { | 183 !file_util::CreateDirectory(isolated_media_file_system_dir_path)) { |
176 LOG(WARNING) << "Could not create a directory for media snapshot file " | 184 LOG(WARNING) << "Could not create a directory for media snapshot file " |
177 << isolated_media_file_system_dir_path.value(); | 185 << isolated_media_file_system_dir_path.value(); |
178 return base::PLATFORM_FILE_ERROR_FAILED; | 186 return base::PLATFORM_FILE_ERROR_FAILED; |
179 } | 187 } |
180 | 188 |
181 bool file_created = file_util::CreateTemporaryFileInDir( | 189 bool file_created = file_util::CreateTemporaryFileInDir( |
182 isolated_media_file_system_dir_path, local_path); | 190 isolated_media_file_system_dir_path, local_path); |
183 if (!file_created) { | 191 if (!file_created) { |
184 LOG(WARNING) << "Could not create a temporary file for media snapshot in " | 192 LOG(WARNING) << "Could not create a temporary file for media snapshot in " |
185 << isolated_media_file_system_dir_path.value(); | 193 << isolated_media_file_system_dir_path.value(); |
186 return base::PLATFORM_FILE_ERROR_FAILED; | 194 return base::PLATFORM_FILE_ERROR_FAILED; |
187 } | 195 } |
188 return context->mtp_device_delegate()->CreateSnapshotFile( | 196 return context->mtp_device_delegate()->CreateSnapshotFile( |
189 url.path(), *local_path, file_info); | 197 url.path(), *local_path, file_info); |
190 } | 198 } |
191 | 199 |
192 } // namespace fileapi | 200 } // namespace fileapi |
OLD | NEW |