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

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: Remove PmpTableReader::Init, fix up some tests 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.
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 const PmpColumnReader* category_column =
64 pmp_reader.AddColumn("category", PMP_TYPE_UINT32);
65 const PmpColumnReader* date_column =
66 pmp_reader.AddColumn("date", PMP_TYPE_DOUBLE64);
67 const PmpColumnReader* filename_column =
68 pmp_reader.AddColumn("filename", PMP_TYPE_STRING);
69 const PmpColumnReader* name_column =
70 pmp_reader.AddColumn("name", PMP_TYPE_STRING);
71 const PmpColumnReader* token_column =
72 pmp_reader.AddColumn("token", PMP_TYPE_STRING);
73 const PmpColumnReader* uid_column =
74 pmp_reader.AddColumn("uid", PMP_TYPE_STRING);
75
76 if (pmp_reader.Columns().size() != 6)
77 return false;
78
79 for (uint32 i = 0; i < pmp_reader.RowCount(); i++) {
80 uint32 category = kAlbumCategoryInvalid;
81 double date = 0;
82 std::string name;
83 if (!category_column->ReadUInt32(i, &category) ||
84 !date_column->ReadDouble64(i, &date) ||
85 !name_column->ReadString(i, &name) || name.empty()) {
86 continue;
87 }
88
89 base::Time timestamp = TimeFromMicrosoftVariantTime(date);
90
91 switch (category) {
92 case kAlbumCategoryUserAlbum: {
93 std::string token, uid;
94 if (!token_column->ReadString(i, &token) || token.empty() ||
95 !uid_column->ReadString(i, &uid) || uid.empty() ||
96 token.substr(0, kAlbumTokenPrefix.size()) != kAlbumTokenPrefix) {
97 continue;
98 }
99
100 user_albums_.push_back(AlbumInfo(name, timestamp, uid));
101 break;
102 }
103 case kAlbumCategoryFolder: {
104 std::string filename;
105 if (!filename_column->ReadString(i, &filename) || filename.empty())
106 continue;
107
108 #if defined(OS_WIN)
vandebo (ex-Chrome) 2013/04/11 20:29:22 FromUTF8Unsafe
tommycli 2013/04/11 20:51:28 Done.
109 base::FilePath path = base::FilePath(UTF8ToUTF16(filename));
110 #else
111 base::FilePath path = base::FilePath(filename);
112 #endif
113 folders_.push_back(FolderInfo(name, timestamp, path));
114 break;
115 }
116 default: {
117 break;
118 }
119 }
120 }
121
122 return true;
123 }
124
125 } // namespace picasaimport
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698