| 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 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_PICASA_PMP_COLUMN_READER_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_PICASA_PMP_COLUMN_READER_H_ |
| 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_PICASA_PMP_COLUMN_READER_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_PICASA_PMP_COLUMN_READER_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/platform_file.h" |
| 13 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_constants.h" | 14 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_constants.h" |
| 14 | 15 |
| 15 namespace base { | 16 namespace base { |
| 16 class FilePath; | 17 class FilePath; |
| 17 } | 18 } |
| 18 | 19 |
| 19 namespace picasa { | 20 namespace picasa { |
| 20 | 21 |
| 21 // Reads a single PMP column from a file. | 22 // Reads a single PMP column from a file. |
| 22 class PmpColumnReader { | 23 class PmpColumnReader { |
| 23 public: | 24 public: |
| 24 PmpColumnReader(); | 25 PmpColumnReader(); |
| 25 virtual ~PmpColumnReader(); | 26 virtual ~PmpColumnReader(); |
| 26 | 27 |
| 27 // Returns true if read successfully. | 28 // Returns true if read successfully. |
| 28 // |rows_read| is undefined if returns false. | 29 // |rows_read| is undefined if returns false. |
| 29 bool Init(const base::FilePath& filepath, const PmpFieldType expected_type, | 30 bool Init(const base::PlatformFile& file, |
| 30 uint32* rows_read); | 31 const PmpFieldType expected_type); |
| 31 | 32 |
| 32 // These functions read the value of that |row| into |result|. | 33 // These functions read the value of that |row| into |result|. |
| 33 // Functions return false if the column is of the wrong type or the row | 34 // Functions return false if the column is of the wrong type or the row |
| 34 // is out of range. | 35 // is out of range. May only be called if successfully initialized. |
| 35 bool ReadString(const uint32 row, std::string* result) const; | 36 bool ReadString(const uint32 row, std::string* result) const; |
| 36 bool ReadUInt32(const uint32 row, uint32* result) const; | 37 bool ReadUInt32(const uint32 row, uint32* result) const; |
| 37 bool ReadDouble64(const uint32 row, double* result) const; | 38 bool ReadDouble64(const uint32 row, double* result) const; |
| 38 bool ReadUInt8(const uint32 row, uint8* result) const; | 39 bool ReadUInt8(const uint32 row, uint8* result) const; |
| 39 bool ReadUInt64(const uint32 row, uint64* result) const; | 40 bool ReadUInt64(const uint32 row, uint64* result) const; |
| 40 | 41 |
| 42 // May only be called if successfully initialized. |
| 43 uint32 rows() const; |
| 44 |
| 41 private: | 45 private: |
| 42 bool ParseData(const PmpFieldType expected_type, uint32* rows_read); | 46 bool ParseData(const PmpFieldType expected_type); |
| 43 // Returns the number of bytes parsed in the body, or, -1 on failure. | 47 // Returns the number of bytes parsed in the body, or, -1 on failure. |
| 44 int64 IndexStrings(); | 48 int64 IndexStrings(); |
| 45 | 49 |
| 46 // Source data | 50 // Source data |
| 47 scoped_ptr<uint8[]> data_; | 51 scoped_ptr<uint8[]> data_; |
| 48 int64 length_; | 52 int64 length_; |
| 49 | 53 |
| 50 // Header data | 54 // Header data |
| 51 PmpFieldType field_type_; | 55 PmpFieldType field_type_; |
| 52 uint32 rows_; | 56 uint32 rows_; |
| 53 | 57 |
| 54 // Index of string start locations if fields are strings. Empty otherwise. | 58 // Index of string start locations if fields are strings. Empty otherwise. |
| 55 std::vector<const char*> strings_; | 59 std::vector<const char*> strings_; |
| 56 | 60 |
| 57 DISALLOW_COPY_AND_ASSIGN(PmpColumnReader); | 61 DISALLOW_COPY_AND_ASSIGN(PmpColumnReader); |
| 58 }; | 62 }; |
| 59 | 63 |
| 60 } // namespace picasa | 64 } // namespace picasa |
| 61 | 65 |
| 62 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_PICASA_PMP_COLUMN_READER_H_ | 66 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_PICASA_PMP_COLUMN_READER_H_ |
| OLD | NEW |