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

Side by Side Diff: ui/base/resource/data_pack.cc

Issue 394313002: Add support for loading pak files from arbitrary file regions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ah, remove <algorithm> Created 6 years, 5 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ui/base/resource/data_pack.h" 5 #include "ui/base/resource/data_pack.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/memory_mapped_file.h" 10 #include "base/files/memory_mapped_file.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 DLOG(ERROR) << "Failed to mmap datapack"; 78 DLOG(ERROR) << "Failed to mmap datapack";
79 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED, 79 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED,
80 LOAD_ERRORS_COUNT); 80 LOAD_ERRORS_COUNT);
81 mmap_.reset(); 81 mmap_.reset();
82 return false; 82 return false;
83 } 83 }
84 return LoadImpl(); 84 return LoadImpl();
85 } 85 }
86 86
87 bool DataPack::LoadFromFile(base::File file) { 87 bool DataPack::LoadFromFile(base::File file) {
88 return LoadFromFileRegion(file.Pass(), base::File::Region::kWholeFile);
89 }
90
91 bool DataPack::LoadFromFileRegion(base::File file,
92 const base::File::Region& region) {
88 mmap_.reset(new base::MemoryMappedFile); 93 mmap_.reset(new base::MemoryMappedFile);
89 if (!mmap_->Initialize(file.Pass())) { 94 if (!mmap_->Initialize(file.Pass(), region)) {
90 DLOG(ERROR) << "Failed to mmap datapack"; 95 DLOG(ERROR) << "Failed to mmap datapack";
91 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED_FROM_FILE, 96 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED_FROM_FILE,
92 LOAD_ERRORS_COUNT); 97 LOAD_ERRORS_COUNT);
93 mmap_.reset(); 98 mmap_.reset();
94 return false; 99 return false;
95 } 100 }
96 return LoadImpl(); 101 return LoadImpl();
97 } 102 }
98 103
99 bool DataPack::LoadImpl() { 104 bool DataPack::LoadImpl() {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 return false; 314 return false;
310 } 315 }
311 } 316 }
312 317
313 base::CloseFile(file); 318 base::CloseFile(file);
314 319
315 return true; 320 return true;
316 } 321 }
317 322
318 } // namespace ui 323 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698