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

Side by Side Diff: chrome/browser/media_galleries/fileapi/picasa/pmp_test_helper.cc

Issue 17101030: Media Galleries API - Picasa: Change PMP Parsing to deal with PlatformFile. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 6 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
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/browser/media_galleries/fileapi/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/platform_file.h"
12 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
13 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_column_reader.h" 14 #include "chrome/browser/media_galleries/fileapi/picasa/pmp_column_reader.h"
14 15
15 namespace picasa { 16 namespace picasa {
16 17
17 namespace { 18 namespace {
18 19
19 bool WriteToFile(const base::FilePath& path, std::vector<uint8> data) { 20 bool WriteToFile(const base::FilePath& path, std::vector<uint8> data) {
20 // Cast for usage in WriteFile function 21 // Cast for usage in WriteFile function
21 const char* data_char = reinterpret_cast<const char*>(&data[0]); 22 const char* data_char = reinterpret_cast<const char*>(&data[0]);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 const std::string&, const PmpFieldType, const std::vector<std::string>&); 104 const std::string&, const PmpFieldType, const std::vector<std::string>&);
104 template bool PmpTestHelper::WriteColumnFileFromVector<uint32>( 105 template bool PmpTestHelper::WriteColumnFileFromVector<uint32>(
105 const std::string&, const PmpFieldType, const std::vector<uint32>&); 106 const std::string&, const PmpFieldType, const std::vector<uint32>&);
106 template bool PmpTestHelper::WriteColumnFileFromVector<double>( 107 template bool PmpTestHelper::WriteColumnFileFromVector<double>(
107 const std::string&, const PmpFieldType, const std::vector<double>&); 108 const std::string&, const PmpFieldType, const std::vector<double>&);
108 template bool PmpTestHelper::WriteColumnFileFromVector<uint8>( 109 template bool PmpTestHelper::WriteColumnFileFromVector<uint8>(
109 const std::string&, const PmpFieldType, const std::vector<uint8>&); 110 const std::string&, const PmpFieldType, const std::vector<uint8>&);
110 template bool PmpTestHelper::WriteColumnFileFromVector<uint64>( 111 template bool PmpTestHelper::WriteColumnFileFromVector<uint64>(
111 const std::string&, const PmpFieldType, const std::vector<uint64>&); 112 const std::string&, const PmpFieldType, const std::vector<uint64>&);
112 113
113 bool PmpTestHelper::InitColumnReaderFromBytes(PmpColumnReader* const reader, 114 bool PmpTestHelper::InitColumnReaderFromBytes(
114 const std::vector<uint8>& data, 115 PmpColumnReader* const reader,
115 const PmpFieldType expected_type, 116 const std::vector<uint8>& data,
116 uint32* rows_read) { 117 const PmpFieldType expected_type) {
117 DCHECK(temp_dir_.IsValid()); 118 DCHECK(temp_dir_.IsValid());
118 119
119 base::FilePath temp_path; 120 base::FilePath temp_path;
120 121
121 if (!file_util::CreateTemporaryFileInDir(temp_dir_.path(), &temp_path) 122 if (!file_util::CreateTemporaryFileInDir(temp_dir_.path(), &temp_path)
122 || !WriteToFile(temp_path, data)) { 123 || !WriteToFile(temp_path, data)) {
123 return false; 124 return false;
124 } 125 }
125 126
126 bool success = reader->Init(temp_path, expected_type, rows_read); 127 int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ;
128 base::PlatformFile platform_file =
129 base::CreatePlatformFile(temp_path, flags, NULL, NULL);
130 if (platform_file == base::kInvalidPlatformFileValue)
131 return false;
127 132
133 bool read_success = reader->ReadFile(platform_file, expected_type);
134
135 base::ClosePlatformFile(platform_file);
128 file_util::Delete(temp_path, true); 136 file_util::Delete(temp_path, true);
Lei Zhang 2013/06/21 02:15:50 You probably don't want the second parameter to be
tommycli 2013/06/21 16:14:23 Done.
129 137
130 return success; 138 return read_success;
131
132 } 139 }
133 140
134 // Return a vector so we don't have to worry about memory management. 141 // Return a vector so we don't have to worry about memory management.
135 std::vector<uint8> PmpTestHelper::MakeHeader(const PmpFieldType field_type, 142 std::vector<uint8> PmpTestHelper::MakeHeader(const PmpFieldType field_type,
136 const uint32 row_count) { 143 const uint32 row_count) {
137 std::vector<uint8> header(picasa::kPmpHeaderSize); 144 std::vector<uint8> header(picasa::kPmpHeaderSize);
138 145
139 // Copy in magic bytes. 146 // Copy in magic bytes.
140 memcpy(&header[picasa::kPmpMagic1Offset], &picasa::kPmpMagic1, 147 memcpy(&header[picasa::kPmpMagic1Offset], &picasa::kPmpMagic1,
141 sizeof(picasa::kPmpMagic1)); 148 sizeof(picasa::kPmpMagic1));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<uint32>( 180 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<uint32>(
174 const PmpFieldType, const uint32, const std::vector<uint32>&); 181 const PmpFieldType, const uint32, const std::vector<uint32>&);
175 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<double>( 182 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<double>(
176 const PmpFieldType, const uint32, const std::vector<double>&); 183 const PmpFieldType, const uint32, const std::vector<double>&);
177 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<uint8>( 184 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<uint8>(
178 const PmpFieldType, const uint32, const std::vector<uint8>&); 185 const PmpFieldType, const uint32, const std::vector<uint8>&);
179 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<uint64>( 186 template std::vector<uint8> PmpTestHelper::MakeHeaderAndBody<uint64>(
180 const PmpFieldType, const uint32, const std::vector<uint64>&); 187 const PmpFieldType, const uint32, const std::vector<uint64>&);
181 188
182 } // namespace picasa 189 } // namespace picasa
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698