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; | |
Lei Zhang
2012/11/21 01:33:30
Perhaps PLATFORM_FILE_ERROR_FAILED is more appropr
kmadhusu
2012/11/21 04:09:53
kinuko preferred base::PLATFORM_FILE_ERROR_NOT_FOU
| |
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 make_scoped_ptr(new FileSystemFileUtil::EmptyFileEnumerator()) | |
87 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); | |
kinuko
2012/11/20 06:25:33
nit: hmm... if we're just creating a new scoped_pt
kmadhusu
2012/11/21 04:09:53
Done.
| |
84 return make_scoped_ptr(new FilteringFileEnumerator( | 88 return make_scoped_ptr(new FilteringFileEnumerator( |
85 context->mtp_device_delegate()->CreateFileEnumerator(url.path(), | 89 context->mtp_device_delegate()->CreateFileEnumerator(url.path(), |
86 recursive), | 90 recursive), |
87 context->media_path_filter())) | 91 context->media_path_filter())) |
88 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); | 92 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); |
89 } | 93 } |
90 | 94 |
91 PlatformFileError DeviceMediaFileUtil::GetLocalFilePath( | 95 PlatformFileError DeviceMediaFileUtil::GetLocalFilePath( |
92 FileSystemOperationContext* context, | 96 FileSystemOperationContext* context, |
93 const FileSystemURL& file_system_url, | 97 const FileSystemURL& file_system_url, |
(...skipping 12 matching lines...) Expand all Loading... | |
106 PlatformFileError DeviceMediaFileUtil::Truncate( | 110 PlatformFileError DeviceMediaFileUtil::Truncate( |
107 FileSystemOperationContext* context, | 111 FileSystemOperationContext* context, |
108 const FileSystemURL& url, | 112 const FileSystemURL& url, |
109 int64 length) { | 113 int64 length) { |
110 return base::PLATFORM_FILE_ERROR_FAILED; | 114 return base::PLATFORM_FILE_ERROR_FAILED; |
111 } | 115 } |
112 | 116 |
113 bool DeviceMediaFileUtil::IsDirectoryEmpty( | 117 bool DeviceMediaFileUtil::IsDirectoryEmpty( |
114 FileSystemOperationContext* context, | 118 FileSystemOperationContext* context, |
115 const FileSystemURL& url) { | 119 const FileSystemURL& url) { |
116 DCHECK(context->mtp_device_delegate()); | 120 if (!context->mtp_device_delegate().get()) |
121 return false; | |
122 | |
117 scoped_ptr<AbstractFileEnumerator> enumerator( | 123 scoped_ptr<AbstractFileEnumerator> enumerator( |
118 CreateFileEnumerator(context, url, false)); | 124 CreateFileEnumerator(context, url, false)); |
119 FilePath path; | 125 FilePath path; |
120 while (!(path = enumerator->Next()).empty()) { | 126 while (!(path = enumerator->Next()).empty()) { |
121 if (enumerator->IsDirectory() || | 127 if (enumerator->IsDirectory() || |
122 context->media_path_filter()->Match(path)) | 128 context->media_path_filter()->Match(path)) |
123 return false; | 129 return false; |
124 } | 130 } |
125 return true; | 131 return true; |
126 } | 132 } |
(...skipping 27 matching lines...) Expand all Loading... | |
154 | 160 |
155 base::PlatformFileError DeviceMediaFileUtil::CreateSnapshotFile( | 161 base::PlatformFileError DeviceMediaFileUtil::CreateSnapshotFile( |
156 FileSystemOperationContext* context, | 162 FileSystemOperationContext* context, |
157 const FileSystemURL& url, | 163 const FileSystemURL& url, |
158 base::PlatformFileInfo* file_info, | 164 base::PlatformFileInfo* file_info, |
159 FilePath* local_path, | 165 FilePath* local_path, |
160 SnapshotFilePolicy* snapshot_policy) { | 166 SnapshotFilePolicy* snapshot_policy) { |
161 DCHECK(file_info); | 167 DCHECK(file_info); |
162 DCHECK(local_path); | 168 DCHECK(local_path); |
163 DCHECK(snapshot_policy); | 169 DCHECK(snapshot_policy); |
164 DCHECK(context->mtp_device_delegate()); | 170 if (!context->mtp_device_delegate().get()) |
171 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
165 | 172 |
166 // We return a temporary file as a snapshot. | 173 // We return a temporary file as a snapshot. |
167 *snapshot_policy = FileSystemFileUtil::kSnapshotFileTemporary; | 174 *snapshot_policy = FileSystemFileUtil::kSnapshotFileTemporary; |
168 | 175 |
169 // Create a temp file in "profile_path_/kDeviceMediaFileUtilTempDir". | 176 // Create a temp file in "profile_path_/kDeviceMediaFileUtilTempDir". |
170 FilePath isolated_media_file_system_dir_path = | 177 FilePath isolated_media_file_system_dir_path = |
171 profile_path_.Append(kDeviceMediaFileUtilTempDir); | 178 profile_path_.Append(kDeviceMediaFileUtilTempDir); |
172 bool dir_exists = file_util::DirectoryExists( | 179 bool dir_exists = file_util::DirectoryExists( |
173 isolated_media_file_system_dir_path); | 180 isolated_media_file_system_dir_path); |
174 if (!dir_exists && | 181 if (!dir_exists && |
175 !file_util::CreateDirectory(isolated_media_file_system_dir_path)) { | 182 !file_util::CreateDirectory(isolated_media_file_system_dir_path)) { |
176 LOG(WARNING) << "Could not create a directory for media snapshot file " | 183 LOG(WARNING) << "Could not create a directory for media snapshot file " |
177 << isolated_media_file_system_dir_path.value(); | 184 << isolated_media_file_system_dir_path.value(); |
178 return base::PLATFORM_FILE_ERROR_FAILED; | 185 return base::PLATFORM_FILE_ERROR_FAILED; |
179 } | 186 } |
180 | 187 |
181 bool file_created = file_util::CreateTemporaryFileInDir( | 188 bool file_created = file_util::CreateTemporaryFileInDir( |
182 isolated_media_file_system_dir_path, local_path); | 189 isolated_media_file_system_dir_path, local_path); |
183 if (!file_created) { | 190 if (!file_created) { |
184 LOG(WARNING) << "Could not create a temporary file for media snapshot in " | 191 LOG(WARNING) << "Could not create a temporary file for media snapshot in " |
185 << isolated_media_file_system_dir_path.value(); | 192 << isolated_media_file_system_dir_path.value(); |
186 return base::PLATFORM_FILE_ERROR_FAILED; | 193 return base::PLATFORM_FILE_ERROR_FAILED; |
187 } | 194 } |
188 return context->mtp_device_delegate()->CreateSnapshotFile( | 195 return context->mtp_device_delegate()->CreateSnapshotFile( |
189 url.path(), *local_path, file_info); | 196 url.path(), *local_path, file_info); |
190 } | 197 } |
191 | 198 |
192 } // namespace fileapi | 199 } // namespace fileapi |
OLD | NEW |