OLD | NEW |
1 // Copyright 2014 The Crashpad Authors. All rights reserved. | 1 // Copyright 2014 The Crashpad Authors. All rights reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS IS" BASIS, | 10 // distributed under the License is distributed on an "AS IS" BASIS, |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 // See the License for the specific language governing permissions and | 12 // See the License for the specific language governing permissions and |
13 // limitations under the License. | 13 // limitations under the License. |
14 | 14 |
15 #include "minidump/minidump_simple_string_dictionary_writer.h" | 15 #include "minidump/minidump_simple_string_dictionary_writer.h" |
16 | 16 |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
| 18 #include "base/stl_util.h" |
18 #include "util/file/file_writer.h" | 19 #include "util/file/file_writer.h" |
19 #include "util/numeric/safe_assignment.h" | 20 #include "util/numeric/safe_assignment.h" |
20 | 21 |
21 namespace crashpad { | 22 namespace crashpad { |
22 | 23 |
23 MinidumpSimpleStringDictionaryEntryWriter:: | 24 MinidumpSimpleStringDictionaryEntryWriter:: |
24 MinidumpSimpleStringDictionaryEntryWriter() | 25 MinidumpSimpleStringDictionaryEntryWriter() |
25 : MinidumpWritable(), entry_(), key_(), value_() { | 26 : MinidumpWritable(), entry_(), key_(), value_() { |
26 } | 27 } |
27 | 28 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 // MinidumpSimpleStringDictionary, and its children are responsible for | 86 // MinidumpSimpleStringDictionary, and its children are responsible for |
86 // writing themselves. | 87 // writing themselves. |
87 return true; | 88 return true; |
88 } | 89 } |
89 | 90 |
90 MinidumpSimpleStringDictionaryWriter::MinidumpSimpleStringDictionaryWriter() | 91 MinidumpSimpleStringDictionaryWriter::MinidumpSimpleStringDictionaryWriter() |
91 : MinidumpWritable(), simple_string_dictionary_base_(), entries_() { | 92 : MinidumpWritable(), simple_string_dictionary_base_(), entries_() { |
92 } | 93 } |
93 | 94 |
94 MinidumpSimpleStringDictionaryWriter::~MinidumpSimpleStringDictionaryWriter() { | 95 MinidumpSimpleStringDictionaryWriter::~MinidumpSimpleStringDictionaryWriter() { |
| 96 STLDeleteContainerPairSecondPointers(entries_.begin(), entries_.end()); |
95 } | 97 } |
96 | 98 |
97 void MinidumpSimpleStringDictionaryWriter::AddEntry( | 99 void MinidumpSimpleStringDictionaryWriter::AddEntry( |
98 MinidumpSimpleStringDictionaryEntryWriter* entry) { | 100 scoped_ptr<MinidumpSimpleStringDictionaryEntryWriter> entry) { |
99 DCHECK_GE(state(), kStateMutable); | 101 DCHECK_GE(state(), kStateMutable); |
100 | 102 |
101 entries_[entry->Key()] = entry; | 103 const std::string& key = entry->Key(); |
| 104 auto iterator = entries_.find(key); |
| 105 if (iterator != entries_.end()) { |
| 106 delete iterator->second; |
| 107 iterator->second = entry.release(); |
| 108 } else { |
| 109 entries_[key] = entry.release(); |
| 110 } |
102 } | 111 } |
103 | 112 |
104 bool MinidumpSimpleStringDictionaryWriter::Freeze() { | 113 bool MinidumpSimpleStringDictionaryWriter::Freeze() { |
105 DCHECK_EQ(state(), kStateMutable); | 114 DCHECK_EQ(state(), kStateMutable); |
106 | 115 |
107 if (!MinidumpWritable::Freeze()) { | 116 if (!MinidumpWritable::Freeze()) { |
108 return false; | 117 return false; |
109 } | 118 } |
110 | 119 |
111 size_t entry_count = entries_.size(); | 120 size_t entry_count = entries_.size(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 for (const auto& key_entry : entries_) { | 157 for (const auto& key_entry : entries_) { |
149 iov.iov_base = key_entry.second->MinidumpSimpleStringDictionaryEntry(); | 158 iov.iov_base = key_entry.second->MinidumpSimpleStringDictionaryEntry(); |
150 iov.iov_len = sizeof(MinidumpSimpleStringDictionaryEntry); | 159 iov.iov_len = sizeof(MinidumpSimpleStringDictionaryEntry); |
151 iovecs.push_back(iov); | 160 iovecs.push_back(iov); |
152 } | 161 } |
153 | 162 |
154 return file_writer->WriteIoVec(&iovecs); | 163 return file_writer->WriteIoVec(&iovecs); |
155 } | 164 } |
156 | 165 |
157 } // namespace crashpad | 166 } // namespace crashpad |
OLD | NEW |