| 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_data_provider.h" | 5 #include "chrome/browser/media_galleries/fileapi/itunes_data_provider.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 base::Bind(&ITunesDataProvider::OnLibraryParsed, | 192 base::Bind(&ITunesDataProvider::OnLibraryParsed, |
| 193 weak_factory_.GetWeakPtr(), | 193 weak_factory_.GetWeakPtr(), |
| 194 ready_callback)); | 194 ready_callback)); |
| 195 } | 195 } |
| 196 | 196 |
| 197 const base::FilePath& ITunesDataProvider::auto_add_path() const { | 197 const base::FilePath& ITunesDataProvider::auto_add_path() const { |
| 198 return auto_add_path_; | 198 return auto_add_path_; |
| 199 } | 199 } |
| 200 | 200 |
| 201 bool ITunesDataProvider::KnownArtist(const ArtistName& artist) const { | 201 bool ITunesDataProvider::KnownArtist(const ArtistName& artist) const { |
| 202 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 202 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
| 203 DCHECK(valid()); | 203 DCHECK(valid()); |
| 204 return base::ContainsKey(library_, artist); | 204 return base::ContainsKey(library_, artist); |
| 205 } | 205 } |
| 206 | 206 |
| 207 bool ITunesDataProvider::KnownAlbum(const ArtistName& artist, | 207 bool ITunesDataProvider::KnownAlbum(const ArtistName& artist, |
| 208 const AlbumName& album) const { | 208 const AlbumName& album) const { |
| 209 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 209 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
| 210 DCHECK(valid()); | 210 DCHECK(valid()); |
| 211 Library::const_iterator library_it = library_.find(artist); | 211 Library::const_iterator library_it = library_.find(artist); |
| 212 if (library_it == library_.end()) | 212 if (library_it == library_.end()) |
| 213 return false; | 213 return false; |
| 214 return base::ContainsKey(library_it->second, album); | 214 return base::ContainsKey(library_it->second, album); |
| 215 } | 215 } |
| 216 | 216 |
| 217 base::FilePath ITunesDataProvider::GetTrackLocation( | 217 base::FilePath ITunesDataProvider::GetTrackLocation( |
| 218 const ArtistName& artist, const AlbumName& album, | 218 const ArtistName& artist, const AlbumName& album, |
| 219 const TrackName& track) const { | 219 const TrackName& track) const { |
| 220 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 220 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
| 221 DCHECK(valid()); | 221 DCHECK(valid()); |
| 222 Library::const_iterator library_it = library_.find(artist); | 222 Library::const_iterator library_it = library_.find(artist); |
| 223 if (library_it == library_.end()) | 223 if (library_it == library_.end()) |
| 224 return base::FilePath(); | 224 return base::FilePath(); |
| 225 | 225 |
| 226 Artist::const_iterator artist_it = library_it->second.find(album); | 226 Artist::const_iterator artist_it = library_it->second.find(album); |
| 227 if (artist_it == library_it->second.end()) | 227 if (artist_it == library_it->second.end()) |
| 228 return base::FilePath(); | 228 return base::FilePath(); |
| 229 | 229 |
| 230 Album::const_iterator album_it = artist_it->second.find(track); | 230 Album::const_iterator album_it = artist_it->second.find(track); |
| 231 if (album_it == artist_it->second.end()) | 231 if (album_it == artist_it->second.end()) |
| 232 return base::FilePath(); | 232 return base::FilePath(); |
| 233 return album_it->second; | 233 return album_it->second; |
| 234 } | 234 } |
| 235 | 235 |
| 236 std::set<ITunesDataProvider::ArtistName> | 236 std::set<ITunesDataProvider::ArtistName> |
| 237 ITunesDataProvider::GetArtistNames() const { | 237 ITunesDataProvider::GetArtistNames() const { |
| 238 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 238 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
| 239 DCHECK(valid()); | 239 DCHECK(valid()); |
| 240 std::set<ArtistName> result; | 240 std::set<ArtistName> result; |
| 241 Library::const_iterator it; | 241 Library::const_iterator it; |
| 242 for (it = library_.begin(); it != library_.end(); ++it) { | 242 for (it = library_.begin(); it != library_.end(); ++it) { |
| 243 result.insert(it->first); | 243 result.insert(it->first); |
| 244 } | 244 } |
| 245 return result; | 245 return result; |
| 246 } | 246 } |
| 247 | 247 |
| 248 std::set<ITunesDataProvider::AlbumName> ITunesDataProvider::GetAlbumNames( | 248 std::set<ITunesDataProvider::AlbumName> ITunesDataProvider::GetAlbumNames( |
| 249 const ArtistName& artist) const { | 249 const ArtistName& artist) const { |
| 250 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 250 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
| 251 DCHECK(valid()); | 251 DCHECK(valid()); |
| 252 std::set<AlbumName> result; | 252 std::set<AlbumName> result; |
| 253 Library::const_iterator artist_lookup = library_.find(artist); | 253 Library::const_iterator artist_lookup = library_.find(artist); |
| 254 if (artist_lookup == library_.end()) | 254 if (artist_lookup == library_.end()) |
| 255 return result; | 255 return result; |
| 256 | 256 |
| 257 const Artist& artist_entry = artist_lookup->second; | 257 const Artist& artist_entry = artist_lookup->second; |
| 258 Artist::const_iterator it; | 258 Artist::const_iterator it; |
| 259 for (it = artist_entry.begin(); it != artist_entry.end(); ++it) { | 259 for (it = artist_entry.begin(); it != artist_entry.end(); ++it) { |
| 260 result.insert(it->first); | 260 result.insert(it->first); |
| 261 } | 261 } |
| 262 return result; | 262 return result; |
| 263 } | 263 } |
| 264 | 264 |
| 265 ITunesDataProvider::Album ITunesDataProvider::GetAlbum( | 265 ITunesDataProvider::Album ITunesDataProvider::GetAlbum( |
| 266 const ArtistName& artist, const AlbumName& album) const { | 266 const ArtistName& artist, const AlbumName& album) const { |
| 267 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 267 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
| 268 DCHECK(valid()); | 268 DCHECK(valid()); |
| 269 Album result; | 269 Album result; |
| 270 Library::const_iterator artist_lookup = library_.find(artist); | 270 Library::const_iterator artist_lookup = library_.find(artist); |
| 271 if (artist_lookup != library_.end()) { | 271 if (artist_lookup != library_.end()) { |
| 272 Artist::const_iterator album_lookup = artist_lookup->second.find(album); | 272 Artist::const_iterator album_lookup = artist_lookup->second.find(album); |
| 273 if (album_lookup != artist_lookup->second.end()) | 273 if (album_lookup != artist_lookup->second.end()) |
| 274 result = album_lookup->second; | 274 result = album_lookup->second; |
| 275 } | 275 } |
| 276 return result; | 276 return result; |
| 277 } | 277 } |
| 278 | 278 |
| 279 void ITunesDataProvider::OnLibraryParsed(const ReadyCallback& ready_callback, | 279 void ITunesDataProvider::OnLibraryParsed(const ReadyCallback& ready_callback, |
| 280 bool result, | 280 bool result, |
| 281 const parser::Library& library) { | 281 const parser::Library& library) { |
| 282 DCHECK(MediaFileSystemBackend::CurrentlyOnMediaTaskRunnerThread()); | 282 MediaFileSystemBackend::AssertCurrentlyOnMediaSequence(); |
| 283 set_valid(result); | 283 set_valid(result); |
| 284 if (valid()) { | 284 if (valid()) { |
| 285 library_.clear(); | 285 library_.clear(); |
| 286 for (parser::Library::const_iterator artist_it = library.begin(); | 286 for (parser::Library::const_iterator artist_it = library.begin(); |
| 287 artist_it != library.end(); | 287 artist_it != library.end(); |
| 288 ++artist_it) { | 288 ++artist_it) { |
| 289 std::string artist_name = SanitizeName(artist_it->first); | 289 std::string artist_name = SanitizeName(artist_it->first); |
| 290 for (parser::Albums::const_iterator album_it = artist_it->second.begin(); | 290 for (parser::Albums::const_iterator album_it = artist_it->second.begin(); |
| 291 album_it != artist_it->second.end(); | 291 album_it != artist_it->second.end(); |
| 292 ++album_it) { | 292 ++album_it) { |
| 293 std::string album_name = SanitizeName(album_it->first); | 293 std::string album_name = SanitizeName(album_it->first); |
| 294 library_[artist_name][album_name] = | 294 library_[artist_name][album_name] = |
| 295 MakeUniqueTrackNames(album_it->second); | 295 MakeUniqueTrackNames(album_it->second); |
| 296 } | 296 } |
| 297 } | 297 } |
| 298 } | 298 } |
| 299 ready_callback.Run(valid()); | 299 ready_callback.Run(valid()); |
| 300 } | 300 } |
| 301 | 301 |
| 302 } // namespace itunes | 302 } // namespace itunes |
| OLD | NEW |