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

Side by Side Diff: webkit/fileapi/media/picasa/picasa_album_data_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: Formatting fixes. 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_album_data_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 uint16 kAlbumCategoryUserAlbum = 0;
19 const uint16 kAlbumCategoryFolder = 2;
20 const uint16 kAlbumCategoryInvalid = 0xffff;
21
22 const int kPmpVariantTimeEpochYear = 1899;
23 const int kPmpVariantTimeEpochMonth = 12;
24 const int kPmpVariantTimeEpochDay = 30;
25
26 // |variant_time| is specified as the number of days from Dec 30, 1899.
27 base::Time TimeFromMicrosoftVariantTime(double variant_time) {
28 base::Time::Exploded variant_epoch;
29
30 // First set to Dec 30, 1899, (variant time epoch).
vandebo (ex-Chrome) 2013/04/08 23:57:24 remove comment.
tommycli 2013/04/09 00:45:34 Done.
31 variant_epoch.year = kPmpVariantTimeEpochYear;
32 variant_epoch.month = kPmpVariantTimeEpochMonth;
33 variant_epoch.day_of_month = kPmpVariantTimeEpochDay;
34
35 base::TimeDelta variant_delta = base::TimeDelta::FromMicroseconds(
36 static_cast<int64>(variant_time * base::Time::kMicrosecondsPerDay));
37
38 return base::Time::FromLocalExploded(variant_epoch) + variant_delta;
39 }
40
41 } // namespace
42
43 AlbumInfo::AlbumInfo(const std::string& name, const base::Time& timestamp,
44 const std::string& uid)
45 : name(name), timestamp(timestamp), uid(uid) { }
vandebo (ex-Chrome) 2013/04/08 23:57:24 nit: if the struct/class initializer list doesn't
tommycli 2013/04/09 00:45:34 Done.
46
47 FolderInfo::FolderInfo(const std::string& name, const base::Time& timestamp,
48 const base::FilePath& path)
49 : name(name), timestamp(timestamp), path(path) { }
50
51 PicasaAlbumDataReader::PicasaAlbumDataReader() { }
vandebo (ex-Chrome) 2013/04/08 23:57:24 nit: no space; {} or { }
tommycli 2013/04/09 00:45:34 Done.
52
53 PicasaAlbumDataReader::~PicasaAlbumDataReader() { }
54
55 bool PicasaAlbumDataReader::Init(const base::FilePath& directory_path) {
56 const std::string kAlbumTokenPrefix = "]album:";
57
58 PmpTableReader pmp_reader("albumdata", directory_path);
59
60 if (!pmp_reader.Init())
61 return false;
62
63 const PmpColumnReader* column_category =
vandebo (ex-Chrome) 2013/04/08 23:57:24 nit: category_column or just category
tommycli 2013/04/09 00:45:34 Done.
64 pmp_reader.AddColumn("category", PMP_UINT32_TYPE);
65 const PmpColumnReader* column_date =
66 pmp_reader.AddColumn("date", PMP_DOUBLE64_TYPE);
67 const PmpColumnReader* column_filename =
68 pmp_reader.AddColumn("filename", PMP_STRING_TYPE);
69 const PmpColumnReader* column_name =
70 pmp_reader.AddColumn("name", PMP_STRING_TYPE);
71 const PmpColumnReader* column_token =
72 pmp_reader.AddColumn("token", PMP_STRING_TYPE);
73 const PmpColumnReader* column_uid =
74 pmp_reader.AddColumn("uid", PMP_STRING_TYPE);
tommycli 2013/04/08 23:27:10 I wish all of these lined up in a pretty way.
75
76 if (!(column_category && column_date && column_filename && column_name &&
77 column_token && column_uid)) {
tommycli 2013/04/08 23:27:10 Is there a smarter way to check that they're all n
vandebo (ex-Chrome) 2013/04/08 23:57:24 It's not technically the same, but you could do Ge
tommycli 2013/04/09 00:45:34 Done.
78 return false;
79 }
80
81 for (uint32 i = 0; i < pmp_reader.RowCount(); i++) {
82 uint32 category = kAlbumCategoryInvalid;
83 std::string name;
84 double date = 0;
vandebo (ex-Chrome) 2013/04/08 23:57:24 very nit picky nit: move to the previous line so d
tommycli 2013/04/09 00:45:34 Done.
85
vandebo (ex-Chrome) 2013/04/08 23:57:24 nit: remove line
tommycli 2013/04/09 00:45:34 Done.
86 if (!column_category->ReadUInt32(i, &category) ||
87 !column_date->ReadDouble64(i, &date) ||
88 !column_name->ReadString(i, &name) || name.empty()) {
89 continue;
90 }
91
92 base::Time timestamp = TimeFromMicrosoftVariantTime(date);
93
94 switch (category) {
95 case kAlbumCategoryUserAlbum: {
96 std::string token, uid;
97
vandebo (ex-Chrome) 2013/04/08 23:57:24 nit: remove line
tommycli 2013/04/09 00:45:34 Done.
98 if (!column_token->ReadString(i, &token) || token.empty() ||
99 !column_uid->ReadString(i, &uid) || uid.empty() ||
100 token.substr(0, kAlbumTokenPrefix.size()) != kAlbumTokenPrefix) {
101 continue;
102 }
103
104 user_albums_.push_back(AlbumInfo(name, timestamp, uid));
105 break;
106 }
107 case kAlbumCategoryFolder: {
108 std::string filename;
109
vandebo (ex-Chrome) 2013/04/08 23:57:24 nit: remove line
tommycli 2013/04/09 00:45:34 Done.
110 if (!column_filename->ReadString(i, &filename) || filename.empty())
111 continue;
112
113 #if defined(OS_WIN)
114 base::FilePath path = base::FilePath(UTF8ToUTF16(filename));
115 #else
116 base::FilePath path = base::FilePath(filename);
117 #endif
118
vandebo (ex-Chrome) 2013/04/08 23:57:24 nit: remove line
tommycli 2013/04/09 00:45:34 Done.
119 folders_.push_back(FolderInfo(name, timestamp, path));
120 break;
121 }
122 default: {
123 break;
124 }
125 }
126 }
127
128 return true;
129 }
130
131 } // namespace picasaimport
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698