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

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: Missing include. 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; // Sentinel value.
vandebo (ex-Chrome) 2013/04/09 19:16:56 nit: two spaces before a comment.
tommycli 2013/04/11 18:24:05 Done.
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 variant_epoch.year = kPmpVariantTimeEpochYear;
31 variant_epoch.month = kPmpVariantTimeEpochMonth;
32 variant_epoch.day_of_month = kPmpVariantTimeEpochDay;
33
34 base::TimeDelta variant_delta = base::TimeDelta::FromMicroseconds(
35 static_cast<int64>(variant_time * base::Time::kMicrosecondsPerDay));
36
37 return base::Time::FromLocalExploded(variant_epoch) + variant_delta;
38 }
39
40 } // namespace
41
42 AlbumInfo::AlbumInfo(const std::string& name, const base::Time& timestamp,
43 const std::string& uid)
44 : name(name),
45 timestamp(timestamp),
46 uid(uid) {}
47
48 FolderInfo::FolderInfo(const std::string& name, const base::Time& timestamp,
49 const base::FilePath& path)
50 : name(name),
51 timestamp(timestamp),
52 path(path) {}
53
54 PicasaAlbumDataReader::PicasaAlbumDataReader() {}
55
56 PicasaAlbumDataReader::~PicasaAlbumDataReader() {}
57
58 bool PicasaAlbumDataReader::Init(const base::FilePath& directory_path) {
59 const std::string kAlbumTokenPrefix = "]album:";
60
61 PmpTableReader pmp_reader("albumdata", directory_path);
62
63 if (!pmp_reader.Init())
64 return false;
65
66 const PmpColumnReader* category_column =
67 pmp_reader.AddColumn("category", PMP_UINT32_TYPE);
68 const PmpColumnReader* date_column =
69 pmp_reader.AddColumn("date", PMP_DOUBLE64_TYPE);
70 const PmpColumnReader* filename_column =
71 pmp_reader.AddColumn("filename", PMP_STRING_TYPE);
72 const PmpColumnReader* name_column =
73 pmp_reader.AddColumn("name", PMP_STRING_TYPE);
74 const PmpColumnReader* token_column =
75 pmp_reader.AddColumn("token", PMP_STRING_TYPE);
76 const PmpColumnReader* uid_column =
77 pmp_reader.AddColumn("uid", PMP_STRING_TYPE);
78
79 if (pmp_reader.Columns().size() != 6)
80 return false;
81
82 for (uint32 i = 0; i < pmp_reader.RowCount(); i++) {
83 uint32 category = kAlbumCategoryInvalid;
84 double date = 0;
85 std::string name;
86 if (!category_column->ReadUInt32(i, &category) ||
87 !date_column->ReadDouble64(i, &date) ||
88 !name_column->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 if (!token_column->ReadString(i, &token) || token.empty() ||
98 !uid_column->ReadString(i, &uid) || uid.empty() ||
99 token.substr(0, kAlbumTokenPrefix.size()) != kAlbumTokenPrefix) {
100 continue;
101 }
102
103 user_albums_.push_back(AlbumInfo(name, timestamp, uid));
104 break;
105 }
106 case kAlbumCategoryFolder: {
107 std::string filename;
108 if (!filename_column->ReadString(i, &filename) || filename.empty())
109 continue;
110
111 #if defined(OS_WIN)
112 base::FilePath path = base::FilePath(UTF8ToUTF16(filename));
113 #else
114 base::FilePath path = base::FilePath(filename);
115 #endif
116 folders_.push_back(FolderInfo(name, timestamp, path));
117 break;
118 }
119 default: {
120 break;
121 }
122 }
123 }
124
125 return true;
126 }
127
128 } // namespace picasaimport
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698