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

Side by Side Diff: chrome/common/media_galleries/pmp_test_helper.cc

Issue 23499006: Media Galleries API Picasa: Add file watch to invalidate database data on disk write. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
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/common/media_galleries/pmp_test_helper.h" 5 #include "chrome/common/media_galleries/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"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 return total; 52 return total;
53 } 53 }
54 54
55 } // namespace 55 } // namespace
56 56
57 PmpTestHelper::PmpTestHelper(const std::string& table_name) 57 PmpTestHelper::PmpTestHelper(const std::string& table_name)
58 : table_name_(table_name) { 58 : table_name_(table_name) {
59 } 59 }
60 60
61 bool PmpTestHelper::Init() { 61 bool PmpTestHelper::Init(ColumnFileDestination column_file_destination) {
62 if (!temp_dir_.CreateUniqueTempDir() || !temp_dir_.IsValid()) 62 if (!root_dir_.CreateUniqueTempDir() ||
63 !root_dir_.IsValid() ||
64 !file_util::CreateDirectory(GetDatabaseDirPath()) ||
65 !file_util::CreateDirectory(GetTempDirPath())) {
63 return false; 66 return false;
67 }
64 68
65 base::FilePath indicator_path = temp_dir_.path().Append( 69 if (column_file_destination == DATABASE_DIRECTORY)
70 column_file_destination_directory_ = GetDatabaseDirPath();
71 else if (column_file_destination == TEMPORARY_DIRECTORY)
72 column_file_destination_directory_ = GetTempDirPath();
73 else
74 NOTREACHED();
75
76 base::FilePath indicator_path = column_file_destination_directory_.Append(
66 base::FilePath::FromUTF8Unsafe(table_name_ + "_0")); 77 base::FilePath::FromUTF8Unsafe(table_name_ + "_0"));
67 78
68 return file_util::WriteFile(indicator_path, NULL, 0) == 0; 79 return file_util::WriteFile(indicator_path, NULL, 0) == 0;
69 } 80 }
70 81
71 base::FilePath PmpTestHelper::GetTempDirPath() { 82 base::FilePath PmpTestHelper::GetDatabaseDirPath() const {
72 DCHECK(temp_dir_.IsValid()); 83 DCHECK(root_dir_.IsValid());
73 return temp_dir_.path(); 84 return root_dir_.path().AppendASCII(kPicasaDatabaseDirName);
85 }
86
87 base::FilePath PmpTestHelper::GetTempDirPath() const {
88 DCHECK(root_dir_.IsValid());
89 return root_dir_.path().AppendASCII(kPicasaTempDirName);
74 } 90 }
75 91
76 template<class T> 92 template<class T>
77 bool PmpTestHelper::WriteColumnFileFromVector( 93 bool PmpTestHelper::WriteColumnFileFromVector(
78 const std::string& column_name, const PmpFieldType field_type, 94 const std::string& column_name, const PmpFieldType field_type,
79 const std::vector<T>& elements_vector) { 95 const std::vector<T>& elements_vector) const {
80 DCHECK(temp_dir_.IsValid());
81
82 std::string file_name = table_name_ + "_" + column_name + "." + kPmpExtension; 96 std::string file_name = table_name_ + "_" + column_name + "." + kPmpExtension;
83 97
84 base::FilePath path = temp_dir_.path().Append( 98 base::FilePath path =
85 base::FilePath::FromUTF8Unsafe(file_name)); 99 column_file_destination_directory_.AppendASCII(file_name);
86 100
87 std::vector<char> data = PmpTestHelper::MakeHeaderAndBody( 101 std::vector<char> data = PmpTestHelper::MakeHeaderAndBody(
88 field_type, elements_vector.size(), elements_vector); 102 field_type, elements_vector.size(), elements_vector);
89 103
90 size_t bytes_written = file_util::WriteFile(path, &data[0], data.size()); 104 size_t bytes_written = file_util::WriteFile(path, &data[0], data.size());
91 return (bytes_written == data.size()); 105 return (bytes_written == data.size());
92 } 106 }
93 107
94 // Explicit Instantiation for all the valid types. 108 // Explicit Instantiation for all the valid types.
95 template bool PmpTestHelper::WriteColumnFileFromVector<std::string>( 109 template bool PmpTestHelper::WriteColumnFileFromVector<std::string>(
96 const std::string&, const PmpFieldType, const std::vector<std::string>&); 110 const std::string&, const PmpFieldType,
111 const std::vector<std::string>&) const;
97 template bool PmpTestHelper::WriteColumnFileFromVector<uint32>( 112 template bool PmpTestHelper::WriteColumnFileFromVector<uint32>(
98 const std::string&, const PmpFieldType, const std::vector<uint32>&); 113 const std::string&, const PmpFieldType, const std::vector<uint32>&) const;
99 template bool PmpTestHelper::WriteColumnFileFromVector<double>( 114 template bool PmpTestHelper::WriteColumnFileFromVector<double>(
100 const std::string&, const PmpFieldType, const std::vector<double>&); 115 const std::string&, const PmpFieldType, const std::vector<double>&) const;
101 template bool PmpTestHelper::WriteColumnFileFromVector<uint8>( 116 template bool PmpTestHelper::WriteColumnFileFromVector<uint8>(
102 const std::string&, const PmpFieldType, const std::vector<uint8>&); 117 const std::string&, const PmpFieldType, const std::vector<uint8>&) const;
103 template bool PmpTestHelper::WriteColumnFileFromVector<uint64>( 118 template bool PmpTestHelper::WriteColumnFileFromVector<uint64>(
104 const std::string&, const PmpFieldType, const std::vector<uint64>&); 119 const std::string&, const PmpFieldType, const std::vector<uint64>&) const;
105 120
106 // Return a vector so we don't have to worry about memory management. 121 // Return a vector so we don't have to worry about memory management.
107 std::vector<char> PmpTestHelper::MakeHeader(const PmpFieldType field_type, 122 std::vector<char> PmpTestHelper::MakeHeader(const PmpFieldType field_type,
108 const uint32 row_count) { 123 const uint32 row_count) {
109 std::vector<char> header(picasa::kPmpHeaderSize); 124 std::vector<char> header(picasa::kPmpHeaderSize);
110 125
111 // Copy in magic bytes. 126 // Copy in magic bytes.
112 memcpy(&header[picasa::kPmpMagic1Offset], &picasa::kPmpMagic1, 127 memcpy(&header[picasa::kPmpMagic1Offset], &picasa::kPmpMagic1,
113 sizeof(picasa::kPmpMagic1)); 128 sizeof(picasa::kPmpMagic1));
114 memcpy(&header[picasa::kPmpMagic2Offset], &picasa::kPmpMagic2, 129 memcpy(&header[picasa::kPmpMagic2Offset], &picasa::kPmpMagic2,
(...skipping 30 matching lines...) Expand all
145 template std::vector<char> PmpTestHelper::MakeHeaderAndBody<uint32>( 160 template std::vector<char> PmpTestHelper::MakeHeaderAndBody<uint32>(
146 const PmpFieldType, const uint32, const std::vector<uint32>&); 161 const PmpFieldType, const uint32, const std::vector<uint32>&);
147 template std::vector<char> PmpTestHelper::MakeHeaderAndBody<double>( 162 template std::vector<char> PmpTestHelper::MakeHeaderAndBody<double>(
148 const PmpFieldType, const uint32, const std::vector<double>&); 163 const PmpFieldType, const uint32, const std::vector<double>&);
149 template std::vector<char> PmpTestHelper::MakeHeaderAndBody<uint8>( 164 template std::vector<char> PmpTestHelper::MakeHeaderAndBody<uint8>(
150 const PmpFieldType, const uint32, const std::vector<uint8>&); 165 const PmpFieldType, const uint32, const std::vector<uint8>&);
151 template std::vector<char> PmpTestHelper::MakeHeaderAndBody<uint64>( 166 template std::vector<char> PmpTestHelper::MakeHeaderAndBody<uint64>(
152 const PmpFieldType, const uint32, const std::vector<uint64>&); 167 const PmpFieldType, const uint32, const std::vector<uint64>&);
153 168
154 } // namespace picasa 169 } // namespace picasa
OLDNEW
« no previous file with comments | « chrome/common/media_galleries/pmp_test_helper.h ('k') | chrome/utility/media_galleries/picasa_album_table_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698