Commit b71e2501 authored by rvargas@chromium.org's avatar rvargas@chromium.org

Remove ClosePlatformFile from media galleries.

BUG=322664

Review URL: https://codereview.chromium.org/252683006

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266728 0039d316-1c4b-4281-b951-d872f2087c98
parent 4e2dec35
...@@ -945,9 +945,8 @@ void ChromeContentUtilityClient::OnParseITunesPrefXml( ...@@ -945,9 +945,8 @@ void ChromeContentUtilityClient::OnParseITunesPrefXml(
void ChromeContentUtilityClient::OnParseIPhotoLibraryXmlFile( void ChromeContentUtilityClient::OnParseIPhotoLibraryXmlFile(
const IPC::PlatformFileForTransit& iphoto_library_file) { const IPC::PlatformFileForTransit& iphoto_library_file) {
iphoto::IPhotoLibraryParser parser; iphoto::IPhotoLibraryParser parser;
base::PlatformFile file = base::File file = IPC::PlatformFileForTransitToFile(iphoto_library_file);
IPC::PlatformFileForTransitToPlatformFile(iphoto_library_file); bool result = parser.Parse(iapps::ReadFileAsString(file.Pass()));
bool result = parser.Parse(iapps::ReadPlatformFileAsString(file));
Send(new ChromeUtilityHostMsg_GotIPhotoLibrary(result, parser.library())); Send(new ChromeUtilityHostMsg_GotIPhotoLibrary(result, parser.library()));
ReleaseProcessIfNeeded(); ReleaseProcessIfNeeded();
} }
...@@ -957,9 +956,8 @@ void ChromeContentUtilityClient::OnParseIPhotoLibraryXmlFile( ...@@ -957,9 +956,8 @@ void ChromeContentUtilityClient::OnParseIPhotoLibraryXmlFile(
void ChromeContentUtilityClient::OnParseITunesLibraryXmlFile( void ChromeContentUtilityClient::OnParseITunesLibraryXmlFile(
const IPC::PlatformFileForTransit& itunes_library_file) { const IPC::PlatformFileForTransit& itunes_library_file) {
itunes::ITunesLibraryParser parser; itunes::ITunesLibraryParser parser;
base::PlatformFile file = base::File file = IPC::PlatformFileForTransitToFile(itunes_library_file);
IPC::PlatformFileForTransitToPlatformFile(itunes_library_file); bool result = parser.Parse(iapps::ReadFileAsString(file.Pass()));
bool result = parser.Parse(iapps::ReadPlatformFileAsString(file));
Send(new ChromeUtilityHostMsg_GotITunesLibrary(result, parser.library())); Send(new ChromeUtilityHostMsg_GotITunesLibrary(result, parser.library()));
ReleaseProcessIfNeeded(); ReleaseProcessIfNeeded();
} }
......
...@@ -77,28 +77,23 @@ bool ReadInteger(XmlReader* reader, uint64* result) { ...@@ -77,28 +77,23 @@ bool ReadInteger(XmlReader* reader, uint64* result) {
return base::StringToUint64(value, result); return base::StringToUint64(value, result);
} }
std::string ReadPlatformFileAsString(const base::PlatformFile file) { std::string ReadFileAsString(base::File file) {
std::string result; std::string result;
if (file == base::kInvalidPlatformFileValue) if (!file.IsValid())
return result; return result;
// A "reasonable" artificial limit. // A "reasonable" artificial limit.
// TODO(vandebo): Add a UMA to figure out what common values are. // TODO(vandebo): Add a UMA to figure out what common values are.
const int64 kMaxLibraryFileSize = 150 * 1024 * 1024; const int64 kMaxLibraryFileSize = 150 * 1024 * 1024;
base::PlatformFileInfo file_info; base::File::Info file_info;
if (!base::GetPlatformFileInfo(file, &file_info) || if (!file.GetInfo(&file_info) || file_info.size > kMaxLibraryFileSize)
file_info.size > kMaxLibraryFileSize) {
base::ClosePlatformFile(file);
return result; return result;
}
result.resize(file_info.size); result.resize(file_info.size);
int bytes_read = int bytes_read = file.Read(0, string_as_array(&result), file_info.size);
base::ReadPlatformFile(file, 0, string_as_array(&result), file_info.size);
if (bytes_read != file_info.size) if (bytes_read != file_info.size)
result.clear(); result.clear();
base::ClosePlatformFile(file);
return result; return result;
} }
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include <string> #include <string>
#include "base/platform_file.h" #include "base/files/file.h"
class XmlReader; class XmlReader;
...@@ -32,7 +32,7 @@ bool ReadString(XmlReader* reader, std::string* result); ...@@ -32,7 +32,7 @@ bool ReadString(XmlReader* reader, std::string* result);
bool ReadInteger(XmlReader* reader, uint64* result); bool ReadInteger(XmlReader* reader, uint64* result);
// Read in the contents of the given library xml |file| and return as a string. // Read in the contents of the given library xml |file| and return as a string.
std::string ReadPlatformFileAsString(const base::PlatformFile file); std::string ReadFileAsString(base::File file);
} // namespace iapps } // namespace iapps
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment