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

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: Fix rvalue usage in move operation. 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..cf85d17debe1ed5fad96f708a6e0c8edd766f467
--- /dev/null
+++ b/webkit/fileapi/media/picasa/pmp_table_reader.cc
@@ -0,0 +1,93 @@
+// Copyright (c) 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/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(const std::string& table_name,
+ const base::FilePath& directory_path,
+ const std::vector<std::string>& columns)
+ : table_name_(table_name),
+ directory_path_(directory_path),
+ columns_(columns),
+ column_readers_(),
+ max_row_count_(0) { }
+
+PmpTableReader::~PmpTableReader() { }
+
+bool PmpTableReader::ReadFromDisk() {
+ // Expect to read some columns, otherwise, a programming error.
+ DCHECK(!columns_.empty());
+
+ // Directory must exist.
+ 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.
+ 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> current_col_readers;
vandebo (ex-Chrome) 2013/03/28 00:56:04 column_readers
tommycli 2013/03/29 00:16:01 Done.
+ uint32 current_max_rows_parsed = 0;
vandebo (ex-Chrome) 2013/03/28 00:56:04 max_row_count ?
tommycli 2013/03/29 00:16:01 Done.
+
+ // Construct the column readers.
+ for (std::vector<std::string>::const_iterator it = columns_.begin();
+ it != columns_.end(); it++) {
+ base::FilePath column_file_path = directory_path_.Append(
+ table_prefix + *it + "." + kPmpExtension);
+
+ PmpColumnReader* column_reader = new PmpColumnReader(*it);
+ current_col_readers.push_back(column_reader);
+
+ uint32 row_cnt;
+
+ // If file is not initialized, too small, or too large (50MB), fail out.
vandebo (ex-Chrome) 2013/03/28 00:56:04 redundant comment.
tommycli 2013/03/29 00:16:01 Done.
+ if (!column_reader->ReadFromFile(column_file_path, &row_cnt))
+ return false;
+
+ current_max_rows_parsed = std::max(current_max_rows_parsed, row_cnt);
+ }
+
+ // Actually succeeded. Set member data.
+ column_readers_.clear();
vandebo (ex-Chrome) 2013/03/28 00:56:04 Do you need to clear before assignment ?
tommycli 2013/03/29 00:16:01 Done.
+ column_readers_ = current_col_readers.Pass();
+ max_row_count_ = current_max_rows_parsed;
+
+ 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