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

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

Issue 12704024: Simple PMP reader to parse Picasa's metadata (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unused constant. Created 7 years, 9 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_table_reader.cc
diff --git a/webkit/fileapi/media/picasa/pmp_table_reader.cc b/webkit/fileapi/media/picasa/pmp_table_reader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9894667075eee54ea62dabfa08c47b17d5cc76ce
--- /dev/null
+++ b/webkit/fileapi/media/picasa/pmp_table_reader.cc
@@ -0,0 +1,90 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
vandebo (ex-Chrome) 2013/03/29 21:35:07 nit: no (c)
tommycli 2013/04/01 22:19:18 Done.
+// 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/pmp_table_reader.h"
+
+#include <algorithm>
+
+#include "base/file_util.h"
+#include "base/files/file_path.h"
+#include "base/logging.h"
+#include "webkit/fileapi/media/picasa/pmp_column_reader.h"
+#include "webkit/fileapi/media/picasa/pmp_constants.h"
+
+namespace fileapi {
+
+namespace {
+
+COMPILE_ASSERT(sizeof(double) == 8, double_must_be_8_bytes_long);
+
+} // namespace
+
+PmpTableReader::PmpTableReader() : column_readers_(), max_row_count_(0) { }
+
+PmpTableReader::~PmpTableReader() { }
+
+bool PmpTableReader::InitFromDisk(const std::string& table_name,
+ const base::FilePath& directory_path,
+ const std::vector<std::string>& columns) {
+ // Expect to read some columns, otherwise, a programming error.
vandebo (ex-Chrome) 2013/03/29 21:35:07 Remove comment.
tommycli 2013/04/01 22:19:18 Done.
+ DCHECK(!columns.empty());
+
+ // Only allow initialization once
vandebo (ex-Chrome) 2013/03/29 21:35:07 Remove comment.
tommycli 2013/04/01 22:19:18 Done.
+ if(!column_readers_.empty())
+ return false;
+
+ // Directory must exist.
vandebo (ex-Chrome) 2013/03/29 21:35:07 Remove comment.
tommycli 2013/04/01 22:19:18 Done.
+ if(!file_util::DirectoryExists(directory_path))
+ return false;
+
+ std::string table_prefix = table_name + "_";
+
+ // Look for the "%s_0".format(table_name_) file, indicating table existence.
vandebo (ex-Chrome) 2013/03/29 21:35:07 Does '"%s_0".format(table_name_)' mean table_name_
tommycli 2013/04/01 22:19:18 Done.
+ base::FilePath indicator_file = directory_path.Append(table_prefix + "0");
+
+ // Expect the indicator file to exist but not be a directory.
+ if(!file_util::PathExists(indicator_file) ||
+ file_util::DirectoryExists(indicator_file)) {
+ return false;
+ }
+
+ ScopedVector<PmpColumnReader> column_readers;
+ uint32 max_row_count = 0;
+
+ // Construct the column readers.
vandebo (ex-Chrome) 2013/03/29 21:35:07 Remove comment.
tommycli 2013/04/01 22:19:18 Done.
+ for (std::vector<std::string>::const_iterator it = columns.begin();
+ it != columns.end(); it++) {
vandebo (ex-Chrome) 2013/03/29 21:35:07 ++it
tommycli 2013/04/01 22:19:18 Done.
+ base::FilePath column_file_path = directory_path.Append(
+ table_prefix + *it + "." + kPmpExtension);
+
+ PmpColumnReader* column_reader = new PmpColumnReader();
+ column_readers.push_back(column_reader);
+
+ uint32 row_cnt;
+
+ if (!column_reader->InitFromFile(column_file_path, &row_cnt))
+ return false;
+
+ max_row_count = std::max(max_row_count, row_cnt);
+ }
+
+ // Actually succeeded. Set member data.
vandebo (ex-Chrome) 2013/03/29 21:35:07 Remove comment.
tommycli 2013/04/01 22:19:18 Done.
+ column_readers_ = column_readers.Pass();
+ max_row_count_ = max_row_count;
+
+ return true;
+}
+
+uint32 PmpTableReader::RowCount() const {
+ return max_row_count_;
+}
+
+std::vector<const PmpColumnReader*> PmpTableReader::GetColumns() const {
+ std::vector<const PmpColumnReader*> readers;
+ std::copy(column_readers_.begin(), column_readers_.end(),
+ std::back_inserter(readers));
+ return readers;
+}
+
+} // namespace fileapi

Powered by Google App Engine
This is Rietveld 408576698