| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/utility/media_galleries/picasa_album_table_reader.h" | 5 #include "chrome/utility/media_galleries/picasa_album_table_reader.h" |
| 6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 7 #include <algorithm> | 9 #include <algorithm> |
| 8 #include <string> | 10 #include <string> |
| 9 | 11 |
| 10 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/common/media_galleries/pmp_constants.h" | 14 #include "chrome/common/media_galleries/pmp_constants.h" |
| 13 #include "chrome/utility/media_galleries/pmp_column_reader.h" | 15 #include "chrome/utility/media_galleries/pmp_column_reader.h" |
| 14 | 16 |
| 15 namespace picasa { | 17 namespace picasa { |
| 16 | 18 |
| 17 namespace { | 19 namespace { |
| 18 | 20 |
| 19 // |variant_time| is specified as the number of days from Dec 30, 1899. | 21 // |variant_time| is specified as the number of days from Dec 30, 1899. |
| 20 base::Time TimeFromMicrosoftVariantTime(double variant_time) { | 22 base::Time TimeFromMicrosoftVariantTime(double variant_time) { |
| 21 base::TimeDelta variant_delta = base::TimeDelta::FromMicroseconds( | 23 base::TimeDelta variant_delta = base::TimeDelta::FromMicroseconds( |
| 22 static_cast<int64>(variant_time * base::Time::kMicrosecondsPerDay)); | 24 static_cast<int64_t>(variant_time * base::Time::kMicrosecondsPerDay)); |
| 23 | 25 |
| 24 return base::Time::FromLocalExploded(kPmpVariantTimeEpoch) + variant_delta; | 26 return base::Time::FromLocalExploded(kPmpVariantTimeEpoch) + variant_delta; |
| 25 } | 27 } |
| 26 | 28 |
| 27 } // namespace | 29 } // namespace |
| 28 | 30 |
| 29 PicasaAlbumTableReader::PicasaAlbumTableReader(AlbumTableFiles table_files) | 31 PicasaAlbumTableReader::PicasaAlbumTableReader(AlbumTableFiles table_files) |
| 30 : table_files_(table_files.Pass()), | 32 : table_files_(table_files.Pass()), |
| 31 initialized_(false) { | 33 initialized_(false) { |
| 32 } | 34 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 57 !date_column.ReadFile(&table_files_.date_file, PMP_TYPE_DOUBLE64) || | 59 !date_column.ReadFile(&table_files_.date_file, PMP_TYPE_DOUBLE64) || |
| 58 !filename_column.ReadFile(&table_files_.filename_file, PMP_TYPE_STRING) || | 60 !filename_column.ReadFile(&table_files_.filename_file, PMP_TYPE_STRING) || |
| 59 !name_column.ReadFile(&table_files_.name_file, PMP_TYPE_STRING) || | 61 !name_column.ReadFile(&table_files_.name_file, PMP_TYPE_STRING) || |
| 60 !token_column.ReadFile(&table_files_.token_file, PMP_TYPE_STRING) || | 62 !token_column.ReadFile(&table_files_.token_file, PMP_TYPE_STRING) || |
| 61 !uid_column.ReadFile(&table_files_.uid_file, PMP_TYPE_STRING)) { | 63 !uid_column.ReadFile(&table_files_.uid_file, PMP_TYPE_STRING)) { |
| 62 return false; | 64 return false; |
| 63 } | 65 } |
| 64 | 66 |
| 65 // In the PMP format, columns can be different lengths. The number of rows | 67 // In the PMP format, columns can be different lengths. The number of rows |
| 66 // in the table is max of all the columns, and short columns are NULL padded. | 68 // in the table is max of all the columns, and short columns are NULL padded. |
| 67 uint32 row_count = 0; | 69 uint32_t row_count = 0; |
| 68 row_count = std::max(row_count, category_column.rows_read()); | 70 row_count = std::max(row_count, category_column.rows_read()); |
| 69 row_count = std::max(row_count, date_column.rows_read()); | 71 row_count = std::max(row_count, date_column.rows_read()); |
| 70 row_count = std::max(row_count, filename_column.rows_read()); | 72 row_count = std::max(row_count, filename_column.rows_read()); |
| 71 row_count = std::max(row_count, name_column.rows_read()); | 73 row_count = std::max(row_count, name_column.rows_read()); |
| 72 row_count = std::max(row_count, token_column.rows_read()); | 74 row_count = std::max(row_count, token_column.rows_read()); |
| 73 row_count = std::max(row_count, uid_column.rows_read()); | 75 row_count = std::max(row_count, uid_column.rows_read()); |
| 74 | 76 |
| 75 for (uint32 i = 0; i < row_count; i++) { | 77 for (uint32_t i = 0; i < row_count; i++) { |
| 76 uint32 category = kAlbumCategoryInvalid; | 78 uint32_t category = kAlbumCategoryInvalid; |
| 77 double date = 0; | 79 double date = 0; |
| 78 std::string name; | 80 std::string name; |
| 79 std::string uid; | 81 std::string uid; |
| 80 // PMP tables often contain 'garbage' rows of deleted or auto-generated | 82 // PMP tables often contain 'garbage' rows of deleted or auto-generated |
| 81 // album-like entities. We ignore those rows. | 83 // album-like entities. We ignore those rows. |
| 82 if (!category_column.ReadUInt32(i, &category) || | 84 if (!category_column.ReadUInt32(i, &category) || |
| 83 !date_column.ReadDouble64(i, &date) || | 85 !date_column.ReadDouble64(i, &date) || |
| 84 !name_column.ReadString(i, &name) || name.empty() || | 86 !name_column.ReadString(i, &name) || name.empty() || |
| 85 !uid_column.ReadString(i, &uid) || uid.empty()) { | 87 !uid_column.ReadString(i, &uid) || uid.empty()) { |
| 86 continue; | 88 continue; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 107 | 109 |
| 108 folders_.push_back(AlbumInfo(name, timestamp, uid, path)); | 110 folders_.push_back(AlbumInfo(name, timestamp, uid, path)); |
| 109 } | 111 } |
| 110 } | 112 } |
| 111 | 113 |
| 112 initialized_ = true; | 114 initialized_ = true; |
| 113 return true; | 115 return true; |
| 114 } | 116 } |
| 115 | 117 |
| 116 } // namespace picasa | 118 } // namespace picasa |
| OLD | NEW |