OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/media_galleries/fileapi/iphoto_file_util.h" | 5 #include "chrome/browser/media_galleries/fileapi/iphoto_file_util.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "webkit/common/blob/shareable_file_reference.h" | 22 #include "webkit/common/blob/shareable_file_reference.h" |
23 #include "webkit/common/fileapi/directory_entry.h" | 23 #include "webkit/common/fileapi/directory_entry.h" |
24 #include "webkit/common/fileapi/file_system_util.h" | 24 #include "webkit/common/fileapi/file_system_util.h" |
25 | 25 |
26 using fileapi::DirectoryEntry; | 26 using fileapi::DirectoryEntry; |
27 | 27 |
28 namespace iphoto { | 28 namespace iphoto { |
29 | 29 |
30 namespace { | 30 namespace { |
31 | 31 |
32 base::PlatformFileError MakeDirectoryFileInfo( | 32 base::File::Error MakeDirectoryFileInfo(base::File::Info* file_info) { |
33 base::PlatformFileInfo* file_info) { | 33 base::File::Info result; |
34 base::PlatformFileInfo result; | |
35 result.is_directory = true; | 34 result.is_directory = true; |
36 *file_info = result; | 35 *file_info = result; |
37 return base::PLATFORM_FILE_OK; | 36 return base::File::FILE_OK; |
38 } | 37 } |
39 | 38 |
40 template <typename T> | 39 template <typename T> |
41 bool ContainsElement(const std::vector<T>& collection, const T& key) { | 40 bool ContainsElement(const std::vector<T>& collection, const T& key) { |
42 typename std::vector<T>::const_iterator it = collection.begin(); | 41 typename std::vector<T>::const_iterator it = collection.begin(); |
43 while (it != collection.end()) { | 42 while (it != collection.end()) { |
44 if (*it == key) | 43 if (*it == key) |
45 return true; | 44 return true; |
46 it++; | 45 it++; |
47 } | 46 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 void IPhotoFileUtil::GetFileInfoWithFreshDataProvider( | 94 void IPhotoFileUtil::GetFileInfoWithFreshDataProvider( |
96 scoped_ptr<fileapi::FileSystemOperationContext> context, | 95 scoped_ptr<fileapi::FileSystemOperationContext> context, |
97 const fileapi::FileSystemURL& url, | 96 const fileapi::FileSystemURL& url, |
98 const GetFileInfoCallback& callback, | 97 const GetFileInfoCallback& callback, |
99 bool valid_parse) { | 98 bool valid_parse) { |
100 if (!valid_parse) { | 99 if (!valid_parse) { |
101 if (!callback.is_null()) { | 100 if (!callback.is_null()) { |
102 content::BrowserThread::PostTask( | 101 content::BrowserThread::PostTask( |
103 content::BrowserThread::IO, | 102 content::BrowserThread::IO, |
104 FROM_HERE, | 103 FROM_HERE, |
105 base::Bind(callback, base::PLATFORM_FILE_ERROR_IO, | 104 base::Bind(callback, base::File::FILE_ERROR_IO, base::File::Info())); |
106 base::PlatformFileInfo())); | |
107 } | 105 } |
108 return; | 106 return; |
109 } | 107 } |
110 NativeMediaFileUtil::GetFileInfoOnTaskRunnerThread(context.Pass(), url, | 108 NativeMediaFileUtil::GetFileInfoOnTaskRunnerThread(context.Pass(), url, |
111 callback); | 109 callback); |
112 } | 110 } |
113 | 111 |
114 void IPhotoFileUtil::ReadDirectoryWithFreshDataProvider( | 112 void IPhotoFileUtil::ReadDirectoryWithFreshDataProvider( |
115 scoped_ptr<fileapi::FileSystemOperationContext> context, | 113 scoped_ptr<fileapi::FileSystemOperationContext> context, |
116 const fileapi::FileSystemURL& url, | 114 const fileapi::FileSystemURL& url, |
117 const ReadDirectoryCallback& callback, | 115 const ReadDirectoryCallback& callback, |
118 bool valid_parse) { | 116 bool valid_parse) { |
119 if (!valid_parse) { | 117 if (!valid_parse) { |
120 if (!callback.is_null()) { | 118 if (!callback.is_null()) { |
121 content::BrowserThread::PostTask( | 119 content::BrowserThread::PostTask( |
122 content::BrowserThread::IO, | 120 content::BrowserThread::IO, |
123 FROM_HERE, | 121 FROM_HERE, |
124 base::Bind(callback, base::PLATFORM_FILE_ERROR_IO, EntryList(), | 122 base::Bind(callback, base::File::FILE_ERROR_IO, EntryList(), false)); |
125 false)); | |
126 } | 123 } |
127 return; | 124 return; |
128 } | 125 } |
129 NativeMediaFileUtil::ReadDirectoryOnTaskRunnerThread(context.Pass(), url, | 126 NativeMediaFileUtil::ReadDirectoryOnTaskRunnerThread(context.Pass(), url, |
130 callback); | 127 callback); |
131 } | 128 } |
132 | 129 |
133 void IPhotoFileUtil::CreateSnapshotFileWithFreshDataProvider( | 130 void IPhotoFileUtil::CreateSnapshotFileWithFreshDataProvider( |
134 scoped_ptr<fileapi::FileSystemOperationContext> context, | 131 scoped_ptr<fileapi::FileSystemOperationContext> context, |
135 const fileapi::FileSystemURL& url, | 132 const fileapi::FileSystemURL& url, |
136 const CreateSnapshotFileCallback& callback, | 133 const CreateSnapshotFileCallback& callback, |
137 bool valid_parse) { | 134 bool valid_parse) { |
138 if (!valid_parse) { | 135 if (!valid_parse) { |
139 if (!callback.is_null()) { | 136 if (!callback.is_null()) { |
140 base::PlatformFileInfo file_info; | 137 base::File::Info file_info; |
141 base::FilePath platform_path; | 138 base::FilePath platform_path; |
142 scoped_refptr<webkit_blob::ShareableFileReference> file_ref; | 139 scoped_refptr<webkit_blob::ShareableFileReference> file_ref; |
143 content::BrowserThread::PostTask( | 140 content::BrowserThread::PostTask( |
144 content::BrowserThread::IO, | 141 content::BrowserThread::IO, |
145 FROM_HERE, | 142 FROM_HERE, |
146 base::Bind(callback, base::PLATFORM_FILE_ERROR_IO, file_info, | 143 base::Bind(callback, base::File::FILE_ERROR_IO, file_info, |
147 platform_path, file_ref)); | 144 platform_path, file_ref)); |
148 } | 145 } |
149 return; | 146 return; |
150 } | 147 } |
151 NativeMediaFileUtil::CreateSnapshotFileOnTaskRunnerThread(context.Pass(), url, | 148 NativeMediaFileUtil::CreateSnapshotFileOnTaskRunnerThread(context.Pass(), url, |
152 callback); | 149 callback); |
153 } | 150 } |
154 | 151 |
155 // Begin actual implementation. | 152 // Begin actual implementation. |
156 | 153 |
157 base::PlatformFileError IPhotoFileUtil::GetFileInfoSync( | 154 base::File::Error IPhotoFileUtil::GetFileInfoSync( |
158 fileapi::FileSystemOperationContext* context, | 155 fileapi::FileSystemOperationContext* context, |
159 const fileapi::FileSystemURL& url, | 156 const fileapi::FileSystemURL& url, |
160 base::PlatformFileInfo* file_info, | 157 base::File::Info* file_info, |
161 base::FilePath* platform_path) { | 158 base::FilePath* platform_path) { |
162 std::vector<std::string> components; | 159 std::vector<std::string> components; |
163 fileapi::VirtualPath::GetComponentsUTF8Unsafe(url.path(), &components); | 160 fileapi::VirtualPath::GetComponentsUTF8Unsafe(url.path(), &components); |
164 | 161 |
165 if (components.size() == 0) { | 162 if (components.size() == 0) { |
166 return MakeDirectoryFileInfo(file_info); | 163 return MakeDirectoryFileInfo(file_info); |
167 } | 164 } |
168 | 165 |
169 // The 'Albums' directory. | 166 // The 'Albums' directory. |
170 if (components[0] == kIPhotoAlbumsDir) { | 167 if (components[0] == kIPhotoAlbumsDir) { |
171 if (components.size() == 1) { | 168 if (components.size() == 1) { |
172 return MakeDirectoryFileInfo(file_info); | 169 return MakeDirectoryFileInfo(file_info); |
173 } else if (components.size() == 2) { | 170 } else if (components.size() == 2) { |
174 std::vector<std::string> albums = | 171 std::vector<std::string> albums = |
175 GetDataProvider()->GetAlbumNames(); | 172 GetDataProvider()->GetAlbumNames(); |
176 if (ContainsElement(albums, components[1])) | 173 if (ContainsElement(albums, components[1])) |
177 return MakeDirectoryFileInfo(file_info); | 174 return MakeDirectoryFileInfo(file_info); |
178 } else if (components.size() == 3) { | 175 } else if (components.size() == 3) { |
179 if (components[2] == kIPhotoOriginalsDir) { | 176 if (components[2] == kIPhotoOriginalsDir) { |
180 if (GetDataProvider()->HasOriginals(components[1])) | 177 if (GetDataProvider()->HasOriginals(components[1])) |
181 return MakeDirectoryFileInfo(file_info); | 178 return MakeDirectoryFileInfo(file_info); |
182 else | 179 else |
183 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 180 return base::File::FILE_ERROR_NOT_FOUND; |
184 } | 181 } |
185 | 182 |
186 base::FilePath location = GetDataProvider()->GetPhotoLocationInAlbum( | 183 base::FilePath location = GetDataProvider()->GetPhotoLocationInAlbum( |
187 components[1], components[2]); | 184 components[1], components[2]); |
188 if (!location.empty()) { | 185 if (!location.empty()) { |
189 return NativeMediaFileUtil::GetFileInfoSync( | 186 return NativeMediaFileUtil::GetFileInfoSync( |
190 context, url, file_info, platform_path); | 187 context, url, file_info, platform_path); |
191 } | 188 } |
192 } else if (components.size() == 4 && | 189 } else if (components.size() == 4 && |
193 GetDataProvider()->HasOriginals(components[1]) && | 190 GetDataProvider()->HasOriginals(components[1]) && |
194 components[2] == kIPhotoOriginalsDir) { | 191 components[2] == kIPhotoOriginalsDir) { |
195 base::FilePath location = GetDataProvider()->GetOriginalPhotoLocation( | 192 base::FilePath location = GetDataProvider()->GetOriginalPhotoLocation( |
196 components[1], components[3]); | 193 components[1], components[3]); |
197 if (!location.empty()) { | 194 if (!location.empty()) { |
198 return NativeMediaFileUtil::GetFileInfoSync( | 195 return NativeMediaFileUtil::GetFileInfoSync( |
199 context, url, file_info, platform_path); | 196 context, url, file_info, platform_path); |
200 } | 197 } |
201 } | 198 } |
202 } | 199 } |
203 | 200 |
204 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 201 return base::File::FILE_ERROR_NOT_FOUND; |
205 } | 202 } |
206 | 203 |
207 base::PlatformFileError IPhotoFileUtil::ReadDirectorySync( | 204 base::File::Error IPhotoFileUtil::ReadDirectorySync( |
208 fileapi::FileSystemOperationContext* context, | 205 fileapi::FileSystemOperationContext* context, |
209 const fileapi::FileSystemURL& url, | 206 const fileapi::FileSystemURL& url, |
210 EntryList* file_list) { | 207 EntryList* file_list) { |
211 DCHECK(file_list->empty()); | 208 DCHECK(file_list->empty()); |
212 std::vector<std::string> components; | 209 std::vector<std::string> components; |
213 fileapi::VirtualPath::GetComponentsUTF8Unsafe(url.path(), &components); | 210 fileapi::VirtualPath::GetComponentsUTF8Unsafe(url.path(), &components); |
214 | 211 |
215 // Root directory. Child is the /Albums dir. | 212 // Root directory. Child is the /Albums dir. |
216 if (components.size() == 0) { | 213 if (components.size() == 0) { |
217 file_list->push_back(DirectoryEntry(kIPhotoAlbumsDir, | 214 file_list->push_back(DirectoryEntry(kIPhotoAlbumsDir, |
218 DirectoryEntry::DIRECTORY, | 215 DirectoryEntry::DIRECTORY, |
219 0, base::Time())); | 216 0, base::Time())); |
220 return base::PLATFORM_FILE_OK; | 217 return base::File::FILE_OK; |
221 } | 218 } |
222 | 219 |
223 if (components[0] == kIPhotoAlbumsDir) { | 220 if (components[0] == kIPhotoAlbumsDir) { |
224 if (components.size() == 1) { | 221 if (components.size() == 1) { |
225 // Albums dir contains all album names. | 222 // Albums dir contains all album names. |
226 std::vector<std::string> albums = | 223 std::vector<std::string> albums = |
227 GetDataProvider()->GetAlbumNames(); | 224 GetDataProvider()->GetAlbumNames(); |
228 for (std::vector<std::string>::const_iterator it = albums.begin(); | 225 for (std::vector<std::string>::const_iterator it = albums.begin(); |
229 it != albums.end(); it++) { | 226 it != albums.end(); it++) { |
230 file_list->push_back(DirectoryEntry(*it, DirectoryEntry::DIRECTORY, | 227 file_list->push_back(DirectoryEntry(*it, DirectoryEntry::DIRECTORY, |
231 0, base::Time())); | 228 0, base::Time())); |
232 } | 229 } |
233 return base::PLATFORM_FILE_OK; | 230 return base::File::FILE_OK; |
234 } else if (components.size() == 2) { | 231 } else if (components.size() == 2) { |
235 std::vector<std::string> albums = | 232 std::vector<std::string> albums = |
236 GetDataProvider()->GetAlbumNames(); | 233 GetDataProvider()->GetAlbumNames(); |
237 if (!ContainsElement(albums, components[1])) | 234 if (!ContainsElement(albums, components[1])) |
238 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 235 return base::File::FILE_ERROR_NOT_FOUND; |
239 | 236 |
240 // Album dirs contain all photos in them. | 237 // Album dirs contain all photos in them. |
241 if (GetDataProvider()->HasOriginals(components[1])) { | 238 if (GetDataProvider()->HasOriginals(components[1])) { |
242 file_list->push_back(DirectoryEntry(kIPhotoOriginalsDir, | 239 file_list->push_back(DirectoryEntry(kIPhotoOriginalsDir, |
243 DirectoryEntry::DIRECTORY, | 240 DirectoryEntry::DIRECTORY, |
244 0, base::Time())); | 241 0, base::Time())); |
245 } | 242 } |
246 std::map<std::string, base::FilePath> locations = | 243 std::map<std::string, base::FilePath> locations = |
247 GetDataProvider()->GetAlbumContents(components[1]); | 244 GetDataProvider()->GetAlbumContents(components[1]); |
248 for (std::map<std::string, base::FilePath>::const_iterator it = | 245 for (std::map<std::string, base::FilePath>::const_iterator it = |
249 locations.begin(); | 246 locations.begin(); |
250 it != locations.end(); it++) { | 247 it != locations.end(); it++) { |
251 base::File::Info info; | 248 base::File::Info info; |
252 if (!base::GetFileInfo(it->second, &info)) | 249 if (!base::GetFileInfo(it->second, &info)) |
253 return base::PLATFORM_FILE_ERROR_IO; | 250 return base::File::FILE_ERROR_IO; |
254 file_list->push_back(DirectoryEntry(it->first, DirectoryEntry::FILE, | 251 file_list->push_back(DirectoryEntry(it->first, DirectoryEntry::FILE, |
255 info.size, info.last_modified)); | 252 info.size, info.last_modified)); |
256 } | 253 } |
257 return base::PLATFORM_FILE_OK; | 254 return base::File::FILE_OK; |
258 } else if (components.size() == 3 && | 255 } else if (components.size() == 3 && |
259 components[2] == kIPhotoOriginalsDir && | 256 components[2] == kIPhotoOriginalsDir && |
260 GetDataProvider()->HasOriginals(components[1])) { | 257 GetDataProvider()->HasOriginals(components[1])) { |
261 std::map<std::string, base::FilePath> originals = | 258 std::map<std::string, base::FilePath> originals = |
262 GetDataProvider()->GetOriginals(components[1]); | 259 GetDataProvider()->GetOriginals(components[1]); |
263 for (std::map<std::string, base::FilePath>::const_iterator it = | 260 for (std::map<std::string, base::FilePath>::const_iterator it = |
264 originals.begin(); | 261 originals.begin(); |
265 it != originals.end(); it++) { | 262 it != originals.end(); it++) { |
266 base::File::Info info; | 263 base::File::Info info; |
267 if (!base::GetFileInfo(it->second, &info)) | 264 if (!base::GetFileInfo(it->second, &info)) |
268 return base::PLATFORM_FILE_ERROR_IO; | 265 return base::File::FILE_ERROR_IO; |
269 file_list->push_back(DirectoryEntry(it->first, DirectoryEntry::FILE, | 266 file_list->push_back(DirectoryEntry(it->first, DirectoryEntry::FILE, |
270 info.size, info.last_modified)); | 267 info.size, info.last_modified)); |
271 } | 268 } |
272 return base::PLATFORM_FILE_OK; | 269 return base::File::FILE_OK; |
273 } | 270 } |
274 } | 271 } |
275 | 272 |
276 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 273 return base::File::FILE_ERROR_NOT_FOUND; |
277 } | 274 } |
278 | 275 |
279 base::PlatformFileError IPhotoFileUtil::DeleteDirectorySync( | 276 base::File::Error IPhotoFileUtil::DeleteDirectorySync( |
280 fileapi::FileSystemOperationContext* context, | 277 fileapi::FileSystemOperationContext* context, |
281 const fileapi::FileSystemURL& url) { | 278 const fileapi::FileSystemURL& url) { |
282 return base::PLATFORM_FILE_ERROR_SECURITY; | 279 return base::File::FILE_ERROR_SECURITY; |
283 } | 280 } |
284 | 281 |
285 base::PlatformFileError IPhotoFileUtil::DeleteFileSync( | 282 base::File::Error IPhotoFileUtil::DeleteFileSync( |
286 fileapi::FileSystemOperationContext* context, | 283 fileapi::FileSystemOperationContext* context, |
287 const fileapi::FileSystemURL& url) { | 284 const fileapi::FileSystemURL& url) { |
288 return base::PLATFORM_FILE_ERROR_SECURITY; | 285 return base::File::FILE_ERROR_SECURITY; |
289 } | 286 } |
290 | 287 |
291 | 288 |
292 base::PlatformFileError IPhotoFileUtil::GetLocalFilePath( | 289 base::File::Error IPhotoFileUtil::GetLocalFilePath( |
293 fileapi::FileSystemOperationContext* context, | 290 fileapi::FileSystemOperationContext* context, |
294 const fileapi::FileSystemURL& url, | 291 const fileapi::FileSystemURL& url, |
295 base::FilePath* local_file_path) { | 292 base::FilePath* local_file_path) { |
296 std::vector<std::string> components; | 293 std::vector<std::string> components; |
297 fileapi::VirtualPath::GetComponentsUTF8Unsafe(url.path(), &components); | 294 fileapi::VirtualPath::GetComponentsUTF8Unsafe(url.path(), &components); |
298 | 295 |
299 if (components.size() == 3 && components[0] == kIPhotoAlbumsDir) { | 296 if (components.size() == 3 && components[0] == kIPhotoAlbumsDir) { |
300 base::FilePath location = GetDataProvider()->GetPhotoLocationInAlbum( | 297 base::FilePath location = GetDataProvider()->GetPhotoLocationInAlbum( |
301 components[1], components[2]); | 298 components[1], components[2]); |
302 if (!location.empty()) { | 299 if (!location.empty()) { |
303 *local_file_path = location; | 300 *local_file_path = location; |
304 return base::PLATFORM_FILE_OK; | 301 return base::File::FILE_OK; |
305 } | 302 } |
306 } | 303 } |
307 | 304 |
308 if (components.size() == 4 && components[0] == kIPhotoAlbumsDir && | 305 if (components.size() == 4 && components[0] == kIPhotoAlbumsDir && |
309 GetDataProvider()->HasOriginals(components[1]) && | 306 GetDataProvider()->HasOriginals(components[1]) && |
310 components[2] == kIPhotoOriginalsDir) { | 307 components[2] == kIPhotoOriginalsDir) { |
311 base::FilePath location = GetDataProvider()->GetOriginalPhotoLocation( | 308 base::FilePath location = GetDataProvider()->GetOriginalPhotoLocation( |
312 components[1], components[3]); | 309 components[1], components[3]); |
313 if (!location.empty()) { | 310 if (!location.empty()) { |
314 *local_file_path = location; | 311 *local_file_path = location; |
315 return base::PLATFORM_FILE_OK; | 312 return base::File::FILE_OK; |
316 } | 313 } |
317 } | 314 } |
318 | 315 |
319 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 316 return base::File::FILE_ERROR_NOT_FOUND; |
320 } | 317 } |
321 | 318 |
322 IPhotoDataProvider* IPhotoFileUtil::GetDataProvider() { | 319 IPhotoDataProvider* IPhotoFileUtil::GetDataProvider() { |
323 if (!imported_registry_) | 320 if (!imported_registry_) |
324 imported_registry_ = ImportedMediaGalleryRegistry::GetInstance(); | 321 imported_registry_ = ImportedMediaGalleryRegistry::GetInstance(); |
325 return imported_registry_->IPhotoDataProvider(); | 322 return imported_registry_->IPhotoDataProvider(); |
326 } | 323 } |
327 | 324 |
328 } // namespace iphoto | 325 } // namespace iphoto |
OLD | NEW |