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

Unified Diff: webkit/fileapi/media/picasa/pmp_albumdata_table_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/pmp_albumdata_table_reader.cc
diff --git a/webkit/fileapi/media/picasa/pmp_albumdata_table_reader.cc b/webkit/fileapi/media/picasa/pmp_albumdata_table_reader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d36c449eeff10860417736e8be6f5c2fd585523a
--- /dev/null
+++ b/webkit/fileapi/media/picasa/pmp_albumdata_table_reader.cc
@@ -0,0 +1,140 @@
+// 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 "pmp_albumdata_table_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"
+
+namespace picasaimport {
+
+namespace {
+
+const int kColCategory = 0;
+const int kColDate = 1;
+const int kColFilename = 2;
+const int kColName = 3;
+const int kColToken = 4;
+const int kColUid = 5;
+
+const uint16 albumdata_field_types[] = {
+ PMP_UINT32_TYPE,
+ PMP_DOUBLE64_TYPE,
+ PMP_STRING_TYPE,
+ PMP_STRING_TYPE,
+ PMP_STRING_TYPE,
+ PMP_STRING_TYPE
+};
+
+int albumdata_columns_len = 6;
+
+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).
+ variant_epoch.year = kPmpVariantTimeEpochYear;
+ variant_epoch.month = kPmpVariantTimeEpochMonth;
+ variant_epoch.day_of_month = kPmpVariantTimeEpochDay;
+
+ base::TimeDelta variant_delta = base::TimeDelta::FromMicroseconds(
vandebo (ex-Chrome) 2013/04/06 01:10:30 why not FromDays ?
tommycli 2013/04/08 17:17:29 Because the argument is an integer, and VariantTim
+ static_cast<int64>(variant_time * base::Time::kMicrosecondsPerDay));
+
+ return base::Time::FromLocalExploded(variant_epoch) + variant_delta;
+}
+
+} // namespace
+
+PmpAlbumdataTableReader::PmpAlbumdataTableReader() : PmpTableReader() { }
+
+PmpAlbumdataTableReader::~PmpAlbumdataTableReader() { }
+
+bool PmpAlbumdataTableReader::Init(const base::FilePath& directory_path) {
+ const std::string kAlbumTokenPrefix = "]album:";
+
+ std::vector<std::string> column_names;
+ column_names.push_back("category");
+ column_names.push_back("date");
+ column_names.push_back("filename");
+ column_names.push_back("name");
+ column_names.push_back("token");
+ column_names.push_back("uid");
+
+ if(!PmpTableReader::Init("albumdata", directory_path, column_names))
+ return false;
+
+ std::vector<const PmpColumnReader*> columns = GetColumns();
+
+ // Abort if column types aren't as expected.
+ for(int i = 0; i < albumdata_columns_len; i++) {
+ if(columns[i]->field_type() != albumdata_field_types[i])
+ return false;
+ }
+
+ for(uint32 i = 0; i < RowCount(); i++) {
+ uint32 category = kAlbumCategoryInvalid;
+ double date;
+ std::string name, filename, token, uid;
+
+ if(!columns[kColCategory]->ReadUInt32(i, &category) ||
vandebo (ex-Chrome) 2013/04/06 01:10:30 columns[constant number] suggests that maybe a bet
tommycli 2013/04/08 17:17:29 Agreed. I'd like to move forward with what we have
vandebo (ex-Chrome) 2013/04/08 19:02:30 The other CL can go in as is, but lets fix it in t
tommycli 2013/04/09 00:45:33 Done.
+ !columns[kColDate]->ReadDouble64(i, &date) ||
+ !columns[kColName]->ReadString(i, &name) || name.empty()) {
+ continue;
+ }
+
+ AlbumInfo album;
+ album.name = name;
+ album.timestamp = TimeFromMicrosoftVariantTime(date);
+
+ switch(category) {
+ case kAlbumCategoryUserAlbum: {
+ if(!columns[kColName]->ReadString(i, &name) || name.empty() ||
+ !columns[kColToken]->ReadString(i, &token) || token.empty() ||
+ !columns[kColUid]->ReadString(i, &uid) || uid.empty() ||
+ token.substr(0, kAlbumTokenPrefix.size()) != kAlbumTokenPrefix) {
+ continue;
+ }
+
+ album.category = PICASA_USER_ALBUM;
+ album.name = name;
+ album.uid = uid;
+
+ user_albums_.push_back(album);
+ break;
+ }
+ case kAlbumCategoryFolder: {
+ if(!columns[kColFilename]->ReadString(i, &filename) || filename.empty())
+ continue;
+
+ album.category = PICASA_FOLDER;
+#if defined(OS_WIN)
tommycli 2013/04/05 23:04:08 I'm using this ugly idiom so often. file_path.h al
vandebo (ex-Chrome) 2013/04/06 01:10:30 The bar for adding to base is pretty high...
+ album.path = base::FilePath(UTF8ToUTF16(filename));
+#else
+ album.path = base::FilePath(filename);
+#endif
+
+ folders_.push_back(album);
vandebo (ex-Chrome) 2013/04/06 01:10:30 It looks like some some fields are valid only for
tommycli 2013/04/08 17:17:29 Done.
+ break;
+ }
+ default: {
+ break;
+ }
+ }
+ }
+
+ return true;
+}
+
+} // namespace picasaimport

Powered by Google App Engine
This is Rietveld 408576698