Chromium Code Reviews| Index: webkit/fileapi/media/picasa/picasa_album_table_reader.cc |
| diff --git a/webkit/fileapi/media/picasa/picasa_album_table_reader.cc b/webkit/fileapi/media/picasa/picasa_album_table_reader.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..49f82e875f8127e022ccafc5ca498142549f6a84 |
| --- /dev/null |
| +++ b/webkit/fileapi/media/picasa/picasa_album_table_reader.cc |
| @@ -0,0 +1,127 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "webkit/fileapi/media/picasa/picasa_album_table_reader.h" |
| + |
| +#include <vector> |
| + |
| +#include "base/string_util.h" |
| +#include "base/utf_string_conversions.h" |
| +#include "webkit/fileapi/media/picasa/pmp_column_reader.h" |
| +#include "webkit/fileapi/media/picasa/pmp_constants.h" |
| +#include "webkit/fileapi/media/picasa/pmp_table_reader.h" |
| + |
| +namespace picasaimport { |
| + |
| +namespace { |
| + |
| +// |variant_time| is specified as the number of days from Dec 30, 1899. |
| +base::Time TimeFromMicrosoftVariantTime(double variant_time) { |
| + base::Time::Exploded variant_epoch = { |
| + 1899, 12, 7, 30, // Dec 30, 1899 (Saturday) |
| + 0, 0, 0, 0 // 00:00:00.000 |
| + }; |
| + |
| + base::TimeDelta variant_delta = base::TimeDelta::FromMicroseconds( |
| + static_cast<int64>(variant_time * base::Time::kMicrosecondsPerDay)); |
| + |
| + return base::Time::FromLocalExploded(variant_epoch) + variant_delta; |
| +} |
| + |
| +} // namespace |
| + |
| +AlbumInfo::AlbumInfo(const std::string& name, const base::Time& timestamp, |
| + const std::string& uid) |
| + : name(name), |
| + timestamp(timestamp), |
| + uid(uid) {} |
| + |
| +FolderInfo::FolderInfo(const std::string& name, const base::Time& timestamp, |
| + const std::string& uid, const base::FilePath& path) |
| + : name(name), |
| + timestamp(timestamp), |
| + uid(uid), |
| + path(path) {} |
| + |
| +PicasaAlbumTableReader::PicasaAlbumTableReader( |
| + const base::FilePath& directory_path) |
| + : directory_path_(directory_path), |
| + initialized_(false) {} |
| + |
| +PicasaAlbumTableReader::~PicasaAlbumTableReader() {} |
| + |
| +bool PicasaAlbumTableReader::Init() { |
| + PmpTableReader pmp_reader(kPicasaAlbumTableName, directory_path_); |
| + |
| + const PmpColumnReader* category_column = |
| + pmp_reader.AddColumn("category", PMP_TYPE_UINT32); |
| + const PmpColumnReader* date_column = |
| + pmp_reader.AddColumn("date", PMP_TYPE_DOUBLE64); |
| + const PmpColumnReader* filename_column = |
| + pmp_reader.AddColumn("filename", PMP_TYPE_STRING); |
| + const PmpColumnReader* name_column = |
| + pmp_reader.AddColumn("name", PMP_TYPE_STRING); |
| + const PmpColumnReader* token_column = |
| + pmp_reader.AddColumn("token", PMP_TYPE_STRING); |
| + const PmpColumnReader* uid_column = |
| + pmp_reader.AddColumn("uid", PMP_TYPE_STRING); |
| + |
| + if (pmp_reader.Columns().size() != 6) |
| + return false; |
| + |
| + for (uint32 i = 0; i < pmp_reader.RowCount(); i++) { |
| + uint32 category = kAlbumCategoryInvalid; |
| + double date = 0; |
| + std::string name, uid; |
|
Greg Billock
2013/04/12 23:17:58
separate lines
tommycli
2013/04/12 23:44:04
Done.
|
| + if (!category_column->ReadUInt32(i, &category) || |
| + !date_column->ReadDouble64(i, &date) || |
| + !name_column->ReadString(i, &name) || name.empty() || |
| + !uid_column->ReadString(i, &uid) || uid.empty()) { |
| + continue; |
| + } |
| + |
| + base::Time timestamp = TimeFromMicrosoftVariantTime(date); |
| + |
| + switch (category) { |
| + case kAlbumCategoryUserAlbum: { |
| + std::string token; |
| + if (!token_column->ReadString(i, &token) || token.empty() || |
| + !StartsWithASCII(token, kAlbumTokenPrefix, false)) { |
| + continue; |
| + } |
| + |
| + user_albums_.push_back(AlbumInfo(name, timestamp, uid)); |
| + break; |
| + } |
| + case kAlbumCategoryFolder: { |
| + std::string filename; |
| + if (!filename_column->ReadString(i, &filename) || filename.empty()) |
| + continue; |
| + |
| + base::FilePath path = |
| + base::FilePath(base::FilePath::FromUTF8Unsafe(filename)); |
| + |
| + folders_.push_back(FolderInfo(name, timestamp, uid, path)); |
| + break; |
| + } |
| + default: { |
| + break; |
| + } |
| + } |
| + } |
| + |
| + return initialized_ = true; |
|
Greg Billock
2013/04/12 23:17:58
Looks like it maybe ought to be "return initialize
tommycli
2013/04/12 23:44:04
Done.
|
| +} |
| + |
| +const std::vector<FolderInfo>& PicasaAlbumTableReader::folders() const { |
| + DCHECK(initialized_); |
| + return folders_; |
| +} |
| + |
| +const std::vector<AlbumInfo>& PicasaAlbumTableReader::user_albums() const { |
| + DCHECK(initialized_); |
| + return user_albums_; |
| +} |
| + |
| +} // namespace picasaimport |