Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: webkit/fileapi/media/picasa/pmp_table_reader.cc

Issue 13529028: PicasaAlbumTableReader for Media Galleries API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@0005-picasa-import-pmp-reader
Patch Set: Missing include. Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/threading/thread_restrictions.h"
12 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
13 #include "webkit/fileapi/media/picasa/pmp_column_reader.h" 14 #include "webkit/fileapi/media/picasa/pmp_column_reader.h"
14 #include "webkit/fileapi/media/picasa/pmp_constants.h"
15 15
16 namespace picasaimport { 16 namespace picasaimport {
17 17
18 namespace { 18 namespace {
19 19
20 COMPILE_ASSERT(sizeof(double) == 8, double_must_be_8_bytes_long); 20 COMPILE_ASSERT(sizeof(double) == 8, double_must_be_8_bytes_long);
21 21
22 } // namespace 22 } // namespace
23 23
24 PmpTableReader::PmpTableReader() : column_readers_(), max_row_count_(0) { } 24 PmpTableReader::PmpTableReader(const std::string& table_name,
25 const base::FilePath& directory_path)
26 : table_name_(table_name),
27 directory_path_(directory_path),
28 column_readers_(),
29 max_row_count_(0) {}
25 30
26 PmpTableReader::~PmpTableReader() { } 31 PmpTableReader::~PmpTableReader() {}
27 32
28 bool PmpTableReader::Init(const std::string& table_name, 33 bool PmpTableReader::Init() {
29 const base::FilePath& directory_path, 34 base::ThreadRestrictions::AssertIOAllowed();
30 const std::vector<std::string>& columns) {
31 DCHECK(!columns.empty());
32 35
33 if (!column_readers_.empty()) 36 if (!file_util::DirectoryExists(directory_path_))
34 return false; 37 return false;
35 38
36 if (!file_util::DirectoryExists(directory_path)) 39 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 40
42 #if defined(OS_WIN) 41 #if defined(OS_WIN)
43 base::FilePath indicator_file = directory_path.Append( 42 base::FilePath indicator_file = directory_path_.Append(
44 UTF8ToUTF16(indicator_file_name)); 43 UTF8ToUTF16(indicator_file_name));
45 #else 44 #else
46 base::FilePath indicator_file = 45 base::FilePath indicator_file =
47 directory_path.Append(indicator_file_name); 46 directory_path_.Append(indicator_file_name);
48 #endif 47 #endif
49 48
50 // Look for the indicator_file file, indicating table existence. 49 // Look for the indicator_file file, indicating table existence.
51 if (!file_util::PathExists(indicator_file) || 50 return file_util::PathExists(indicator_file) &&
52 file_util::DirectoryExists(indicator_file)) { 51 !file_util::DirectoryExists(indicator_file);
53 return false; 52 }
54 }
55 53
56 ScopedVector<PmpColumnReader> column_readers; 54 const PmpColumnReader* PmpTableReader::AddColumn(
57 uint32 max_row_count = 0; 55 const std::string& column_name, const PmpFieldType expected_type) {
58 56 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 57
63 #if defined(OS_WIN) 58 #if defined(OS_WIN)
64 base::FilePath column_file_path = directory_path.Append( 59 base::FilePath column_file_path = directory_path_.Append(
65 UTF8ToUTF16(filename)); 60 UTF8ToUTF16(filename));
66 #else 61 #else
67 base::FilePath column_file_path = directory_path.Append(filename); 62 base::FilePath column_file_path = directory_path_.Append(filename);
68 #endif 63 #endif
69 64
65 scoped_ptr<PmpColumnReader> column_reader(new PmpColumnReader(column_name));
70 66
71 PmpColumnReader* column_reader = new PmpColumnReader(); 67 uint32 row_count;
72 column_readers.push_back(column_reader); 68 if (!column_reader->Init(column_file_path, expected_type, &row_count))
69 return NULL;
73 70
74 uint32 row_cnt; 71 column_readers_.push_back(column_reader.release());
75 72
76 if (!column_reader->Init(column_file_path, &row_cnt)) 73 max_row_count_ = std::max(max_row_count_, row_count);
77 return false;
78 74
79 max_row_count = std::max(max_row_count, row_cnt); 75 return column_readers_.back();
80 }
81
82 column_readers_ = column_readers.Pass();
83 max_row_count_ = max_row_count;
84
85 return true;
86 } 76 }
87 77
88 uint32 PmpTableReader::RowCount() const { 78 uint32 PmpTableReader::RowCount() const {
89 return max_row_count_; 79 return max_row_count_;
90 } 80 }
91 81
92 std::vector<const PmpColumnReader*> PmpTableReader::GetColumns() const { 82 std::map<std::string, const PmpColumnReader*> PmpTableReader::Columns() const {
93 std::vector<const PmpColumnReader*> readers( 83 std::map<std::string, const PmpColumnReader*> column_map;
94 column_readers_.begin(), column_readers_.end()); 84
95 return readers; 85 for (ScopedVector<PmpColumnReader>::const_iterator it =
86 column_readers_.begin();
87 it != column_readers_.end(); ++it) {
88 column_map[(*it)->column_name()] = *it;
89 }
90
91 return column_map;
96 } 92 }
97 93
98 } // namespace picasaimport 94 } // namespace picasaimport
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698