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 29 matching lines...) Expand all Loading... |
40 bool ContainsElement(const std::vector<T>& collection, const T& key) { | 40 bool ContainsElement(const std::vector<T>& collection, const T& key) { |
41 typename std::vector<T>::const_iterator it = collection.begin(); | 41 typename std::vector<T>::const_iterator it = collection.begin(); |
42 while (it != collection.end()) { | 42 while (it != collection.end()) { |
43 if (*it == key) | 43 if (*it == key) |
44 return true; | 44 return true; |
45 it++; | 45 it++; |
46 } | 46 } |
47 return false; | 47 return false; |
48 } | 48 } |
49 | 49 |
| 50 std::vector<std::string> GetVirtualPathComponents( |
| 51 const fileapi::FileSystemURL& url) { |
| 52 ImportedMediaGalleryRegistry* imported_registry = |
| 53 ImportedMediaGalleryRegistry::GetInstance(); |
| 54 base::FilePath root = imported_registry->ImportedRoot().AppendASCII("iphoto"); |
| 55 |
| 56 DCHECK(root.IsParent(url.path()) || root == url.path()); |
| 57 base::FilePath virtual_path; |
| 58 root.AppendRelativePath(url.path(), &virtual_path); |
| 59 |
| 60 std::vector<std::string> result; |
| 61 fileapi::VirtualPath::GetComponentsUTF8Unsafe(virtual_path, &result); |
| 62 return result; |
| 63 } |
| 64 |
50 } // namespace | 65 } // namespace |
51 | 66 |
52 const char kIPhotoAlbumsDir[] = "Albums"; | 67 const char kIPhotoAlbumsDir[] = "Albums"; |
53 const char kIPhotoOriginalsDir[] = "Originals"; | 68 const char kIPhotoOriginalsDir[] = "Originals"; |
54 | 69 |
55 IPhotoFileUtil::IPhotoFileUtil(MediaPathFilter* media_path_filter) | 70 IPhotoFileUtil::IPhotoFileUtil(MediaPathFilter* media_path_filter) |
56 : NativeMediaFileUtil(media_path_filter), | 71 : NativeMediaFileUtil(media_path_filter), |
57 weak_factory_(this), | 72 weak_factory_(this), |
58 imported_registry_(NULL) { | 73 imported_registry_(NULL) { |
59 } | 74 } |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 callback); | 164 callback); |
150 } | 165 } |
151 | 166 |
152 // Begin actual implementation. | 167 // Begin actual implementation. |
153 | 168 |
154 base::File::Error IPhotoFileUtil::GetFileInfoSync( | 169 base::File::Error IPhotoFileUtil::GetFileInfoSync( |
155 fileapi::FileSystemOperationContext* context, | 170 fileapi::FileSystemOperationContext* context, |
156 const fileapi::FileSystemURL& url, | 171 const fileapi::FileSystemURL& url, |
157 base::File::Info* file_info, | 172 base::File::Info* file_info, |
158 base::FilePath* platform_path) { | 173 base::FilePath* platform_path) { |
159 std::vector<std::string> components; | 174 std::vector<std::string> components = GetVirtualPathComponents(url); |
160 fileapi::VirtualPath::GetComponentsUTF8Unsafe(url.path(), &components); | |
161 | 175 |
162 if (components.size() == 0) { | 176 if (components.size() == 0) { |
163 return MakeDirectoryFileInfo(file_info); | 177 return MakeDirectoryFileInfo(file_info); |
164 } | 178 } |
165 | 179 |
166 // The 'Albums' directory. | 180 // The 'Albums' directory. |
167 if (components[0] == kIPhotoAlbumsDir) { | 181 if (components[0] == kIPhotoAlbumsDir) { |
168 if (components.size() == 1) { | 182 if (components.size() == 1) { |
169 return MakeDirectoryFileInfo(file_info); | 183 return MakeDirectoryFileInfo(file_info); |
170 } else if (components.size() == 2) { | 184 } else if (components.size() == 2) { |
(...skipping 28 matching lines...) Expand all Loading... |
199 } | 213 } |
200 | 214 |
201 return base::File::FILE_ERROR_NOT_FOUND; | 215 return base::File::FILE_ERROR_NOT_FOUND; |
202 } | 216 } |
203 | 217 |
204 base::File::Error IPhotoFileUtil::ReadDirectorySync( | 218 base::File::Error IPhotoFileUtil::ReadDirectorySync( |
205 fileapi::FileSystemOperationContext* context, | 219 fileapi::FileSystemOperationContext* context, |
206 const fileapi::FileSystemURL& url, | 220 const fileapi::FileSystemURL& url, |
207 EntryList* file_list) { | 221 EntryList* file_list) { |
208 DCHECK(file_list->empty()); | 222 DCHECK(file_list->empty()); |
209 std::vector<std::string> components; | 223 std::vector<std::string> components = GetVirtualPathComponents(url); |
210 fileapi::VirtualPath::GetComponentsUTF8Unsafe(url.path(), &components); | |
211 | 224 |
212 // Root directory. Child is the /Albums dir. | 225 // Root directory. Child is the /Albums dir. |
213 if (components.size() == 0) { | 226 if (components.size() == 0) { |
214 file_list->push_back(DirectoryEntry(kIPhotoAlbumsDir, | 227 file_list->push_back(DirectoryEntry(kIPhotoAlbumsDir, |
215 DirectoryEntry::DIRECTORY, | 228 DirectoryEntry::DIRECTORY, |
216 0, base::Time())); | 229 0, base::Time())); |
217 return base::File::FILE_OK; | 230 return base::File::FILE_OK; |
218 } | 231 } |
219 | 232 |
220 if (components[0] == kIPhotoAlbumsDir) { | 233 if (components[0] == kIPhotoAlbumsDir) { |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 fileapi::FileSystemOperationContext* context, | 296 fileapi::FileSystemOperationContext* context, |
284 const fileapi::FileSystemURL& url) { | 297 const fileapi::FileSystemURL& url) { |
285 return base::File::FILE_ERROR_SECURITY; | 298 return base::File::FILE_ERROR_SECURITY; |
286 } | 299 } |
287 | 300 |
288 | 301 |
289 base::File::Error IPhotoFileUtil::GetLocalFilePath( | 302 base::File::Error IPhotoFileUtil::GetLocalFilePath( |
290 fileapi::FileSystemOperationContext* context, | 303 fileapi::FileSystemOperationContext* context, |
291 const fileapi::FileSystemURL& url, | 304 const fileapi::FileSystemURL& url, |
292 base::FilePath* local_file_path) { | 305 base::FilePath* local_file_path) { |
293 std::vector<std::string> components; | 306 std::vector<std::string> components = GetVirtualPathComponents(url); |
294 fileapi::VirtualPath::GetComponentsUTF8Unsafe(url.path(), &components); | |
295 | 307 |
296 if (components.size() == 3 && components[0] == kIPhotoAlbumsDir) { | 308 if (components.size() == 3 && components[0] == kIPhotoAlbumsDir) { |
297 base::FilePath location = GetDataProvider()->GetPhotoLocationInAlbum( | 309 base::FilePath location = GetDataProvider()->GetPhotoLocationInAlbum( |
298 components[1], components[2]); | 310 components[1], components[2]); |
299 if (!location.empty()) { | 311 if (!location.empty()) { |
300 *local_file_path = location; | 312 *local_file_path = location; |
301 return base::File::FILE_OK; | 313 return base::File::FILE_OK; |
302 } | 314 } |
303 } | 315 } |
304 | 316 |
(...skipping 11 matching lines...) Expand all Loading... |
316 return base::File::FILE_ERROR_NOT_FOUND; | 328 return base::File::FILE_ERROR_NOT_FOUND; |
317 } | 329 } |
318 | 330 |
319 IPhotoDataProvider* IPhotoFileUtil::GetDataProvider() { | 331 IPhotoDataProvider* IPhotoFileUtil::GetDataProvider() { |
320 if (!imported_registry_) | 332 if (!imported_registry_) |
321 imported_registry_ = ImportedMediaGalleryRegistry::GetInstance(); | 333 imported_registry_ = ImportedMediaGalleryRegistry::GetInstance(); |
322 return imported_registry_->IPhotoDataProvider(); | 334 return imported_registry_->IPhotoDataProvider(); |
323 } | 335 } |
324 | 336 |
325 } // namespace iphoto | 337 } // namespace iphoto |
OLD | NEW |