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

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

Issue 12704024: Simple PMP reader to parse Picasa's metadata (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Make PmpTestHelper stateful and possess the temporary directory. 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
(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 "webkit/fileapi/media/picasa/pmp_column_reader.h"
13 #include "webkit/fileapi/media/picasa/pmp_constants.h"
14
15 namespace picasaimport {
16
17 namespace {
18
19 COMPILE_ASSERT(sizeof(double) == 8, double_must_be_8_bytes_long);
20
21 } // namespace
22
23 PmpTableReader::PmpTableReader() : column_readers_(), max_row_count_(0) { }
24
25 PmpTableReader::~PmpTableReader() { }
26
27 bool PmpTableReader::Init(const std::string& table_name,
28 const base::FilePath& directory_path,
29 const std::vector<std::string>& columns) {
30 DCHECK(!columns.empty());
31
32 if (!column_readers_.empty())
33 return false;
34
35 if (!file_util::DirectoryExists(directory_path))
36 return false;
37
38 std::string table_prefix = table_name + "_";
39
40 // Look for the (table_prefix + "_0") file, indicating table existence.
41 base::FilePath indicator_file = directory_path.Append(table_prefix + "0");
42
43 // Expect the indicator file to exist but not be a directory.
44 if (!file_util::PathExists(indicator_file) ||
45 file_util::DirectoryExists(indicator_file)) {
46 return false;
47 }
48
49 ScopedVector<PmpColumnReader> column_readers;
50 uint32 max_row_count = 0;
51
52 for (std::vector<std::string>::const_iterator it = columns.begin();
53 it != columns.end(); ++it) {
54 base::FilePath column_file_path = directory_path.Append(
55 table_prefix + *it + "." + kPmpExtension);
56
57 PmpColumnReader* column_reader = new PmpColumnReader();
58 column_readers.push_back(column_reader);
59
60 uint32 row_cnt;
61
62 if (!column_reader->Init(column_file_path, &row_cnt))
63 return false;
64
65 max_row_count = std::max(max_row_count, row_cnt);
66 }
67
68 column_readers_ = column_readers.Pass();
69 max_row_count_ = max_row_count;
70
71 return true;
72 }
73
74 uint32 PmpTableReader::RowCount() const {
75 return max_row_count_;
76 }
77
78 std::vector<const PmpColumnReader*> PmpTableReader::GetColumns() const {
79 std::vector<const PmpColumnReader*> readers;
80 std::copy(column_readers_.begin(), column_readers_.end(),
81 std::back_inserter(readers));
82 return readers;
83 }
84
85 } // namespace picasaimport
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698