This source file includes following definitions.
- albums_images_
- HandleTriplet
- ParseFolderINI
#include "chrome/utility/media_galleries/picasa_albums_indexer.h"
#include <algorithm>
#include <utility>
#include <vector>
#include "base/ini_parser.h"
#include "base/logging.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
namespace picasa {
namespace {
const char kAlbumSectionHeader[] = ".album:";
const char kAlbumsKey[] = "albums";
const int kMaxDedupeNumber = 1000;
class PicasaINIParser : public base::INIParser {
public:
PicasaINIParser(
const base::FilePath& folder_path, AlbumImagesMap* albums_images)
: folder_path_(folder_path),
albums_images_(albums_images) {
}
virtual ~PicasaINIParser() {}
private:
virtual void HandleTriplet(const std::string& section,
const std::string& key,
const std::string& value) OVERRIDE {
if (key != kAlbumsKey)
return;
if (section.find(kAlbumSectionHeader) == 0)
return;
std::vector<std::string> containing_albums;
base::SplitString(value, ',', &containing_albums);
for (std::vector<std::string>::iterator it = containing_albums.begin();
it != containing_albums.end(); ++it) {
AlbumImagesMap::iterator album_map_it = albums_images_->find(*it);
if (album_map_it == albums_images_->end())
continue;
base::FilePath filename = base::FilePath::FromUTF8Unsafe(section);
AlbumImages& album_images = album_map_it->second;
if (album_images.insert(
std::make_pair(section, folder_path_.Append(filename))).second) {
continue;
}
for (int i = 1; i < kMaxDedupeNumber; ++i) {
std::string deduped_filename =
filename.InsertBeforeExtensionASCII(base::StringPrintf(" (%d)", i))
.AsUTF8Unsafe();
if (album_images.insert(
std::make_pair(deduped_filename, folder_path_.Append(filename)))
.second) {
break;
}
}
}
}
const base::FilePath folder_path_;
AlbumImagesMap* const albums_images_;
};
}
PicasaAlbumsIndexer::PicasaAlbumsIndexer(const AlbumUIDSet& album_uids) {
for (AlbumUIDSet::const_iterator it = album_uids.begin();
it != album_uids.end(); ++it) {
albums_images_[*it] = AlbumImages();
}
}
PicasaAlbumsIndexer::~PicasaAlbumsIndexer() {}
void PicasaAlbumsIndexer::ParseFolderINI(
const std::vector<picasa::FolderINIContents>& folders_inis) {
std::vector<picasa::FolderINIContents> folders_inis_sorted = folders_inis;
std::sort(folders_inis_sorted.begin(), folders_inis_sorted.end());
for (std::vector<picasa::FolderINIContents>::const_iterator it =
folders_inis_sorted.begin();
it != folders_inis_sorted.end();
++it) {
PicasaINIParser parser(it->folder_path, &albums_images_);
parser.Parse(it->ini_contents);
}
}
}