summaryrefslogtreecommitdiff
path: root/chromium/ui/base/resource/data_pack.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/ui/base/resource/data_pack.cc')
-rw-r--r--chromium/ui/base/resource/data_pack.cc23
1 files changed, 20 insertions, 3 deletions
diff --git a/chromium/ui/base/resource/data_pack.cc b/chromium/ui/base/resource/data_pack.cc
index 618204dfcda..09513e6aed2 100644
--- a/chromium/ui/base/resource/data_pack.cc
+++ b/chromium/ui/base/resource/data_pack.cc
@@ -10,6 +10,7 @@
#include <utility>
#include "base/command_line.h"
+#include "base/files/file.h"
#include "base/files/file_util.h"
#include "base/files/memory_mapped_file.h"
#include "base/logging.h"
@@ -41,8 +42,11 @@ static const size_t kHeaderLengthV5 =
// We're crashing when trying to load a pak file on Windows. Add some error
// codes for logging.
// http://crbug.com/58056
+// These values are logged to UMA. Entries should not be renumbered and
+// numeric values should never be reused. Keep in sync with "DataPackLoadErrors"
+// in src/tools/metrics/histograms/enums.xml.
enum LoadErrors {
- INIT_FAILED = 1,
+ INIT_FAILED_OBSOLETE = 1,
BAD_VERSION,
INDEX_TRUNCATED,
ENTRY_NOT_FOUND,
@@ -50,6 +54,8 @@ enum LoadErrors {
WRONG_ENCODING,
INIT_FAILED_FROM_FILE,
UNZIP_FAILED,
+ OPEN_FAILED,
+ MAP_FAILED,
LOAD_ERRORS_COUNT,
};
@@ -274,9 +280,20 @@ DataPack::~DataPack() {
bool DataPack::LoadFromPath(const base::FilePath& path) {
std::unique_ptr<base::MemoryMappedFile> mmap =
std::make_unique<base::MemoryMappedFile>();
- if (!mmap->Initialize(path)) {
+ // Open the file for reading; allowing other consumers to also open it for
+ // reading and deleting. Do not allow others to write to it.
+ base::File data_file(path, base::File::FLAG_OPEN | base::File::FLAG_READ |
+ base::File::FLAG_EXCLUSIVE_WRITE |
+ base::File::FLAG_SHARE_DELETE);
+ if (!data_file.IsValid()) {
+ DLOG(ERROR) << "Failed to open datapack with base::File::Error "
+ << data_file.error_details();
+ LogDataPackError(OPEN_FAILED);
+ return false;
+ }
+ if (!mmap->Initialize(std::move(data_file))) {
DLOG(ERROR) << "Failed to mmap datapack";
- LogDataPackError(INIT_FAILED);
+ LogDataPackError(MAP_FAILED);
return false;
}
if (MmapHasGzipHeader(mmap.get())) {