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

Side by Side Diff: webkit/fileapi/media/picasa/picasa_albumdata_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: Address vandebo's comments. 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/picasa_albumdata_reader.h"
6
7 #include <vector>
8
9 #include "base/utf_string_conversions.h"
10 #include "webkit/fileapi/media/picasa/pmp_column_reader.h"
11 #include "webkit/fileapi/media/picasa/pmp_constants.h"
12 #include "webkit/fileapi/media/picasa/pmp_table_reader.h"
13
14 namespace picasaimport {
15
16 namespace {
17
18 const int kColCategory = 0;
19 const int kColDate = 1;
20 const int kColFilename = 2;
21 const int kColName = 3;
22 const int kColToken = 4;
23 const int kColUid = 5;
24
25 const uint16 albumdata_field_types[] = {
26 PMP_UINT32_TYPE,
27 PMP_DOUBLE64_TYPE,
28 PMP_STRING_TYPE,
29 PMP_STRING_TYPE,
30 PMP_STRING_TYPE,
31 PMP_STRING_TYPE
32 };
33
34 int albumdata_columns_len = 6;
35
36 const uint16 kAlbumCategoryUserAlbum = 0;
37 const uint16 kAlbumCategoryFolder = 2;
38 const uint16 kAlbumCategoryInvalid = 0xffff;
vandebo (ex-Chrome) 2013/04/08 19:02:30 Is this actually defined in PMP, or is this your s
tommycli 2013/04/08 23:27:10 Just a sentinel value.
vandebo (ex-Chrome) 2013/04/08 23:57:24 Maybe a quick comment to that effect then.
tommycli 2013/04/09 00:45:33 Done.
39
40 const int kPmpVariantTimeEpochYear = 1899;
41 const int kPmpVariantTimeEpochMonth = 12;
42 const int kPmpVariantTimeEpochDay = 30;
43
44 // |variant_time| is specified as the number of days from Dec 30, 1899.
45 base::Time TimeFromMicrosoftVariantTime(double variant_time) {
46 base::Time::Exploded variant_epoch;
47
48 // First set to Dec 30, 1899, (variant time epoch).
49 variant_epoch.year = kPmpVariantTimeEpochYear;
50 variant_epoch.month = kPmpVariantTimeEpochMonth;
51 variant_epoch.day_of_month = kPmpVariantTimeEpochDay;
52
53 base::TimeDelta variant_delta = base::TimeDelta::FromMicroseconds(
54 static_cast<int64>(variant_time * base::Time::kMicrosecondsPerDay));
55
56 return base::Time::FromLocalExploded(variant_epoch) + variant_delta;
57 }
58
59 } // namespace
60
61 PicasaAlbumdataReader::PicasaAlbumdataReader() { }
62
63 PicasaAlbumdataReader::~PicasaAlbumdataReader() { }
64
65 bool PicasaAlbumdataReader::Init(const base::FilePath& directory_path) {
66 const std::string kAlbumTokenPrefix = "]album:";
67
68 std::vector<std::string> column_names;
vandebo (ex-Chrome) 2013/04/08 19:02:30 As we discussed, to simplify this code, we can cha
tommycli 2013/04/08 23:27:10 Done.
69 column_names.push_back("category");
70 column_names.push_back("date");
71 column_names.push_back("filename");
72 column_names.push_back("name");
73 column_names.push_back("token");
74 column_names.push_back("uid");
75
76 PmpTableReader pmp_reader;
77
78 if(!pmp_reader.Init("albumdata", directory_path, column_names))
79 return false;
80
81 std::vector<const PmpColumnReader*> columns = pmp_reader.GetColumns();
82
83 // Abort if column types aren't as expected.
84 for(int i = 0; i < albumdata_columns_len; i++) {
85 if(columns[i]->field_type() != albumdata_field_types[i])
86 return false;
87 }
88
89 for(uint32 i = 0; i < pmp_reader.RowCount(); i++) {
90 uint32 category = kAlbumCategoryInvalid;
91 double date;
92 std::string name, filename, token, uid;
vandebo (ex-Chrome) 2013/04/08 19:02:30 Move token, filename, and uid into the scope that
tommycli 2013/04/08 23:27:10 Done.
93
94 if(!columns[kColCategory]->ReadUInt32(i, &category) ||
95 !columns[kColDate]->ReadDouble64(i, &date) ||
96 !columns[kColName]->ReadString(i, &name) || name.empty()) {
97 continue;
98 }
99
100 switch(category) {
vandebo (ex-Chrome) 2013/04/08 19:02:30 nit: space
tommycli 2013/04/08 23:27:10 Done.
101 case kAlbumCategoryUserAlbum: {
102 if(!columns[kColName]->ReadString(i, &name) || name.empty() ||
vandebo (ex-Chrome) 2013/04/08 19:02:30 You already read name, right?
tommycli 2013/04/08 23:27:10 Done.
103 !columns[kColToken]->ReadString(i, &token) || token.empty() ||
104 !columns[kColUid]->ReadString(i, &uid) || uid.empty() ||
105 token.substr(0, kAlbumTokenPrefix.size()) != kAlbumTokenPrefix) {
106 continue;
107 }
108
109 AlbumInfo album;
vandebo (ex-Chrome) 2013/04/08 19:02:30 A constructor for AlbumInfo would make this code s
tommycli 2013/04/08 23:27:10 Done.
110 album.name = name;
111 album.timestamp = TimeFromMicrosoftVariantTime(date);
112 album.uid = uid;
113
114 user_albums_.push_back(album);
115 break;
116 }
117 case kAlbumCategoryFolder: {
118 if(!columns[kColFilename]->ReadString(i, &filename) || filename.empty())
119 continue;
120
121 FolderInfo folder;
122 folder.name = name;
123 folder.timestamp = TimeFromMicrosoftVariantTime(date);
vandebo (ex-Chrome) 2013/04/08 19:02:30 Pull the conversion to base::Time to before the sw
tommycli 2013/04/08 23:27:10 Done.
124 #if defined(OS_WIN)
125 folder.path = base::FilePath(UTF8ToUTF16(filename));
126 #else
127 folder.path = base::FilePath(filename);
128 #endif
129
130 folders_.push_back(folder);
131 break;
132 }
133 default: {
134 break;
135 }
136 }
137 }
138
139 return true;
140 }
141
142 } // namespace picasaimport
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698