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/picasa_file_util.h" | 5 #include "chrome/browser/media_galleries/fileapi/picasa_file_util.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 | 42 |
43 if (it == map->end()) | 43 if (it == map->end()) |
44 return base::File::FILE_ERROR_NOT_FOUND; | 44 return base::File::FILE_ERROR_NOT_FOUND; |
45 | 45 |
46 if (album_info != NULL) | 46 if (album_info != NULL) |
47 *album_info = it->second; | 47 *album_info = it->second; |
48 | 48 |
49 return base::File::FILE_OK; | 49 return base::File::FILE_OK; |
50 } | 50 } |
51 | 51 |
| 52 std::vector<std::string> GetVirtualPathComponents( |
| 53 const fileapi::FileSystemURL& url) { |
| 54 ImportedMediaGalleryRegistry* imported_registry = |
| 55 ImportedMediaGalleryRegistry::GetInstance(); |
| 56 base::FilePath root = imported_registry->ImportedRoot().AppendASCII("picasa"); |
| 57 |
| 58 DCHECK(root.IsParent(url.path()) || root == url.path()); |
| 59 base::FilePath virtual_path; |
| 60 root.AppendRelativePath(url.path(), &virtual_path); |
| 61 |
| 62 std::vector<std::string> result; |
| 63 fileapi::VirtualPath::GetComponentsUTF8Unsafe(virtual_path, &result); |
| 64 return result; |
| 65 } |
| 66 |
52 PicasaDataProvider::DataType GetDataTypeForURL( | 67 PicasaDataProvider::DataType GetDataTypeForURL( |
53 const fileapi::FileSystemURL& url) { | 68 const fileapi::FileSystemURL& url) { |
54 std::vector<std::string> components; | 69 std::vector<std::string> components = GetVirtualPathComponents(url); |
55 fileapi::VirtualPath::GetComponentsUTF8Unsafe(url.path(), &components); | |
56 | |
57 if (components.size() >= 2 && components[0] == kPicasaDirAlbums) | 70 if (components.size() >= 2 && components[0] == kPicasaDirAlbums) |
58 return PicasaDataProvider::ALBUMS_IMAGES_DATA; | 71 return PicasaDataProvider::ALBUMS_IMAGES_DATA; |
59 | 72 |
60 return PicasaDataProvider::LIST_OF_ALBUMS_AND_FOLDERS_DATA; | 73 return PicasaDataProvider::LIST_OF_ALBUMS_AND_FOLDERS_DATA; |
61 } | 74 } |
62 | 75 |
63 } // namespace | 76 } // namespace |
64 | 77 |
65 const char kPicasaDirAlbums[] = "albums"; | 78 const char kPicasaDirAlbums[] = "albums"; |
66 const char kPicasaDirFolders[] = "folders"; | 79 const char kPicasaDirFolders[] = "folders"; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 113 |
101 base::File::Error PicasaFileUtil::GetFileInfoSync( | 114 base::File::Error PicasaFileUtil::GetFileInfoSync( |
102 FileSystemOperationContext* context, const FileSystemURL& url, | 115 FileSystemOperationContext* context, const FileSystemURL& url, |
103 base::File::Info* file_info, base::FilePath* platform_path) { | 116 base::File::Info* file_info, base::FilePath* platform_path) { |
104 DCHECK(context); | 117 DCHECK(context); |
105 DCHECK(file_info); | 118 DCHECK(file_info); |
106 | 119 |
107 if (platform_path) | 120 if (platform_path) |
108 *platform_path = base::FilePath(); | 121 *platform_path = base::FilePath(); |
109 | 122 |
110 std::vector<std::string> components; | 123 std::vector<std::string> components = GetVirtualPathComponents(url); |
111 fileapi::VirtualPath::GetComponentsUTF8Unsafe(url.path(), &components); | |
112 | 124 |
113 switch (components.size()) { | 125 switch (components.size()) { |
114 case 0: | 126 case 0: |
115 // Root directory. | 127 // Root directory. |
116 file_info->is_directory = true; | 128 file_info->is_directory = true; |
117 return base::File::FILE_OK; | 129 return base::File::FILE_OK; |
118 case 1: | 130 case 1: |
119 if (components[0] == kPicasaDirAlbums || | 131 if (components[0] == kPicasaDirAlbums || |
120 components[0] == kPicasaDirFolders) { | 132 components[0] == kPicasaDirFolders) { |
121 file_info->is_directory = true; | 133 file_info->is_directory = true; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 base::FilePath platform_directory_path; | 181 base::FilePath platform_directory_path; |
170 base::File::Error error = GetFileInfoSync( | 182 base::File::Error error = GetFileInfoSync( |
171 context, url, &file_info, &platform_directory_path); | 183 context, url, &file_info, &platform_directory_path); |
172 | 184 |
173 if (error != base::File::FILE_OK) | 185 if (error != base::File::FILE_OK) |
174 return error; | 186 return error; |
175 | 187 |
176 if (!file_info.is_directory) | 188 if (!file_info.is_directory) |
177 return base::File::FILE_ERROR_NOT_A_DIRECTORY; | 189 return base::File::FILE_ERROR_NOT_A_DIRECTORY; |
178 | 190 |
179 std::vector<std::string> components; | 191 std::vector<std::string> components = GetVirtualPathComponents(url); |
180 fileapi::VirtualPath::GetComponentsUTF8Unsafe(url.path(), &components); | |
181 | |
182 switch (components.size()) { | 192 switch (components.size()) { |
183 case 0: { | 193 case 0: { |
184 // Root directory. | 194 // Root directory. |
185 file_list->push_back( | 195 file_list->push_back( |
186 DirectoryEntry(kPicasaDirAlbums, DirectoryEntry::DIRECTORY, 0, | 196 DirectoryEntry(kPicasaDirAlbums, DirectoryEntry::DIRECTORY, 0, |
187 base::Time())); | 197 base::Time())); |
188 file_list->push_back( | 198 file_list->push_back( |
189 DirectoryEntry(kPicasaDirFolders, DirectoryEntry::DIRECTORY, 0, | 199 DirectoryEntry(kPicasaDirFolders, DirectoryEntry::DIRECTORY, 0, |
190 base::Time())); | 200 base::Time())); |
191 break; | 201 break; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 fileapi::FileSystemOperationContext* context, | 286 fileapi::FileSystemOperationContext* context, |
277 const fileapi::FileSystemURL& url) { | 287 const fileapi::FileSystemURL& url) { |
278 return base::File::FILE_ERROR_SECURITY; | 288 return base::File::FILE_ERROR_SECURITY; |
279 } | 289 } |
280 | 290 |
281 base::File::Error PicasaFileUtil::GetLocalFilePath( | 291 base::File::Error PicasaFileUtil::GetLocalFilePath( |
282 FileSystemOperationContext* context, const FileSystemURL& url, | 292 FileSystemOperationContext* context, const FileSystemURL& url, |
283 base::FilePath* local_file_path) { | 293 base::FilePath* local_file_path) { |
284 DCHECK(local_file_path); | 294 DCHECK(local_file_path); |
285 DCHECK(url.is_valid()); | 295 DCHECK(url.is_valid()); |
286 std::vector<std::string> components; | 296 std::vector<std::string> components = GetVirtualPathComponents(url); |
287 fileapi::VirtualPath::GetComponentsUTF8Unsafe(url.path(), &components); | |
288 | 297 |
289 switch (components.size()) { | 298 switch (components.size()) { |
290 case 2: | 299 case 2: |
291 if (components[0] == kPicasaDirFolders) { | 300 if (components[0] == kPicasaDirFolders) { |
292 scoped_ptr<AlbumMap> album_map = GetDataProvider()->GetFolders(); | 301 scoped_ptr<AlbumMap> album_map = GetDataProvider()->GetFolders(); |
293 AlbumInfo album_info; | 302 AlbumInfo album_info; |
294 base::File::Error error = | 303 base::File::Error error = |
295 FindAlbumInfo(components[1], album_map.get(), &album_info); | 304 FindAlbumInfo(components[1], album_map.get(), &album_info); |
296 if (error != base::File::FILE_OK) | 305 if (error != base::File::FILE_OK) |
297 return error; | 306 return error; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 } | 384 } |
376 NativeMediaFileUtil::ReadDirectoryOnTaskRunnerThread( | 385 NativeMediaFileUtil::ReadDirectoryOnTaskRunnerThread( |
377 context.Pass(), url, callback); | 386 context.Pass(), url, callback); |
378 } | 387 } |
379 | 388 |
380 PicasaDataProvider* PicasaFileUtil::GetDataProvider() { | 389 PicasaDataProvider* PicasaFileUtil::GetDataProvider() { |
381 return ImportedMediaGalleryRegistry::PicasaDataProvider(); | 390 return ImportedMediaGalleryRegistry::PicasaDataProvider(); |
382 } | 391 } |
383 | 392 |
384 } // namespace picasa | 393 } // namespace picasa |
OLD | NEW |