| 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/itunes_file_util.h" | 5 #include "chrome/browser/media_galleries/fileapi/itunes_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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 storage::FileSystemOperationContext* context, | 188 storage::FileSystemOperationContext* context, |
| 189 const storage::FileSystemURL& url, | 189 const storage::FileSystemURL& url, |
| 190 EntryList* file_list) { | 190 EntryList* file_list) { |
| 191 DCHECK(file_list->empty()); | 191 DCHECK(file_list->empty()); |
| 192 std::vector<std::string> components = GetVirtualPathComponents(url); | 192 std::vector<std::string> components = GetVirtualPathComponents(url); |
| 193 | 193 |
| 194 if (components.size() == 0) { | 194 if (components.size() == 0) { |
| 195 base::File::Info xml_info; | 195 base::File::Info xml_info; |
| 196 if (!base::GetFileInfo(GetDataProvider()->library_path(), &xml_info)) | 196 if (!base::GetFileInfo(GetDataProvider()->library_path(), &xml_info)) |
| 197 return base::File::FILE_ERROR_IO; | 197 return base::File::FILE_ERROR_IO; |
| 198 file_list->push_back(DirectoryEntry(kITunesLibraryXML, | 198 file_list->push_back( |
| 199 DirectoryEntry::FILE, | 199 DirectoryEntry(kITunesLibraryXML, DirectoryEntry::FILE)); |
| 200 xml_info.size, xml_info.last_modified)); | 200 file_list->push_back( |
| 201 file_list->push_back(DirectoryEntry(kITunesMediaDir, | 201 DirectoryEntry(kITunesMediaDir, DirectoryEntry::DIRECTORY)); |
| 202 DirectoryEntry::DIRECTORY, | |
| 203 0, base::Time())); | |
| 204 return base::File::FILE_OK; | 202 return base::File::FILE_OK; |
| 205 } | 203 } |
| 206 | 204 |
| 207 if (components.size() == 1 && components[0] == kITunesLibraryXML) | 205 if (components.size() == 1 && components[0] == kITunesLibraryXML) |
| 208 return base::File::FILE_ERROR_NOT_A_DIRECTORY; | 206 return base::File::FILE_ERROR_NOT_A_DIRECTORY; |
| 209 | 207 |
| 210 if (components[0] != kITunesMediaDir || components.size() > 5) | 208 if (components[0] != kITunesMediaDir || components.size() > 5) |
| 211 return base::File::FILE_ERROR_NOT_FOUND; | 209 return base::File::FILE_ERROR_NOT_FOUND; |
| 212 | 210 |
| 213 if (components.size() == 1) { | 211 if (components.size() == 1) { |
| 214 if (!GetDataProvider()->auto_add_path().empty()) { | 212 if (!GetDataProvider()->auto_add_path().empty()) { |
| 215 file_list->push_back(DirectoryEntry(kITunesAutoAddDir, | 213 file_list->push_back( |
| 216 DirectoryEntry::DIRECTORY, | 214 DirectoryEntry(kITunesAutoAddDir, DirectoryEntry::DIRECTORY)); |
| 217 0, base::Time())); | |
| 218 } | 215 } |
| 219 file_list->push_back(DirectoryEntry(kITunesMusicDir, | 216 file_list->push_back( |
| 220 DirectoryEntry::DIRECTORY, | 217 DirectoryEntry(kITunesMusicDir, DirectoryEntry::DIRECTORY)); |
| 221 0, base::Time())); | |
| 222 return base::File::FILE_OK; | 218 return base::File::FILE_OK; |
| 223 } | 219 } |
| 224 | 220 |
| 225 if (components[1] == kITunesAutoAddDir && | 221 if (components[1] == kITunesAutoAddDir && |
| 226 !GetDataProvider()->auto_add_path().empty()) { | 222 !GetDataProvider()->auto_add_path().empty()) { |
| 227 return NativeMediaFileUtil::ReadDirectorySync(context, url, file_list); | 223 return NativeMediaFileUtil::ReadDirectorySync(context, url, file_list); |
| 228 } | 224 } |
| 229 | 225 |
| 230 if (components[1] != kITunesMusicDir) | 226 if (components[1] != kITunesMusicDir) |
| 231 return base::File::FILE_ERROR_NOT_FOUND; | 227 return base::File::FILE_ERROR_NOT_FOUND; |
| 232 | 228 |
| 233 if (components.size() == 2) { | 229 if (components.size() == 2) { |
| 234 std::set<ITunesDataProvider::ArtistName> artists = | 230 std::set<ITunesDataProvider::ArtistName> artists = |
| 235 GetDataProvider()->GetArtistNames(); | 231 GetDataProvider()->GetArtistNames(); |
| 236 std::set<ITunesDataProvider::ArtistName>::const_iterator it; | 232 std::set<ITunesDataProvider::ArtistName>::const_iterator it; |
| 237 for (it = artists.begin(); it != artists.end(); ++it) | 233 for (it = artists.begin(); it != artists.end(); ++it) |
| 238 file_list->push_back(DirectoryEntry(*it, DirectoryEntry::DIRECTORY, | 234 file_list->push_back(DirectoryEntry(*it, DirectoryEntry::DIRECTORY)); |
| 239 0, base::Time())); | |
| 240 return base::File::FILE_OK; | 235 return base::File::FILE_OK; |
| 241 } | 236 } |
| 242 | 237 |
| 243 if (components.size() == 3) { | 238 if (components.size() == 3) { |
| 244 std::set<ITunesDataProvider::AlbumName> albums = | 239 std::set<ITunesDataProvider::AlbumName> albums = |
| 245 GetDataProvider()->GetAlbumNames(components[2]); | 240 GetDataProvider()->GetAlbumNames(components[2]); |
| 246 if (albums.size() == 0) | 241 if (albums.size() == 0) |
| 247 return base::File::FILE_ERROR_NOT_FOUND; | 242 return base::File::FILE_ERROR_NOT_FOUND; |
| 248 std::set<ITunesDataProvider::AlbumName>::const_iterator it; | 243 std::set<ITunesDataProvider::AlbumName>::const_iterator it; |
| 249 for (it = albums.begin(); it != albums.end(); ++it) | 244 for (it = albums.begin(); it != albums.end(); ++it) |
| 250 file_list->push_back(DirectoryEntry(*it, DirectoryEntry::DIRECTORY, | 245 file_list->push_back(DirectoryEntry(*it, DirectoryEntry::DIRECTORY)); |
| 251 0, base::Time())); | |
| 252 return base::File::FILE_OK; | 246 return base::File::FILE_OK; |
| 253 } | 247 } |
| 254 | 248 |
| 255 if (components.size() == 4) { | 249 if (components.size() == 4) { |
| 256 ITunesDataProvider::Album album = | 250 ITunesDataProvider::Album album = |
| 257 GetDataProvider()->GetAlbum(components[2], components[3]); | 251 GetDataProvider()->GetAlbum(components[2], components[3]); |
| 258 if (album.size() == 0) | 252 if (album.size() == 0) |
| 259 return base::File::FILE_ERROR_NOT_FOUND; | 253 return base::File::FILE_ERROR_NOT_FOUND; |
| 260 ITunesDataProvider::Album::const_iterator it; | 254 ITunesDataProvider::Album::const_iterator it; |
| 261 for (it = album.begin(); it != album.end(); ++it) { | 255 for (it = album.begin(); it != album.end(); ++it) { |
| 262 base::File::Info file_info; | 256 base::File::Info file_info; |
| 263 if (media_path_filter()->Match(it->second) && | 257 if (media_path_filter()->Match(it->second) && |
| 264 base::GetFileInfo(it->second, &file_info)) { | 258 base::GetFileInfo(it->second, &file_info)) { |
| 265 file_list->push_back(DirectoryEntry(it->first, DirectoryEntry::FILE, | 259 file_list->push_back(DirectoryEntry(it->first, DirectoryEntry::FILE)); |
| 266 file_info.size, | |
| 267 file_info.last_modified)); | |
| 268 } | 260 } |
| 269 } | 261 } |
| 270 return base::File::FILE_OK; | 262 return base::File::FILE_OK; |
| 271 } | 263 } |
| 272 | 264 |
| 273 // At this point, the only choice is one of two errors, but figuring out | 265 // At this point, the only choice is one of two errors, but figuring out |
| 274 // which one is required. | 266 // which one is required. |
| 275 DCHECK_EQ(4UL, components.size()); | 267 DCHECK_EQ(4UL, components.size()); |
| 276 base::FilePath location; | 268 base::FilePath location; |
| 277 location = GetDataProvider()->GetTrackLocation(components[1], components[2], | 269 location = GetDataProvider()->GetTrackLocation(components[1], components[2], |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 callback); | 405 callback); |
| 414 } | 406 } |
| 415 | 407 |
| 416 ITunesDataProvider* ITunesFileUtil::GetDataProvider() { | 408 ITunesDataProvider* ITunesFileUtil::GetDataProvider() { |
| 417 if (!imported_registry_) | 409 if (!imported_registry_) |
| 418 imported_registry_ = ImportedMediaGalleryRegistry::GetInstance(); | 410 imported_registry_ = ImportedMediaGalleryRegistry::GetInstance(); |
| 419 return imported_registry_->ITunesDataProvider(); | 411 return imported_registry_->ITunesDataProvider(); |
| 420 } | 412 } |
| 421 | 413 |
| 422 } // namespace itunes | 414 } // namespace itunes |
| OLD | NEW |