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 #include <utility> |
8 | 9 |
9 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
10 #include "base/files/memory_mapped_file.h" | 11 #include "base/files/memory_mapped_file.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/memory/ref_counted_memory.h" | 13 #include "base/memory/ref_counted_memory.h" |
13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
14 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
15 | 16 |
16 // For details of the file layout, see | 17 // For details of the file layout, see |
17 // http://dev.chromium.org/developers/design-documents/linuxresourcesandlocalize
dstrings | 18 // http://dev.chromium.org/developers/design-documents/linuxresourcesandlocalize
dstrings |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 DLOG(ERROR) << "Failed to mmap datapack"; | 80 DLOG(ERROR) << "Failed to mmap datapack"; |
80 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED, | 81 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED, |
81 LOAD_ERRORS_COUNT); | 82 LOAD_ERRORS_COUNT); |
82 mmap_.reset(); | 83 mmap_.reset(); |
83 return false; | 84 return false; |
84 } | 85 } |
85 return LoadImpl(); | 86 return LoadImpl(); |
86 } | 87 } |
87 | 88 |
88 bool DataPack::LoadFromFile(base::File file) { | 89 bool DataPack::LoadFromFile(base::File file) { |
89 return LoadFromFileRegion(file.Pass(), | 90 return LoadFromFileRegion(std::move(file), |
90 base::MemoryMappedFile::Region::kWholeFile); | 91 base::MemoryMappedFile::Region::kWholeFile); |
91 } | 92 } |
92 | 93 |
93 bool DataPack::LoadFromFileRegion( | 94 bool DataPack::LoadFromFileRegion( |
94 base::File file, | 95 base::File file, |
95 const base::MemoryMappedFile::Region& region) { | 96 const base::MemoryMappedFile::Region& region) { |
96 mmap_.reset(new base::MemoryMappedFile); | 97 mmap_.reset(new base::MemoryMappedFile); |
97 if (!mmap_->Initialize(file.Pass(), region)) { | 98 if (!mmap_->Initialize(std::move(file), region)) { |
98 DLOG(ERROR) << "Failed to mmap datapack"; | 99 DLOG(ERROR) << "Failed to mmap datapack"; |
99 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED_FROM_FILE, | 100 UMA_HISTOGRAM_ENUMERATION("DataPack.Load", INIT_FAILED_FROM_FILE, |
100 LOAD_ERRORS_COUNT); | 101 LOAD_ERRORS_COUNT); |
101 mmap_.reset(); | 102 mmap_.reset(); |
102 return false; | 103 return false; |
103 } | 104 } |
104 return LoadImpl(); | 105 return LoadImpl(); |
105 } | 106 } |
106 | 107 |
107 bool DataPack::LoadImpl() { | 108 bool DataPack::LoadImpl() { |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 return false; | 345 return false; |
345 } | 346 } |
346 } | 347 } |
347 | 348 |
348 base::CloseFile(file); | 349 base::CloseFile(file); |
349 | 350 |
350 return true; | 351 return true; |
351 } | 352 } |
352 | 353 |
353 } // namespace ui | 354 } // namespace ui |
OLD | NEW |