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

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: Fix memory issue. Created 7 years, 9 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.
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 "base/file_util.h"
8 #include "base/files/file_path.h"
9 #include "base/logging.h"
10 #include "webkit/fileapi/media/picasa/pmp_column_reader.h"
11 #include "webkit/fileapi/media/picasa/pmp_constants.h"
12
13 namespace fileapi {
14
15 namespace {
16 COMPILE_ASSERT(sizeof(double) == 8, double_must_be_8_bytes_long);
17 }
18
19 using std::string;
20
21 PmpTableReader::PmpTableReader() : column_readers_(), max_row_count_(0) {
22
23 }
24
25 PmpTableReader::~PmpTableReader() {
26 for (std::vector<PmpColumnReader*>::iterator it = column_readers_.begin();
27 it != column_readers_.end(); it++) {
28 delete *it;
29 }
30 }
31
32 bool PmpTableReader::ReadFromDisk(const string& table_name,
33 const base::FilePath& directory_path,
34 const std::vector<std::string>& columns) {
35 // Expect to read some columns, otherwise, no point in using this
36 DCHECK(!columns.empty());
37
38 // Directory must exist
39 if(!file_util::DirectoryExists(directory_path)) {
40 return false;
41 }
42
43 string table_prefix = table_name + "_";
44 string pmp_suffix = ".pmp";
45
46 // Look for the "%s_0".format(table_name_) file, indicating table existence
47 base::FilePath indicator_file = directory_path.Append(table_prefix + "0");
48
49 // Expect the indicator file to exist but not be a directory
50 if(!file_util::PathExists(indicator_file) ||
51 file_util::DirectoryExists(indicator_file)) {
52 return false;
53 }
54
55 // Construct the column readers
56 for (std::vector<std::string>::const_iterator it = columns.begin();
57 it != columns.end(); it++) {
58 base::FilePath colfile_path = directory_path.Append(
59 table_prefix + *it + pmp_suffix);
60
61 // Constructed on the heap due to PmpColumnReader disallowing
62 // copies and assignment.
63 PmpColumnReader* column_reader = new PmpColumnReader(*it);
64 column_readers_.push_back(column_reader);
65
66 uint32 rows_parsed;
67 bool column_read_success = column_reader->ReadFromDisk(&rows_parsed,
68 colfile_path);
69
70 // If couldn't read this column, fail out
71 if(!column_read_success) {
72 return false;
73 }
74
75 if(rows_parsed > max_row_count_) {
76 max_row_count_ = rows_parsed;
77 }
78 }
79
80 return true;
81 }
82
83 uint32 PmpTableReader::Count() {
84 return max_row_count_;
85 }
86
87 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698