Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: chrome/browser/media_galleries/fileapi/picasa_file_util.cc

Issue 185393012: Change media galleries to external file system type to add toURL support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix picasa,itunes,iphoto path parsing Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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(
Lei Zhang 2014/03/26 17:50:11 Might be nice to merge the 3 version of this someh
vandebo (ex-Chrome) 2014/03/26 23:25:24 Yea, there's a general todo to refactor the file u
53 const fileapi::FileSystemURL& url) {
54 ImportedMediaGalleryRegistry* imported_registry =
55 ImportedMediaGalleryRegistry::GetInstance();
56 base::FilePath root = imported_registry->ImportedRoot().Append("picasa");
57
58 DCHECK(root.IsParent(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
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
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
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 26 matching lines...) Expand all
324 333
325 if (components[0] == kPicasaDirFolders) { 334 if (components[0] == kPicasaDirFolders) {
326 scoped_ptr<AlbumMap> album_map = GetDataProvider()->GetFolders(); 335 scoped_ptr<AlbumMap> album_map = GetDataProvider()->GetFolders();
327 AlbumInfo album_info; 336 AlbumInfo album_info;
328 base::File::Error error = 337 base::File::Error error =
329 FindAlbumInfo(components[1], album_map.get(), &album_info); 338 FindAlbumInfo(components[1], album_map.get(), &album_info);
330 if (error != base::File::FILE_OK) 339 if (error != base::File::FILE_OK)
331 return error; 340 return error;
332 341
333 // Not part of this class's mandate to check that it actually exists. 342 // Not part of this class's mandate to check that it actually exists.
334 *local_file_path = album_info.path.Append(url.path().BaseName()); 343 *local_file_path = album_info.path.Append(components[2]);
335 return base::File::FILE_OK; 344 return base::File::FILE_OK;
336 } 345 }
337 346
338 return base::File::FILE_ERROR_NOT_FOUND; 347 return base::File::FILE_ERROR_NOT_FOUND;
339 break; 348 break;
340 } 349 }
341 350
342 // All other cases don't have a local path. The valid cases should be 351 // All other cases don't have a local path. The valid cases should be
343 // intercepted by GetFileInfo()/CreateFileEnumerator(). Invalid cases 352 // intercepted by GetFileInfo()/CreateFileEnumerator(). Invalid cases
344 // return a NOT_FOUND error. 353 // return a NOT_FOUND error.
(...skipping 30 matching lines...) Expand all
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698