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 "chrome/browser/media_galleries/fileapi/picasa/pmp_table_reader.h" | |
6 | |
7 #include <algorithm> | |
8 | |
9 #include "base/file_util.h" | |
10 #include "base/logging.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "base/strings/utf_string_conversions.h" | |
13 #include "base/threading/thread_restrictions.h" | |
14 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_column_reader.h" | |
15 | |
16 namespace picasa { | |
17 | |
18 namespace { | |
19 | |
20 COMPILE_ASSERT(sizeof(double) == 8, double_must_be_8_bytes_long); | |
21 | |
22 } // namespace | |
23 | |
24 PmpTableReader::PmpTableReader(const std::string& table_name, | |
25 const base::FilePath& directory_path) | |
26 : initialized_(false), | |
27 table_name_(table_name), | |
28 directory_path_(directory_path), | |
29 max_row_count_(0) { | |
30 base::ThreadRestrictions::AssertIOAllowed(); | |
31 | |
32 if (!file_util::DirectoryExists(directory_path_)) | |
33 return; | |
34 | |
35 std::string indicator_file_name = table_name_ + "_0"; | |
36 | |
37 base::FilePath indicator_file = directory_path_.Append( | |
38 base::FilePath::FromUTF8Unsafe(indicator_file_name)); | |
39 | |
40 // Look for the indicator_file file, indicating table existence. | |
41 initialized_ = file_util::PathExists(indicator_file) && | |
42 !file_util::DirectoryExists(indicator_file); | |
43 } | |
44 | |
45 PmpTableReader::~PmpTableReader() {} | |
46 | |
47 const PmpColumnReader* PmpTableReader::AddColumn( | |
48 const std::string& column_name, const PmpFieldType expected_type) { | |
49 if (!initialized_) | |
50 return NULL; | |
51 | |
52 std::string filename = table_name_ + "_" + column_name + "." + kPmpExtension; | |
53 | |
54 base::FilePath column_file_path = directory_path_.Append( | |
55 base::FilePath::FromUTF8Unsafe(filename)); | |
56 scoped_ptr<PmpColumnReader> column_reader(new PmpColumnReader()); | |
57 | |
58 uint32 row_count; | |
59 if (!column_reader->Init(column_file_path, expected_type, &row_count)) | |
60 return NULL; | |
61 | |
62 column_readers_.push_back(column_reader.release()); | |
63 column_map_[column_name] = column_readers_.back(); | |
64 | |
65 max_row_count_ = std::max(max_row_count_, row_count); | |
66 | |
67 return column_readers_.back(); | |
68 } | |
69 | |
70 uint32 PmpTableReader::RowCount() const { | |
71 return max_row_count_; | |
72 } | |
73 | |
74 std::map<std::string, const PmpColumnReader*> PmpTableReader::Columns() const { | |
75 return column_map_; | |
76 } | |
77 | |
78 } // namespace picasa | |
OLD | NEW |