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