Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Unified Diff: webkit/fileapi/media/picasa/picasa_album_data_reader.cc

Issue 13529028: PicasaAlbumTableReader for Media Galleries API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0005-picasa-import-pmp-reader
Patch Set: Formatting fixes. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/fileapi/media/picasa/picasa_album_data_reader.cc
diff --git a/webkit/fileapi/media/picasa/picasa_album_data_reader.cc b/webkit/fileapi/media/picasa/picasa_album_data_reader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2ff4ba33e08d2b6007b644dfd6e5bec4924acf4d
--- /dev/null
+++ b/webkit/fileapi/media/picasa/picasa_album_data_reader.cc
@@ -0,0 +1,131 @@
+// 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_data_reader.h"
+
+#include <vector>
+
+#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 {
+
+const uint16 kAlbumCategoryUserAlbum = 0;
+const uint16 kAlbumCategoryFolder = 2;
+const uint16 kAlbumCategoryInvalid = 0xffff;
+
+const int kPmpVariantTimeEpochYear = 1899;
+const int kPmpVariantTimeEpochMonth = 12;
+const int kPmpVariantTimeEpochDay = 30;
+
+// |variant_time| is specified as the number of days from Dec 30, 1899.
+base::Time TimeFromMicrosoftVariantTime(double variant_time) {
+ base::Time::Exploded variant_epoch;
+
+ // First set to Dec 30, 1899, (variant time epoch).
vandebo (ex-Chrome) 2013/04/08 23:57:24 remove comment.
tommycli 2013/04/09 00:45:34 Done.
+ variant_epoch.year = kPmpVariantTimeEpochYear;
+ variant_epoch.month = kPmpVariantTimeEpochMonth;
+ variant_epoch.day_of_month = kPmpVariantTimeEpochDay;
+
+ 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) { }
vandebo (ex-Chrome) 2013/04/08 23:57:24 nit: if the struct/class initializer list doesn't
tommycli 2013/04/09 00:45:34 Done.
+
+FolderInfo::FolderInfo(const std::string& name, const base::Time& timestamp,
+ const base::FilePath& path)
+ : name(name), timestamp(timestamp), path(path) { }
+
+PicasaAlbumDataReader::PicasaAlbumDataReader() { }
vandebo (ex-Chrome) 2013/04/08 23:57:24 nit: no space; {} or { }
tommycli 2013/04/09 00:45:34 Done.
+
+PicasaAlbumDataReader::~PicasaAlbumDataReader() { }
+
+bool PicasaAlbumDataReader::Init(const base::FilePath& directory_path) {
+ const std::string kAlbumTokenPrefix = "]album:";
+
+ PmpTableReader pmp_reader("albumdata", directory_path);
+
+ if (!pmp_reader.Init())
+ return false;
+
+ const PmpColumnReader* column_category =
vandebo (ex-Chrome) 2013/04/08 23:57:24 nit: category_column or just category
tommycli 2013/04/09 00:45:34 Done.
+ pmp_reader.AddColumn("category", PMP_UINT32_TYPE);
+ const PmpColumnReader* column_date =
+ pmp_reader.AddColumn("date", PMP_DOUBLE64_TYPE);
+ const PmpColumnReader* column_filename =
+ pmp_reader.AddColumn("filename", PMP_STRING_TYPE);
+ const PmpColumnReader* column_name =
+ pmp_reader.AddColumn("name", PMP_STRING_TYPE);
+ const PmpColumnReader* column_token =
+ pmp_reader.AddColumn("token", PMP_STRING_TYPE);
+ const PmpColumnReader* column_uid =
+ pmp_reader.AddColumn("uid", PMP_STRING_TYPE);
tommycli 2013/04/08 23:27:10 I wish all of these lined up in a pretty way.
+
+ if (!(column_category && column_date && column_filename && column_name &&
+ column_token && column_uid)) {
tommycli 2013/04/08 23:27:10 Is there a smarter way to check that they're all n
vandebo (ex-Chrome) 2013/04/08 23:57:24 It's not technically the same, but you could do Ge
tommycli 2013/04/09 00:45:34 Done.
+ return false;
+ }
+
+ for (uint32 i = 0; i < pmp_reader.RowCount(); i++) {
+ uint32 category = kAlbumCategoryInvalid;
+ std::string name;
+ double date = 0;
vandebo (ex-Chrome) 2013/04/08 23:57:24 very nit picky nit: move to the previous line so d
tommycli 2013/04/09 00:45:34 Done.
+
vandebo (ex-Chrome) 2013/04/08 23:57:24 nit: remove line
tommycli 2013/04/09 00:45:34 Done.
+ if (!column_category->ReadUInt32(i, &category) ||
+ !column_date->ReadDouble64(i, &date) ||
+ !column_name->ReadString(i, &name) || name.empty()) {
+ continue;
+ }
+
+ base::Time timestamp = TimeFromMicrosoftVariantTime(date);
+
+ switch (category) {
+ case kAlbumCategoryUserAlbum: {
+ std::string token, uid;
+
vandebo (ex-Chrome) 2013/04/08 23:57:24 nit: remove line
tommycli 2013/04/09 00:45:34 Done.
+ if (!column_token->ReadString(i, &token) || token.empty() ||
+ !column_uid->ReadString(i, &uid) || uid.empty() ||
+ token.substr(0, kAlbumTokenPrefix.size()) != kAlbumTokenPrefix) {
+ continue;
+ }
+
+ user_albums_.push_back(AlbumInfo(name, timestamp, uid));
+ break;
+ }
+ case kAlbumCategoryFolder: {
+ std::string filename;
+
vandebo (ex-Chrome) 2013/04/08 23:57:24 nit: remove line
tommycli 2013/04/09 00:45:34 Done.
+ if (!column_filename->ReadString(i, &filename) || filename.empty())
+ continue;
+
+#if defined(OS_WIN)
+ base::FilePath path = base::FilePath(UTF8ToUTF16(filename));
+#else
+ base::FilePath path = base::FilePath(filename);
+#endif
+
vandebo (ex-Chrome) 2013/04/08 23:57:24 nit: remove line
tommycli 2013/04/09 00:45:34 Done.
+ folders_.push_back(FolderInfo(name, timestamp, path));
+ break;
+ }
+ default: {
+ break;
+ }
+ }
+ }
+
+ return true;
+}
+
+} // namespace picasaimport

Powered by Google App Engine
This is Rietveld 408576698