| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "webkit/fileapi/media/picasa/pmp_table_reader.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "base/file_util.h" |
| 10 #include "base/files/file_path.h" |
| 11 #include "base/logging.h" |
| 12 #include "base/utf_string_conversions.h" |
| 13 #include "webkit/fileapi/media/picasa/pmp_column_reader.h" |
| 14 #include "webkit/fileapi/media/picasa/pmp_constants.h" |
| 15 |
| 16 namespace picasaimport { |
| 17 |
| 18 namespace { |
| 19 |
| 20 COMPILE_ASSERT(sizeof(double) == 8, double_must_be_8_bytes_long); |
| 21 |
| 22 } // namespace |
| 23 |
| 24 PmpTableReader::PmpTableReader() : column_readers_(), max_row_count_(0) { } |
| 25 |
| 26 PmpTableReader::~PmpTableReader() { } |
| 27 |
| 28 bool PmpTableReader::Init(const std::string& table_name, |
| 29 const base::FilePath& directory_path, |
| 30 const std::vector<std::string>& columns) { |
| 31 DCHECK(!columns.empty()); |
| 32 |
| 33 if (!column_readers_.empty()) |
| 34 return false; |
| 35 |
| 36 if (!file_util::DirectoryExists(directory_path)) |
| 37 return false; |
| 38 |
| 39 std::string table_prefix = table_name + "_"; |
| 40 std::string indicator_file_name = table_prefix + "0"; |
| 41 |
| 42 #if defined(OS_WIN) |
| 43 base::FilePath indicator_file = directory_path.Append( |
| 44 UTF8ToUTF16(indicator_file_name)); |
| 45 #else |
| 46 base::FilePath indicator_file = |
| 47 directory_path.Append(indicator_file_name); |
| 48 #endif |
| 49 |
| 50 // Look for the indicator_file file, indicating table existence. |
| 51 if (!file_util::PathExists(indicator_file) || |
| 52 file_util::DirectoryExists(indicator_file)) { |
| 53 return false; |
| 54 } |
| 55 |
| 56 ScopedVector<PmpColumnReader> column_readers; |
| 57 uint32 max_row_count = 0; |
| 58 |
| 59 for (std::vector<std::string>::const_iterator it = columns.begin(); |
| 60 it != columns.end(); ++it) { |
| 61 std::string filename = table_prefix + *it + "." + kPmpExtension; |
| 62 |
| 63 #if defined(OS_WIN) |
| 64 base::FilePath column_file_path = directory_path.Append( |
| 65 UTF8ToUTF16(filename)); |
| 66 #else |
| 67 base::FilePath column_file_path = directory_path.Append(filename); |
| 68 #endif |
| 69 |
| 70 |
| 71 PmpColumnReader* column_reader = new PmpColumnReader(); |
| 72 column_readers.push_back(column_reader); |
| 73 |
| 74 uint32 row_cnt; |
| 75 |
| 76 if (!column_reader->Init(column_file_path, &row_cnt)) |
| 77 return false; |
| 78 |
| 79 max_row_count = std::max(max_row_count, row_cnt); |
| 80 } |
| 81 |
| 82 column_readers_ = column_readers.Pass(); |
| 83 max_row_count_ = max_row_count; |
| 84 |
| 85 return true; |
| 86 } |
| 87 |
| 88 uint32 PmpTableReader::RowCount() const { |
| 89 return max_row_count_; |
| 90 } |
| 91 |
| 92 std::vector<const PmpColumnReader*> PmpTableReader::GetColumns() const { |
| 93 std::vector<const PmpColumnReader*> readers( |
| 94 column_readers_.begin(), column_readers_.end()); |
| 95 return readers; |
| 96 } |
| 97 |
| 98 } // namespace picasaimport |
| OLD | NEW |