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

Side by Side Diff: webkit/fileapi/media/picasa/picasa_album_table_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: Fix ifdef guard. 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_table_reader.h"
6
7 #include <vector>
8
9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h"
11 #include "webkit/fileapi/media/picasa/pmp_column_reader.h"
12 #include "webkit/fileapi/media/picasa/pmp_constants.h"
13 #include "webkit/fileapi/media/picasa/pmp_table_reader.h"
14
15 namespace picasaimport {
16
17 namespace {
18
19 // |variant_time| is specified as the number of days from Dec 30, 1899.
20 base::Time TimeFromMicrosoftVariantTime(double variant_time) {
21 base::Time::Exploded variant_epoch = {
22 1899, 12, 7, 30, // Dec 30, 1899 (Saturday)
23 0, 0, 0, 0 // 00:00:00.000
24 };
25
26 base::TimeDelta variant_delta = base::TimeDelta::FromMicroseconds(
27 static_cast<int64>(variant_time * base::Time::kMicrosecondsPerDay));
28
29 return base::Time::FromLocalExploded(variant_epoch) + variant_delta;
30 }
31
32 } // namespace
33
34 AlbumInfo::AlbumInfo(const std::string& name, const base::Time& timestamp,
35 const std::string& uid)
36 : name(name),
37 timestamp(timestamp),
38 uid(uid) {}
39
40 FolderInfo::FolderInfo(const std::string& name, const base::Time& timestamp,
41 const std::string& uid, const base::FilePath& path)
42 : name(name),
43 timestamp(timestamp),
44 uid(uid),
45 path(path) {}
46
47 PicasaAlbumTableReader::PicasaAlbumTableReader(
48 const base::FilePath& directory_path)
49 : directory_path_(directory_path),
50 initialized_(false) {}
51
52 PicasaAlbumTableReader::~PicasaAlbumTableReader() {}
53
54 bool PicasaAlbumTableReader::Init() {
55 PmpTableReader pmp_reader(kPicasaAlbumTableName, directory_path_);
56
57 const PmpColumnReader* category_column =
58 pmp_reader.AddColumn("category", PMP_TYPE_UINT32);
59 const PmpColumnReader* date_column =
60 pmp_reader.AddColumn("date", PMP_TYPE_DOUBLE64);
61 const PmpColumnReader* filename_column =
62 pmp_reader.AddColumn("filename", PMP_TYPE_STRING);
63 const PmpColumnReader* name_column =
64 pmp_reader.AddColumn("name", PMP_TYPE_STRING);
65 const PmpColumnReader* token_column =
66 pmp_reader.AddColumn("token", PMP_TYPE_STRING);
67 const PmpColumnReader* uid_column =
68 pmp_reader.AddColumn("uid", PMP_TYPE_STRING);
69
70 if (pmp_reader.Columns().size() != 6)
71 return false;
72
73 for (uint32 i = 0; i < pmp_reader.RowCount(); i++) {
74 uint32 category = kAlbumCategoryInvalid;
75 double date = 0;
76 std::string name, uid;
Greg Billock 2013/04/12 23:17:58 separate lines
tommycli 2013/04/12 23:44:04 Done.
77 if (!category_column->ReadUInt32(i, &category) ||
78 !date_column->ReadDouble64(i, &date) ||
79 !name_column->ReadString(i, &name) || name.empty() ||
80 !uid_column->ReadString(i, &uid) || uid.empty()) {
81 continue;
82 }
83
84 base::Time timestamp = TimeFromMicrosoftVariantTime(date);
85
86 switch (category) {
87 case kAlbumCategoryUserAlbum: {
88 std::string token;
89 if (!token_column->ReadString(i, &token) || token.empty() ||
90 !StartsWithASCII(token, kAlbumTokenPrefix, false)) {
91 continue;
92 }
93
94 user_albums_.push_back(AlbumInfo(name, timestamp, uid));
95 break;
96 }
97 case kAlbumCategoryFolder: {
98 std::string filename;
99 if (!filename_column->ReadString(i, &filename) || filename.empty())
100 continue;
101
102 base::FilePath path =
103 base::FilePath(base::FilePath::FromUTF8Unsafe(filename));
104
105 folders_.push_back(FolderInfo(name, timestamp, uid, path));
106 break;
107 }
108 default: {
109 break;
110 }
111 }
112 }
113
114 return initialized_ = true;
Greg Billock 2013/04/12 23:17:58 Looks like it maybe ought to be "return initialize
tommycli 2013/04/12 23:44:04 Done.
115 }
116
117 const std::vector<FolderInfo>& PicasaAlbumTableReader::folders() const {
118 DCHECK(initialized_);
119 return folders_;
120 }
121
122 const std::vector<AlbumInfo>& PicasaAlbumTableReader::user_albums() const {
123 DCHECK(initialized_);
124 return user_albums_;
125 }
126
127 } // namespace picasaimport
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698