Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "pmp_albumdata_table_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 | |
| 13 namespace picasaimport { | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 const int kColCategory = 0; | |
| 18 const int kColDate = 1; | |
| 19 const int kColFilename = 2; | |
| 20 const int kColName = 3; | |
| 21 const int kColToken = 4; | |
| 22 const int kColUid = 5; | |
| 23 | |
| 24 const uint16 albumdata_field_types[] = { | |
| 25 PMP_UINT32_TYPE, | |
| 26 PMP_DOUBLE64_TYPE, | |
| 27 PMP_STRING_TYPE, | |
| 28 PMP_STRING_TYPE, | |
| 29 PMP_STRING_TYPE, | |
| 30 PMP_STRING_TYPE | |
| 31 }; | |
| 32 | |
| 33 int albumdata_columns_len = 6; | |
| 34 | |
| 35 const uint16 kAlbumCategoryUserAlbum = 0; | |
| 36 const uint16 kAlbumCategoryFolder = 2; | |
| 37 const uint16 kAlbumCategoryInvalid = 0xffff; | |
| 38 | |
| 39 const int kPmpVariantTimeEpochYear = 1899; | |
| 40 const int kPmpVariantTimeEpochMonth = 12; | |
| 41 const int kPmpVariantTimeEpochDay = 30; | |
| 42 | |
| 43 // |variant_time| is specified as the number of days from Dec 30, 1899. | |
| 44 base::Time TimeFromMicrosoftVariantTime(double variant_time) { | |
| 45 base::Time::Exploded variant_epoch; | |
| 46 | |
| 47 // First set to Dec 30, 1899, (variant time epoch). | |
| 48 variant_epoch.year = kPmpVariantTimeEpochYear; | |
| 49 variant_epoch.month = kPmpVariantTimeEpochMonth; | |
| 50 variant_epoch.day_of_month = kPmpVariantTimeEpochDay; | |
| 51 | |
| 52 base::TimeDelta variant_delta = base::TimeDelta::FromMicroseconds( | |
|
vandebo (ex-Chrome)
2013/04/06 01:10:30
why not FromDays ?
tommycli
2013/04/08 17:17:29
Because the argument is an integer, and VariantTim
| |
| 53 static_cast<int64>(variant_time * base::Time::kMicrosecondsPerDay)); | |
| 54 | |
| 55 return base::Time::FromLocalExploded(variant_epoch) + variant_delta; | |
| 56 } | |
| 57 | |
| 58 } // namespace | |
| 59 | |
| 60 PmpAlbumdataTableReader::PmpAlbumdataTableReader() : PmpTableReader() { } | |
| 61 | |
| 62 PmpAlbumdataTableReader::~PmpAlbumdataTableReader() { } | |
| 63 | |
| 64 bool PmpAlbumdataTableReader::Init(const base::FilePath& directory_path) { | |
| 65 const std::string kAlbumTokenPrefix = "]album:"; | |
| 66 | |
| 67 std::vector<std::string> column_names; | |
| 68 column_names.push_back("category"); | |
| 69 column_names.push_back("date"); | |
| 70 column_names.push_back("filename"); | |
| 71 column_names.push_back("name"); | |
| 72 column_names.push_back("token"); | |
| 73 column_names.push_back("uid"); | |
| 74 | |
| 75 if(!PmpTableReader::Init("albumdata", directory_path, column_names)) | |
| 76 return false; | |
| 77 | |
| 78 std::vector<const PmpColumnReader*> columns = GetColumns(); | |
| 79 | |
| 80 // Abort if column types aren't as expected. | |
| 81 for(int i = 0; i < albumdata_columns_len; i++) { | |
| 82 if(columns[i]->field_type() != albumdata_field_types[i]) | |
| 83 return false; | |
| 84 } | |
| 85 | |
| 86 for(uint32 i = 0; i < RowCount(); i++) { | |
| 87 uint32 category = kAlbumCategoryInvalid; | |
| 88 double date; | |
| 89 std::string name, filename, token, uid; | |
| 90 | |
| 91 if(!columns[kColCategory]->ReadUInt32(i, &category) || | |
|
vandebo (ex-Chrome)
2013/04/06 01:10:30
columns[constant number] suggests that maybe a bet
tommycli
2013/04/08 17:17:29
Agreed. I'd like to move forward with what we have
vandebo (ex-Chrome)
2013/04/08 19:02:30
The other CL can go in as is, but lets fix it in t
tommycli
2013/04/09 00:45:33
Done.
| |
| 92 !columns[kColDate]->ReadDouble64(i, &date) || | |
| 93 !columns[kColName]->ReadString(i, &name) || name.empty()) { | |
| 94 continue; | |
| 95 } | |
| 96 | |
| 97 AlbumInfo album; | |
| 98 album.name = name; | |
| 99 album.timestamp = TimeFromMicrosoftVariantTime(date); | |
| 100 | |
| 101 switch(category) { | |
| 102 case kAlbumCategoryUserAlbum: { | |
| 103 if(!columns[kColName]->ReadString(i, &name) || name.empty() || | |
| 104 !columns[kColToken]->ReadString(i, &token) || token.empty() || | |
| 105 !columns[kColUid]->ReadString(i, &uid) || uid.empty() || | |
| 106 token.substr(0, kAlbumTokenPrefix.size()) != kAlbumTokenPrefix) { | |
| 107 continue; | |
| 108 } | |
| 109 | |
| 110 album.category = PICASA_USER_ALBUM; | |
| 111 album.name = name; | |
| 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 album.category = PICASA_FOLDER; | |
| 122 #if defined(OS_WIN) | |
|
tommycli
2013/04/05 23:04:08
I'm using this ugly idiom so often. file_path.h al
vandebo (ex-Chrome)
2013/04/06 01:10:30
The bar for adding to base is pretty high...
| |
| 123 album.path = base::FilePath(UTF8ToUTF16(filename)); | |
| 124 #else | |
| 125 album.path = base::FilePath(filename); | |
| 126 #endif | |
| 127 | |
| 128 folders_.push_back(album); | |
|
vandebo (ex-Chrome)
2013/04/06 01:10:30
It looks like some some fields are valid only for
tommycli
2013/04/08 17:17:29
Done.
| |
| 129 break; | |
| 130 } | |
| 131 default: { | |
| 132 break; | |
| 133 } | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 return true; | |
| 138 } | |
| 139 | |
| 140 } // namespace picasaimport | |
| OLD | NEW |