summaryrefslogtreecommitdiffstats
path: root/chrome/installer
diff options
context:
space:
mode:
authorrvargas@chromium.org <rvargas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-25 15:26:35 +0000
committerrvargas@chromium.org <rvargas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-02-25 15:26:35 +0000
commitce3a8f4e678b19600a34471e5c18e6302b98babf (patch)
tree731517059fbf91e70b8c07bf3c87f95d724fdec3 /chrome/installer
parentba2c3bcda89858a32834feddd2ed0e631e12bf92 (diff)
downloadchromium_src-ce3a8f4e678b19600a34471e5c18e6302b98babf.zip
chromium_src-ce3a8f4e678b19600a34471e5c18e6302b98babf.tar.gz
chromium_src-ce3a8f4e678b19600a34471e5c18e6302b98babf.tar.bz2
Installer: remove uses of PlatformFile
BUG=322664 R=grt@chromium.org Review URL: https://codereview.chromium.org/173853004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253168 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/installer')
-rw-r--r--chrome/installer/test/alternate_version_generator.cc38
-rw-r--r--chrome/installer/util/install_util.cc35
-rw-r--r--chrome/installer/util/install_util.h8
-rw-r--r--chrome/installer/util/logging_installer.cc20
-rw-r--r--chrome/installer/util/logging_installer_unittest.cc20
5 files changed, 56 insertions, 65 deletions
diff --git a/chrome/installer/test/alternate_version_generator.cc b/chrome/installer/test/alternate_version_generator.cc
index 6b65aa1..aaeb3c2 100644
--- a/chrome/installer/test/alternate_version_generator.cc
+++ b/chrome/installer/test/alternate_version_generator.cc
@@ -34,11 +34,11 @@
#include "base/basictypes.h"
#include "base/command_line.h"
#include "base/file_util.h"
+#include "base/files/file.h"
#include "base/files/file_enumerator.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/path_service.h"
-#include "base/platform_file.h"
#include "base/process/launch.h"
#include "base/process/process_handle.h"
#include "base/strings/string_util.h"
@@ -151,11 +151,13 @@ class MappedFile {
public:
MappedFile() : size_(), mapping_(), view_() { }
~MappedFile();
- bool Initialize(base::PlatformFile file);
+ bool Initialize(base::File file);
void* data() const { return view_; }
size_t size() const { return size_; }
+
private:
size_t size_;
+ base::File file_;
HANDLE mapping_;
void* view_;
DISALLOW_COPY_AND_ASSIGN(MappedFile);
@@ -174,16 +176,16 @@ MappedFile::~MappedFile() {
}
}
-bool MappedFile::Initialize(base::PlatformFile file) {
+bool MappedFile::Initialize(base::File file) {
DCHECK(mapping_ == NULL);
bool result = false;
- base::PlatformFileInfo file_info;
+ base::File::Info file_info;
- if (base::GetPlatformFileInfo(file, &file_info)) {
+ if (file.GetInfo(&file_info)) {
if (file_info.size <=
static_cast<int64>(std::numeric_limits<DWORD>::max())) {
- mapping_ = CreateFileMapping(file, NULL, PAGE_READWRITE, 0,
- static_cast<DWORD>(file_info.size), NULL);
+ mapping_ = CreateFileMapping(file.GetPlatformFile(), NULL, PAGE_READWRITE,
+ 0, static_cast<DWORD>(file_info.size), NULL);
if (mapping_ != NULL) {
view_ = MapViewOfFile(mapping_, FILE_MAP_WRITE, 0, 0,
static_cast<size_t>(file_info.size));
@@ -202,6 +204,7 @@ bool MappedFile::Initialize(base::PlatformFile file) {
} else {
PLOG(DFATAL) << "GetPlatformFileInfo failed";
}
+ file_ = file.Pass();
return result;
}
@@ -352,29 +355,24 @@ bool UpdateVersionIfMatch(const base::FilePath& image_file,
}
bool result = false;
- base::win::ScopedHandle image_handle(base::CreatePlatformFile(
- image_file,
- (base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ |
- base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_READ |
- base::PLATFORM_FILE_EXCLUSIVE_WRITE), NULL, NULL));
+ uint32 flags = base::File::FLAG_OPEN | base::File::FLAG_READ |
+ base::File::FLAG_WRITE | base::File::FLAG_EXCLUSIVE_READ |
+ base::File::FLAG_EXCLUSIVE_WRITE;
+ base::File file(image_file, flags);
// It turns out that the underlying CreateFile can fail due to unhelpful
// security software locking the newly created DLL. So add a few brief
// retries to help tests that use this pass on machines thusly encumbered.
int retries = 3;
- while (!image_handle.IsValid() && retries-- > 0) {
+ while (!file.IsValid() && retries-- > 0) {
LOG(WARNING) << "Failed to open \"" << image_file.value() << "\"."
<< " Retrying " << retries << " more times.";
Sleep(1000);
- image_handle.Set(base::CreatePlatformFile(
- image_file,
- (base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ |
- base::PLATFORM_FILE_WRITE | base::PLATFORM_FILE_EXCLUSIVE_READ |
- base::PLATFORM_FILE_EXCLUSIVE_WRITE), NULL, NULL));
+ file.Initialize(image_file, flags);
}
- if (image_handle.IsValid()) {
+ if (file.IsValid()) {
MappedFile image_mapping;
- if (image_mapping.Initialize(image_handle)) {
+ if (image_mapping.Initialize(file.Pass())) {
base::win::PEImageAsData image(
reinterpret_cast<HMODULE>(image_mapping.data()));
// PEImage class does not support other-architecture images.
diff --git a/chrome/installer/util/install_util.cc b/chrome/installer/util/install_util.cc
index 3dacaa3..a5475c1 100644
--- a/chrome/installer/util/install_util.cc
+++ b/chrome/installer/util/install_util.cc
@@ -560,38 +560,35 @@ base::string16 InstallUtil::GetCurrentDate() {
}
// Open |path| with minimal access to obtain information about it, returning
-// true and populating |handle| on success.
+// true and populating |file| on success.
// static
bool InstallUtil::ProgramCompare::OpenForInfo(const base::FilePath& path,
- base::win::ScopedHandle* handle) {
- DCHECK(handle);
- handle->Set(base::CreatePlatformFile(path, base::PLATFORM_FILE_OPEN, NULL,
- NULL));
- return handle->IsValid();
+ base::File* file) {
+ DCHECK(file);
+ file->Initialize(path, base::File::FLAG_OPEN);
+ return file->IsValid();
}
-// Populate |info| for |handle|, returning true on success.
+// Populate |info| for |file|, returning true on success.
// static
-bool InstallUtil::ProgramCompare::GetInfo(const base::win::ScopedHandle& handle,
+bool InstallUtil::ProgramCompare::GetInfo(const base::File& file,
BY_HANDLE_FILE_INFORMATION* info) {
- DCHECK(handle.IsValid());
- return GetFileInformationByHandle(
- const_cast<base::win::ScopedHandle&>(handle), info) != 0;
+ DCHECK(file.IsValid());
+ return GetFileInformationByHandle(file.GetPlatformFile(), info) != 0;
}
InstallUtil::ProgramCompare::ProgramCompare(const base::FilePath& path_to_match)
: path_to_match_(path_to_match),
- file_handle_(base::kInvalidPlatformFileValue),
file_info_() {
DCHECK(!path_to_match_.empty());
- if (!OpenForInfo(path_to_match_, &file_handle_)) {
+ if (!OpenForInfo(path_to_match_, &file_)) {
PLOG(WARNING) << "Failed opening " << path_to_match_.value()
<< "; falling back to path string comparisons.";
- } else if (!GetInfo(file_handle_, &file_info_)) {
+ } else if (!GetInfo(file_, &file_info_)) {
PLOG(WARNING) << "Failed getting information for "
<< path_to_match_.value()
<< "; falling back to path string comparisons.";
- file_handle_.Close();
+ file_.Close();
}
}
@@ -621,15 +618,15 @@ bool InstallUtil::ProgramCompare::EvaluatePath(
// If the paths don't match and we couldn't open the expected file, we've done
// our best.
- if (!file_handle_.IsValid())
+ if (!file_.IsValid())
return false;
// Open the program and see if it references the expected file.
- base::win::ScopedHandle handle;
+ base::File file;
BY_HANDLE_FILE_INFORMATION info = {};
- return (OpenForInfo(path, &handle) &&
- GetInfo(handle, &info) &&
+ return (OpenForInfo(path, &file) &&
+ GetInfo(file, &info) &&
info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber &&
info.nFileIndexHigh == file_info_.nFileIndexHigh &&
info.nFileIndexLow == file_info_.nFileIndexLow);
diff --git a/chrome/installer/util/install_util.h b/chrome/installer/util/install_util.h
index eaa9e9e..ba6889b 100644
--- a/chrome/installer/util/install_util.h
+++ b/chrome/installer/util/install_util.h
@@ -14,6 +14,7 @@
#include "base/basictypes.h"
#include "base/command_line.h"
+#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/strings/string16.h"
#include "base/win/scoped_handle.h"
@@ -190,13 +191,12 @@ class InstallUtil {
bool EvaluatePath(const base::FilePath& path) const;
protected:
- static bool OpenForInfo(const base::FilePath& path,
- base::win::ScopedHandle* handle);
- static bool GetInfo(const base::win::ScopedHandle& handle,
+ static bool OpenForInfo(const base::FilePath& path, base::File* file);
+ static bool GetInfo(const base::File& file,
BY_HANDLE_FILE_INFORMATION* info);
base::FilePath path_to_match_;
- base::win::ScopedHandle file_handle_;
+ base::File file_;
BY_HANDLE_FILE_INFORMATION file_info_;
private:
diff --git a/chrome/installer/util/logging_installer.cc b/chrome/installer/util/logging_installer.cc
index 5839989..75f3bc9 100644
--- a/chrome/installer/util/logging_installer.cc
+++ b/chrome/installer/util/logging_installer.cc
@@ -8,11 +8,11 @@
#include "base/command_line.h"
#include "base/file_util.h"
+#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/logging_win.h"
#include "base/path_service.h"
-#include "base/platform_file.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/scoped_handle.h"
@@ -37,12 +37,11 @@ TruncateResult TruncateLogFileIfNeeded(const base::FilePath& log_file) {
if (base::GetFileSize(log_file, &log_size) &&
log_size > kMaxInstallerLogFileSize) {
// Cause the old log file to be deleted when we are done with it.
- const int file_flags = base::PLATFORM_FILE_OPEN |
- base::PLATFORM_FILE_READ |
- base::PLATFORM_FILE_SHARE_DELETE |
- base::PLATFORM_FILE_DELETE_ON_CLOSE;
- base::win::ScopedHandle old_log_file(
- base::CreatePlatformFile(log_file, file_flags, NULL, NULL));
+ uint32 file_flags = base::File::FLAG_OPEN |
+ base::File::FLAG_READ |
+ base::File::FLAG_SHARE_DELETE |
+ base::File::FLAG_DELETE_ON_CLOSE;
+ base::File old_log_file(log_file, file_flags);
if (old_log_file.IsValid()) {
result = LOGFILE_DELETED;
@@ -51,10 +50,9 @@ TruncateResult TruncateLogFileIfNeeded(const base::FilePath& log_file) {
if (base::Move(log_file, tmp_log)) {
int64 offset = log_size - kTruncatedInstallerLogFileSize;
std::string old_log_data(kTruncatedInstallerLogFileSize, 0);
- int bytes_read = base::ReadPlatformFile(old_log_file,
- offset,
- &old_log_data[0],
- kTruncatedInstallerLogFileSize);
+ int bytes_read = old_log_file.Read(offset,
+ &old_log_data[0],
+ kTruncatedInstallerLogFileSize);
if (bytes_read > 0 &&
(bytes_read == file_util::WriteFile(log_file,
&old_log_data[0],
diff --git a/chrome/installer/util/logging_installer_unittest.cc b/chrome/installer/util/logging_installer_unittest.cc
index 7bc1c45..ccd080b 100644
--- a/chrome/installer/util/logging_installer_unittest.cc
+++ b/chrome/installer/util/logging_installer_unittest.cc
@@ -5,9 +5,9 @@
#include <string>
#include "base/file_util.h"
+#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/files/scoped_temp_dir.h"
-#include "base/platform_file.h"
#include "base/win/scoped_handle.h"
#include "chrome/installer/util/logging_installer.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -74,11 +74,10 @@ TEST(LoggingInstallerTest, TestInUseNeedsTruncation) {
EXPECT_EQ(test_data.size(), file_size);
// Prevent the log file from being moved or deleted.
- const int file_flags = base::PLATFORM_FILE_OPEN |
- base::PLATFORM_FILE_READ |
- base::PLATFORM_FILE_EXCLUSIVE_READ;
- base::win::ScopedHandle temp_platform_file(
- base::CreatePlatformFile(temp_file, file_flags, NULL, NULL));
+ uint32 file_flags = base::File::FLAG_OPEN |
+ base::File::FLAG_READ |
+ base::File::FLAG_EXCLUSIVE_READ;
+ base::File temp_platform_file(temp_file, file_flags);
ASSERT_TRUE(temp_platform_file.IsValid());
EXPECT_EQ(installer::LOGFILE_UNTOUCHED,
@@ -104,13 +103,12 @@ TEST(LoggingInstallerTest, TestMoveFailsNeedsTruncation) {
// Create an inconvenient, non-deletable file in the location that
// TruncateLogFileIfNeeded would like to move the log file to.
- const int file_flags = base::PLATFORM_FILE_CREATE |
- base::PLATFORM_FILE_READ |
- base::PLATFORM_FILE_EXCLUSIVE_READ;
+ uint32 file_flags = base::File::FLAG_CREATE |
+ base::File::FLAG_READ |
+ base::File::FLAG_EXCLUSIVE_READ;
base::FilePath temp_file_move_dest(
temp_file.value() + FILE_PATH_LITERAL(".tmp"));
- base::win::ScopedHandle temp_move_destination_file(
- base::CreatePlatformFile(temp_file_move_dest, file_flags, NULL, NULL));
+ base::File temp_move_destination_file(temp_file_move_dest, file_flags);
ASSERT_TRUE(temp_move_destination_file.IsValid());
EXPECT_EQ(installer::LOGFILE_DELETED,