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

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: Remove unused constant. 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 (c) 2013 The Chromium Authors. All rights reserved.
vandebo (ex-Chrome) 2013/03/29 21:35:07 nit: no (c)
tommycli 2013/04/01 22:19:18 Done.
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() : column_readers_(), max_row_count_(0) { }
24
25 PmpTableReader::~PmpTableReader() { }
26
27 bool PmpTableReader::InitFromDisk(const std::string& table_name,
28 const base::FilePath& directory_path,
29 const std::vector<std::string>& columns) {
30 // Expect to read some columns, otherwise, a programming error.
vandebo (ex-Chrome) 2013/03/29 21:35:07 Remove comment.
tommycli 2013/04/01 22:19:18 Done.
31 DCHECK(!columns.empty());
32
33 // Only allow initialization once
vandebo (ex-Chrome) 2013/03/29 21:35:07 Remove comment.
tommycli 2013/04/01 22:19:18 Done.
34 if(!column_readers_.empty())
35 return false;
36
37 // Directory must exist.
vandebo (ex-Chrome) 2013/03/29 21:35:07 Remove comment.
tommycli 2013/04/01 22:19:18 Done.
38 if(!file_util::DirectoryExists(directory_path))
39 return false;
40
41 std::string table_prefix = table_name + "_";
42
43 // Look for the "%s_0".format(table_name_) file, indicating table existence.
vandebo (ex-Chrome) 2013/03/29 21:35:07 Does '"%s_0".format(table_name_)' mean table_name_
tommycli 2013/04/01 22:19:18 Done.
44 base::FilePath indicator_file = directory_path.Append(table_prefix + "0");
45
46 // Expect the indicator file to exist but not be a directory.
47 if(!file_util::PathExists(indicator_file) ||
48 file_util::DirectoryExists(indicator_file)) {
49 return false;
50 }
51
52 ScopedVector<PmpColumnReader> column_readers;
53 uint32 max_row_count = 0;
54
55 // Construct the column readers.
vandebo (ex-Chrome) 2013/03/29 21:35:07 Remove comment.
tommycli 2013/04/01 22:19:18 Done.
56 for (std::vector<std::string>::const_iterator it = columns.begin();
57 it != columns.end(); it++) {
vandebo (ex-Chrome) 2013/03/29 21:35:07 ++it
tommycli 2013/04/01 22:19:18 Done.
58 base::FilePath column_file_path = directory_path.Append(
59 table_prefix + *it + "." + kPmpExtension);
60
61 PmpColumnReader* column_reader = new PmpColumnReader();
62 column_readers.push_back(column_reader);
63
64 uint32 row_cnt;
65
66 if (!column_reader->InitFromFile(column_file_path, &row_cnt))
67 return false;
68
69 max_row_count = std::max(max_row_count, row_cnt);
70 }
71
72 // Actually succeeded. Set member data.
vandebo (ex-Chrome) 2013/03/29 21:35:07 Remove comment.
tommycli 2013/04/01 22:19:18 Done.
73 column_readers_ = column_readers.Pass();
74 max_row_count_ = max_row_count;
75
76 return true;
77 }
78
79 uint32 PmpTableReader::RowCount() const {
80 return max_row_count_;
81 }
82
83 std::vector<const PmpColumnReader*> PmpTableReader::GetColumns() const {
84 std::vector<const PmpColumnReader*> readers;
85 std::copy(column_readers_.begin(), column_readers_.end(),
86 std::back_inserter(readers));
87 return readers;
88 }
89
90 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698