| 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 "webkit/fileapi/media/picasa/pmp_test_helper.h" | 5 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_test_helper.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iterator> | 8 #include <iterator> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "webkit/fileapi/media/picasa/pmp_column_reader.h" | 13 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_column_reader.h" |
| 14 | 14 |
| 15 namespace picasaimport { | 15 namespace picasaimport { |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 bool WriteToFile(const base::FilePath& path, std::vector<uint8> data) { | 19 bool WriteToFile(const base::FilePath& path, std::vector<uint8> data) { |
| 20 // Cast for usage in WriteFile function | 20 // Cast for usage in WriteFile function |
| 21 const char* data_char = reinterpret_cast<const char*>(&data[0]); | 21 const char* data_char = reinterpret_cast<const char*>(&data[0]); |
| 22 size_t bytes_written = file_util::WriteFile(path, data_char, data.size()); | 22 size_t bytes_written = file_util::WriteFile(path, data_char, data.size()); |
| 23 return (bytes_written == data.size()); | 23 return (bytes_written == data.size()); |
| 24 } | 24 } |
| 25 | 25 |
| 26 // Flatten a vector of elements into an array of bytes. | 26 // Flatten a vector of elements into an array of bytes. |
| 27 template<class T> | 27 template<class T> |
| 28 std::vector<uint8> Flatten(const std::vector<T>& elems) { | 28 std::vector<uint8> Flatten(const std::vector<T>& elems) { |
| 29 const uint8* elems0 = reinterpret_cast<const uint8*>(&elems[0]); | 29 const uint8* elems0 = reinterpret_cast<const uint8*>(&elems[0]); |
| 30 std::vector<uint8> data_body(elems0, elems0 + sizeof(T)*elems.size()); | 30 std::vector<uint8> data_body(elems0, elems0 + sizeof(T)*elems.size()); |
| 31 | 31 |
| 32 return data_body; | 32 return data_body; |
| 33 } | 33 } |
| 34 | 34 |
| 35 // Custom specialization for std::string. | 35 // Custom specialization for std::string. |
| 36 template<> | 36 template<> |
| 37 std::vector<uint8> Flatten(const std::vector<std::string>& strings) { | 37 std::vector<uint8> Flatten(const std::vector<std::string>& strings) { |
| 38 std::vector<uint8> totalchars; | 38 std::vector<uint8> totalchars; |
| 39 | 39 |
| 40 for(std::vector<std::string>::const_iterator it = strings.begin(); | 40 for (std::vector<std::string>::const_iterator it = strings.begin(); |
| 41 it != strings.end(); ++it) { | 41 it != strings.end(); ++it) { |
| 42 std::copy(it->begin(), it->end(), std::back_inserter(totalchars)); | 42 std::copy(it->begin(), it->end(), std::back_inserter(totalchars)); |
| 43 totalchars.push_back('\0'); // Add the null termination too. | 43 totalchars.push_back('\0'); // Add the null termination too. |
| 44 } | 44 } |
| 45 | 45 |
| 46 return totalchars; | 46 return totalchars; |
| 47 } | 47 } |
| 48 | 48 |
| 49 // Returns a new vector with the concatenated contents of |a| and |b|. | 49 // Returns a new vector with the concatenated contents of |a| and |b|. |
| 50 std::vector<uint8> CombinedVectors(const std::vector<uint8>& a, | 50 std::vector<uint8> CombinedVectors(const std::vector<uint8>& a, |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<uint32>( | 163 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<uint32>( |
| 164 const PmpFieldType, const uint32, const std::vector<uint32>&); | 164 const PmpFieldType, const uint32, const std::vector<uint32>&); |
| 165 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<double>( | 165 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<double>( |
| 166 const PmpFieldType, const uint32, const std::vector<double>&); | 166 const PmpFieldType, const uint32, const std::vector<double>&); |
| 167 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<uint8>( | 167 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<uint8>( |
| 168 const PmpFieldType, const uint32, const std::vector<uint8>&); | 168 const PmpFieldType, const uint32, const std::vector<uint8>&); |
| 169 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<uint64>( | 169 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<uint64>( |
| 170 const PmpFieldType, const uint32, const std::vector<uint64>&); | 170 const PmpFieldType, const uint32, const std::vector<uint64>&); |
| 171 | 171 |
| 172 } // namespace picasaimport | 172 } // namespace picasaimport |
| OLD | NEW |