| OLD | NEW |
| 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 Loading... |
| 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 const base::File::Region whole_file(file); |
| 89 return LoadFromFileRegion(file.Pass(), whole_file); |
| 90 } |
| 91 |
| 92 bool DataPack::LoadFromFileRegion(base::File file, |
| 93 const base::File::Region& region) { |
| 88 mmap_.reset(new base::MemoryMappedFile); | 94 mmap_.reset(new base::MemoryMappedFile); |
| 89 if (!mmap_->Initialize(file.Pass())) { | 95 if (!mmap_->Initialize(file.Pass(), region)) { |
| 90 DLOG(ERROR) << "Failed to mmap datapack"; | 96 DLOG(ERROR) << "Failed to mmap datapack"; |
| 91 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED_FROM_FILE, | 97 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED_FROM_FILE, |
| 92 LOAD_ERRORS_COUNT); | 98 LOAD_ERRORS_COUNT); |
| 93 mmap_.reset(); | 99 mmap_.reset(); |
| 94 return false; | 100 return false; |
| 95 } | 101 } |
| 96 return LoadImpl(); | 102 return LoadImpl(); |
| 97 } | 103 } |
| 98 | 104 |
| 99 bool DataPack::LoadImpl() { | 105 bool DataPack::LoadImpl() { |
| (...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 return false; | 315 return false; |
| 310 } | 316 } |
| 311 } | 317 } |
| 312 | 318 |
| 313 base::CloseFile(file); | 319 base::CloseFile(file); |
| 314 | 320 |
| 315 return true; | 321 return true; |
| 316 } | 322 } |
| 317 | 323 |
| 318 } // namespace ui | 324 } // namespace ui |
| OLD | NEW |