| 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..2692f62871e66f88956b512d1e0e48fec2598e8c
|
| --- /dev/null
|
| +++ b/webkit/fileapi/media/picasa/pmp_table_reader.cc
|
| @@ -0,0 +1,87 @@
|
| +// 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 "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);
|
| +}
|
| +
|
| +using std::string;
|
| +
|
| +PmpTableReader::PmpTableReader() : column_readers_(), max_row_count_(0) {
|
| +
|
| +}
|
| +
|
| +PmpTableReader::~PmpTableReader() {
|
| + for (std::vector<PmpColumnReader*>::iterator it = column_readers_.begin();
|
| + it != column_readers_.end(); it++) {
|
| + delete *it;
|
| + }
|
| +}
|
| +
|
| +bool PmpTableReader::ReadFromDisk(const string& table_name,
|
| + const base::FilePath& directory_path,
|
| + const std::vector<std::string>& columns) {
|
| + // Expect to read some columns, otherwise, no point in using this
|
| + DCHECK(!columns.empty());
|
| +
|
| + // Directory must exist
|
| + if(!file_util::DirectoryExists(directory_path)) {
|
| + return false;
|
| + }
|
| +
|
| + string table_prefix = table_name + "_";
|
| + string pmp_suffix = ".pmp";
|
| +
|
| + // 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;
|
| + }
|
| +
|
| + // Construct the column readers
|
| + for (std::vector<std::string>::const_iterator it = columns.begin();
|
| + it != columns.end(); it++) {
|
| + base::FilePath colfile_path = directory_path.Append(
|
| + table_prefix + *it + pmp_suffix);
|
| +
|
| + // Constructed on the heap due to PmpColumnReader disallowing
|
| + // copies and assignment.
|
| + PmpColumnReader* column_reader = new PmpColumnReader(*it);
|
| + column_readers_.push_back(column_reader);
|
| +
|
| + uint32 rows_parsed;
|
| + bool column_read_success = column_reader->ReadFromDisk(&rows_parsed,
|
| + colfile_path);
|
| +
|
| + // If couldn't read this column, fail out
|
| + if(!column_read_success) {
|
| + return false;
|
| + }
|
| +
|
| + if(rows_parsed > max_row_count_) {
|
| + max_row_count_ = rows_parsed;
|
| + }
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| +uint32 PmpTableReader::Count() {
|
| + return max_row_count_;
|
| +}
|
| +
|
| +} // namespace fileapi
|
|
|