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/picasa_albums_indexer.h" | 5 #include "chrome/utility/media_galleries/picasa_albums_indexer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 13 #include "base/strings/string_util.h" |
13 #include "base/strings/stringprintf.h" | 14 #include "base/strings/stringprintf.h" |
14 #include "chrome/common/ini_parser.h" | 15 #include "chrome/common/ini_parser.h" |
15 | 16 |
16 namespace picasa { | 17 namespace picasa { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 const char kAlbumSectionHeader[] = ".album:"; | 21 const char kAlbumSectionHeader[] = ".album:"; |
21 const char kAlbumsKey[] = "albums"; | 22 const char kAlbumsKey[] = "albums"; |
22 const int kMaxDedupeNumber = 1000; // Chosen arbitrarily. | 23 const int kMaxDedupeNumber = 1000; // Chosen arbitrarily. |
23 | 24 |
24 class PicasaINIParser : public INIParser { | 25 class PicasaINIParser : public INIParser { |
25 public: | 26 public: |
26 PicasaINIParser( | 27 PicasaINIParser( |
27 const base::FilePath& folder_path, AlbumImagesMap* albums_images) | 28 const base::FilePath& folder_path, AlbumImagesMap* albums_images) |
28 : folder_path_(folder_path), | 29 : folder_path_(folder_path), |
29 albums_images_(albums_images) { | 30 albums_images_(albums_images) { |
30 } | 31 } |
31 ~PicasaINIParser() override {} | 32 ~PicasaINIParser() override {} |
32 | 33 |
33 private: | 34 private: |
34 void HandleTriplet(const std::string& section, | 35 void HandleTriplet(const std::string& section, |
35 const std::string& key, | 36 const std::string& key, |
36 const std::string& value) override { | 37 const std::string& value) override { |
37 if (key != kAlbumsKey) | 38 if (key != kAlbumsKey) |
38 return; | 39 return; |
39 | 40 |
40 // [.album:*] sections ignored as we get that data from the PMP files. | 41 // [.album:*] sections ignored as we get that data from the PMP files. |
41 if (section.find(kAlbumSectionHeader) == 0) | 42 if (base::StartsWith(section, kAlbumSectionHeader, |
| 43 base::CompareCase::SENSITIVE)) |
42 return; | 44 return; |
43 | 45 |
44 for (const std::string& album : base::SplitString( | 46 for (const std::string& album : base::SplitString( |
45 value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { | 47 value, ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
46 AlbumImagesMap::iterator album_map_it = albums_images_->find(album); | 48 AlbumImagesMap::iterator album_map_it = albums_images_->find(album); |
47 | 49 |
48 // Ignore entry if the album uid is not listed among in |album_uids| | 50 // Ignore entry if the album uid is not listed among in |album_uids| |
49 // in the constructor. Happens if the PMP and INI files are inconsistent. | 51 // in the constructor. Happens if the PMP and INI files are inconsistent. |
50 if (album_map_it == albums_images_->end()) | 52 if (album_map_it == albums_images_->end()) |
51 continue; | 53 continue; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 for (std::vector<picasa::FolderINIContents>::const_iterator it = | 104 for (std::vector<picasa::FolderINIContents>::const_iterator it = |
103 folders_inis_sorted.begin(); | 105 folders_inis_sorted.begin(); |
104 it != folders_inis_sorted.end(); | 106 it != folders_inis_sorted.end(); |
105 ++it) { | 107 ++it) { |
106 PicasaINIParser parser(it->folder_path, &albums_images_); | 108 PicasaINIParser parser(it->folder_path, &albums_images_); |
107 parser.Parse(it->ini_contents); | 109 parser.Parse(it->ini_contents); |
108 } | 110 } |
109 } | 111 } |
110 | 112 |
111 } // namespace picasa | 113 } // namespace picasa |
OLD | NEW |