Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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 "webkit/fileapi/media/picasa/pmp_column_reader.h" | |
| 13 #include "webkit/fileapi/media/picasa/pmp_constants.h" | |
| 14 | |
| 15 namespace fileapi { | |
| 16 | |
| 17 namespace { | |
| 18 | |
| 19 COMPILE_ASSERT(sizeof(double) == 8, double_must_be_8_bytes_long); | |
| 20 | |
| 21 } // namespace | |
| 22 | |
| 23 PmpTableReader::PmpTableReader(const std::string& table_name, | |
| 24 const base::FilePath& directory_path, | |
| 25 const std::vector<std::string>& columns) | |
| 26 : table_name_(table_name), | |
| 27 directory_path_(directory_path), | |
| 28 columns_(columns), | |
| 29 column_readers_(), | |
| 30 max_row_count_(0) { } | |
| 31 | |
| 32 PmpTableReader::~PmpTableReader() { } | |
| 33 | |
| 34 bool PmpTableReader::ReadFromDisk() { | |
| 35 // Expect to read some columns, otherwise, a programming error. | |
| 36 DCHECK(!columns_.empty()); | |
| 37 | |
| 38 // Directory must exist. | |
| 39 if(!file_util::DirectoryExists(directory_path_)) | |
| 40 return false; | |
| 41 | |
| 42 std::string table_prefix = table_name_ + "_"; | |
| 43 | |
| 44 // Look for the "%s_0".format(table_name_) file, indicating table existence. | |
| 45 base::FilePath indicator_file = directory_path_.Append(table_prefix + "0"); | |
| 46 | |
| 47 // Expect the indicator file to exist but not be a directory. | |
| 48 if(!file_util::PathExists(indicator_file) || | |
| 49 file_util::DirectoryExists(indicator_file)) { | |
| 50 return false; | |
| 51 } | |
| 52 | |
| 53 ScopedVector<PmpColumnReader> current_col_readers; | |
|
vandebo (ex-Chrome)
2013/03/28 00:56:04
column_readers
tommycli
2013/03/29 00:16:01
Done.
| |
| 54 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.
| |
| 55 | |
| 56 // Construct the column readers. | |
| 57 for (std::vector<std::string>::const_iterator it = columns_.begin(); | |
| 58 it != columns_.end(); it++) { | |
| 59 base::FilePath column_file_path = directory_path_.Append( | |
| 60 table_prefix + *it + "." + kPmpExtension); | |
| 61 | |
| 62 PmpColumnReader* column_reader = new PmpColumnReader(*it); | |
| 63 current_col_readers.push_back(column_reader); | |
| 64 | |
| 65 uint32 row_cnt; | |
| 66 | |
| 67 // 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.
| |
| 68 if (!column_reader->ReadFromFile(column_file_path, &row_cnt)) | |
| 69 return false; | |
| 70 | |
| 71 current_max_rows_parsed = std::max(current_max_rows_parsed, row_cnt); | |
| 72 } | |
| 73 | |
| 74 // Actually succeeded. Set member data. | |
| 75 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.
| |
| 76 column_readers_ = current_col_readers.Pass(); | |
| 77 max_row_count_ = current_max_rows_parsed; | |
| 78 | |
| 79 return true; | |
| 80 } | |
| 81 | |
| 82 uint32 PmpTableReader::RowCount() const { | |
| 83 return max_row_count_; | |
| 84 } | |
| 85 | |
| 86 std::vector<const PmpColumnReader*> PmpTableReader::GetColumns() const { | |
| 87 std::vector<const PmpColumnReader*> readers; | |
| 88 std::copy(column_readers_.begin(), column_readers_.end(), | |
| 89 std::back_inserter(readers)); | |
| 90 return readers; | |
| 91 } | |
| 92 | |
| 93 } // namespace fileapi | |
| OLD | NEW |