summaryrefslogtreecommitdiffstats
path: root/ui/base
diff options
context:
space:
mode:
authorrvargas@chromium.org <rvargas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-03 22:14:15 +0000
committerrvargas@chromium.org <rvargas@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-03 22:14:15 +0000
commit58ba3eab5af91f112de6a26856f07cdd46cde35e (patch)
treeb9fa5046900e2003926caee62454dc572ea9508d /ui/base
parent4b50cf797e2a1b5026da2b03a6f3c6e6f8065d5d (diff)
downloadchromium_src-58ba3eab5af91f112de6a26856f07cdd46cde35e.zip
chromium_src-58ba3eab5af91f112de6a26856f07cdd46cde35e.tar.gz
chromium_src-58ba3eab5af91f112de6a26856f07cdd46cde35e.tar.bz2
Convert base::MemoryMappedFile to use File instead of PlatformFile.
This also modifies consumers of MemoryMappedFile and fixes double handle close on MediaFileChecker, media_file_checker_unittest and data_pack_unittests. BUG=322664 TEST=unit tests R=cpu@chromium.org, dalecurtis@chromium.org (media) TBR (owners): tony@chromium.org (resource) jochen@chromium.org (chrome-content) thakis@chromium.org (base) Review URL: https://codereview.chromium.org/109273002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242937 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/base')
-rw-r--r--ui/base/resource/data_pack.cc4
-rw-r--r--ui/base/resource/data_pack.h4
-rw-r--r--ui/base/resource/data_pack_unittest.cc12
-rw-r--r--ui/base/resource/resource_bundle.cc8
-rw-r--r--ui/base/resource/resource_bundle.h8
5 files changed, 16 insertions, 20 deletions
diff --git a/ui/base/resource/data_pack.cc b/ui/base/resource/data_pack.cc
index 8f8f182..56d74a27 100644
--- a/ui/base/resource/data_pack.cc
+++ b/ui/base/resource/data_pack.cc
@@ -84,9 +84,9 @@ bool DataPack::LoadFromPath(const base::FilePath& path) {
return LoadImpl();
}
-bool DataPack::LoadFromFile(base::PlatformFile file) {
+bool DataPack::LoadFromFile(base::File file) {
mmap_.reset(new base::MemoryMappedFile);
- if (!mmap_->Initialize(file)) {
+ if (!mmap_->Initialize(file.Pass())) {
DLOG(ERROR) << "Failed to mmap datapack";
UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED_FROM_FILE,
LOAD_ERRORS_COUNT);
diff --git a/ui/base/resource/data_pack.h b/ui/base/resource/data_pack.h
index 2ea938f..a1a92c5 100644
--- a/ui/base/resource/data_pack.h
+++ b/ui/base/resource/data_pack.h
@@ -12,8 +12,8 @@
#include <map>
#include "base/basictypes.h"
+#include "base/files/file.h"
#include "base/memory/scoped_ptr.h"
-#include "base/platform_file.h"
#include "base/strings/string_piece.h"
#include "ui/base/layout.h"
#include "ui/base/resource/resource_handle.h"
@@ -36,7 +36,7 @@ class UI_EXPORT DataPack : public ResourceHandle {
bool LoadFromPath(const base::FilePath& path);
// Loads a pack file from |file|, returning false on error.
- bool LoadFromFile(base::PlatformFile file);
+ bool LoadFromFile(base::File file);
// Writes a pack file containing |resources| to |path|. If there are any
// text resources to be written, their encoding must already agree to the
diff --git a/ui/base/resource/data_pack_unittest.cc b/ui/base/resource/data_pack_unittest.cc
index 0ac7819d..e3cd2fb 100644
--- a/ui/base/resource/data_pack_unittest.cc
+++ b/ui/base/resource/data_pack_unittest.cc
@@ -3,6 +3,7 @@
// found in the LICENSE file.
#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/path_service.h"
@@ -62,15 +63,12 @@ TEST(DataPackTest, LoadFromFile) {
ASSERT_EQ(file_util::WriteFile(data_path, kSamplePakContents, kSamplePakSize),
static_cast<int>(kSamplePakSize));
- bool created = false;
- base::PlatformFileError error_code = base::PLATFORM_FILE_OK;
- base::PlatformFile file = base::CreatePlatformFile(
- data_path, base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ,
- &created, &error_code);
+ base::File file(data_path, base::File::FLAG_OPEN | base::File::FLAG_READ);
+ ASSERT_TRUE(file.IsValid());
// Load the file through the data pack API.
DataPack pack(SCALE_FACTOR_100P);
- ASSERT_TRUE(pack.LoadFromFile(file));
+ ASSERT_TRUE(pack.LoadFromFile(file.Pass()));
base::StringPiece data;
ASSERT_TRUE(pack.HasResource(4));
@@ -89,8 +87,6 @@ TEST(DataPackTest, LoadFromFile) {
// Try looking up an invalid key.
ASSERT_FALSE(pack.HasResource(140));
ASSERT_FALSE(pack.GetStringPiece(140, &data));
-
- base::ClosePlatformFile(file);
}
INSTANTIATE_TEST_CASE_P(WriteBINARY, DataPackTest, ::testing::Values(
diff --git a/ui/base/resource/resource_bundle.cc b/ui/base/resource/resource_bundle.cc
index 22f191c..4371e4f 100644
--- a/ui/base/resource/resource_bundle.cc
+++ b/ui/base/resource/resource_bundle.cc
@@ -162,14 +162,14 @@ std::string ResourceBundle::InitSharedInstanceLocaleOnly(
// static
void ResourceBundle::InitSharedInstanceWithPakFile(
- base::PlatformFile pak_file, bool should_load_common_resources) {
+ base::File pak_file, bool should_load_common_resources) {
InitSharedInstance(NULL);
if (should_load_common_resources)
g_shared_instance_->LoadCommonResources();
scoped_ptr<DataPack> data_pack(
new DataPack(SCALE_FACTOR_100P));
- if (!data_pack->LoadFromFile(pak_file)) {
+ if (!data_pack->LoadFromFile(pak_file.Pass())) {
NOTREACHED() << "failed to load pak file";
return;
}
@@ -219,11 +219,11 @@ void ResourceBundle::AddOptionalDataPackFromPath(const base::FilePath& path,
AddDataPackFromPathInternal(path, scale_factor, true);
}
-void ResourceBundle::AddDataPackFromFile(base::PlatformFile file,
+void ResourceBundle::AddDataPackFromFile(base::File file,
ScaleFactor scale_factor) {
scoped_ptr<DataPack> data_pack(
new DataPack(scale_factor));
- if (data_pack->LoadFromFile(file)) {
+ if (data_pack->LoadFromFile(file.Pass())) {
AddDataPack(data_pack.release());
} else {
LOG(ERROR) << "Failed to load data pack from file."
diff --git a/ui/base/resource/resource_bundle.h b/ui/base/resource/resource_bundle.h
index 272c5b3..9df8705 100644
--- a/ui/base/resource/resource_bundle.h
+++ b/ui/base/resource/resource_bundle.h
@@ -11,11 +11,11 @@
#include <string>
#include "base/basictypes.h"
+#include "base/files/file.h"
#include "base/files/file_path.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/scoped_vector.h"
-#include "base/platform_file.h"
#include "base/strings/string16.h"
#include "base/strings/string_piece.h"
#include "ui/base/layout.h"
@@ -135,8 +135,8 @@ class UI_EXPORT ResourceBundle {
// controls whether or not ResourceBundle::LoadCommonResources is called.
// This allows the use of this function in a sandbox without local file
// access (as on Android).
- static void InitSharedInstanceWithPakFile(
- base::PlatformFile file, bool should_load_common_resources);
+ static void InitSharedInstanceWithPakFile(base::File file,
+ bool should_load_common_resources);
// Initialize the ResourceBundle using given data pack path for testing.
static void InitSharedInstanceWithPakPath(const base::FilePath& path);
@@ -164,7 +164,7 @@ class UI_EXPORT ResourceBundle {
ScaleFactor scale_factor);
// Same as above but using an already open file.
- void AddDataPackFromFile(base::PlatformFile file, ScaleFactor scale_factor);
+ void AddDataPackFromFile(base::File file, ScaleFactor scale_factor);
// Same as AddDataPackFromPath but does not log an error if the pack fails to
// load.