| 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/utility/media_galleries/itunes_library_parser.h" | 5 #include "chrome/utility/media_galleries/itunes_library_parser.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 base::FilePath location; | 25 base::FilePath location; |
| 26 std::string artist; | 26 std::string artist; |
| 27 std::string album; | 27 std::string album; |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 class TrackInfoXmlDictReader : public iapps::XmlDictReader { | 30 class TrackInfoXmlDictReader : public iapps::XmlDictReader { |
| 31 public: | 31 public: |
| 32 TrackInfoXmlDictReader(XmlReader* reader, TrackInfo* track_info) : | 32 TrackInfoXmlDictReader(XmlReader* reader, TrackInfo* track_info) : |
| 33 iapps::XmlDictReader(reader), track_info_(track_info) {} | 33 iapps::XmlDictReader(reader), track_info_(track_info) {} |
| 34 | 34 |
| 35 virtual bool ShouldLoop() override { | 35 bool ShouldLoop() override { |
| 36 return !(Found("Track ID") && Found("Location") && | 36 return !(Found("Track ID") && Found("Location") && |
| 37 Found("Album Artist") && Found("Album")); | 37 Found("Album Artist") && Found("Album")); |
| 38 } | 38 } |
| 39 | 39 |
| 40 virtual bool HandleKeyImpl(const std::string& key) override { | 40 bool HandleKeyImpl(const std::string& key) override { |
| 41 if (key == "Track ID") { | 41 if (key == "Track ID") { |
| 42 return iapps::ReadInteger(reader_, &track_info_->id); | 42 return iapps::ReadInteger(reader_, &track_info_->id); |
| 43 } else if (key == "Location") { | 43 } else if (key == "Location") { |
| 44 std::string value; | 44 std::string value; |
| 45 if (!iapps::ReadString(reader_, &value)) | 45 if (!iapps::ReadString(reader_, &value)) |
| 46 return false; | 46 return false; |
| 47 GURL url(value); | 47 GURL url(value); |
| 48 if (!url.SchemeIsFile()) | 48 if (!url.SchemeIsFile()) |
| 49 return false; | 49 return false; |
| 50 url::RawCanonOutputW<1024> decoded_location; | 50 url::RawCanonOutputW<1024> decoded_location; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 68 track_info_->artist.clear(); | 68 track_info_->artist.clear(); |
| 69 return iapps::ReadString(reader_, &track_info_->artist); | 69 return iapps::ReadString(reader_, &track_info_->artist); |
| 70 } else if (key == "Album") { | 70 } else if (key == "Album") { |
| 71 return iapps::ReadString(reader_, &track_info_->album); | 71 return iapps::ReadString(reader_, &track_info_->album); |
| 72 } else if (!SkipToNext()) { | 72 } else if (!SkipToNext()) { |
| 73 return false; | 73 return false; |
| 74 } | 74 } |
| 75 return true; | 75 return true; |
| 76 } | 76 } |
| 77 | 77 |
| 78 virtual bool FinishedOk() override { | 78 bool FinishedOk() override { return Found("Track ID") && Found("Location"); } |
| 79 return Found("Track ID") && Found("Location"); | |
| 80 } | |
| 81 | 79 |
| 82 private: | 80 private: |
| 83 TrackInfo* track_info_; | 81 TrackInfo* track_info_; |
| 84 }; | 82 }; |
| 85 | 83 |
| 86 // Walk through a dictionary filling in |result| with track information. Return | 84 // Walk through a dictionary filling in |result| with track information. Return |
| 87 // true if at least the id and location where found (artist and album may be | 85 // true if at least the id and location where found (artist and album may be |
| 88 // empty). In either case, the cursor is advanced out of the dictionary. | 86 // empty). In either case, the cursor is advanced out of the dictionary. |
| 89 bool GetTrackInfoFromDict(XmlReader* reader, TrackInfo* result) { | 87 bool GetTrackInfoFromDict(XmlReader* reader, TrackInfo* result) { |
| 90 DCHECK(result); | 88 DCHECK(result); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 track_found = true; | 153 track_found = true; |
| 156 } else { | 154 } else { |
| 157 no_errors = false; | 155 no_errors = false; |
| 158 } | 156 } |
| 159 } | 157 } |
| 160 | 158 |
| 161 return track_found || no_errors; | 159 return track_found || no_errors; |
| 162 } | 160 } |
| 163 | 161 |
| 164 } // namespace itunes | 162 } // namespace itunes |
| OLD | NEW |