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, |
(...skipping 23 matching lines...) Expand all Loading... |
34 MinidumpSimpleStringDictionaryEntryWriter::MinidumpSimpleStringDictionaryEntry() | 34 MinidumpSimpleStringDictionaryEntryWriter::MinidumpSimpleStringDictionaryEntry() |
35 const { | 35 const { |
36 DCHECK_EQ(state(), kStateWritable); | 36 DCHECK_EQ(state(), kStateWritable); |
37 | 37 |
38 return &entry_; | 38 return &entry_; |
39 } | 39 } |
40 | 40 |
41 void MinidumpSimpleStringDictionaryEntryWriter::SetKeyValue( | 41 void MinidumpSimpleStringDictionaryEntryWriter::SetKeyValue( |
42 const std::string& key, | 42 const std::string& key, |
43 const std::string& value) { | 43 const std::string& value) { |
| 44 DCHECK_EQ(state(), kStateMutable); |
| 45 |
44 key_.SetUTF8(key); | 46 key_.SetUTF8(key); |
45 value_.SetUTF8(value); | 47 value_.SetUTF8(value); |
46 } | 48 } |
47 | 49 |
48 bool MinidumpSimpleStringDictionaryEntryWriter::Freeze() { | 50 bool MinidumpSimpleStringDictionaryEntryWriter::Freeze() { |
49 DCHECK_EQ(state(), kStateMutable); | 51 DCHECK_EQ(state(), kStateMutable); |
50 | 52 |
51 if (!MinidumpWritable::Freeze()) { | 53 if (!MinidumpWritable::Freeze()) { |
52 return false; | 54 return false; |
53 } | 55 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 } | 91 } |
90 | 92 |
91 MinidumpSimpleStringDictionaryWriter::MinidumpSimpleStringDictionaryWriter() | 93 MinidumpSimpleStringDictionaryWriter::MinidumpSimpleStringDictionaryWriter() |
92 : MinidumpWritable(), simple_string_dictionary_base_(), entries_() { | 94 : MinidumpWritable(), simple_string_dictionary_base_(), entries_() { |
93 } | 95 } |
94 | 96 |
95 MinidumpSimpleStringDictionaryWriter::~MinidumpSimpleStringDictionaryWriter() { | 97 MinidumpSimpleStringDictionaryWriter::~MinidumpSimpleStringDictionaryWriter() { |
96 STLDeleteContainerPairSecondPointers(entries_.begin(), entries_.end()); | 98 STLDeleteContainerPairSecondPointers(entries_.begin(), entries_.end()); |
97 } | 99 } |
98 | 100 |
| 101 void MinidumpSimpleStringDictionaryWriter::InitializeFromMap( |
| 102 const std::map<std::string, std::string>& map) { |
| 103 DCHECK_EQ(state(), kStateMutable); |
| 104 DCHECK(entries_.empty()); |
| 105 |
| 106 for (const auto& iterator : map) { |
| 107 auto entry = |
| 108 make_scoped_ptr(new MinidumpSimpleStringDictionaryEntryWriter()); |
| 109 entry->SetKeyValue(iterator.first, iterator.second); |
| 110 AddEntry(entry.Pass()); |
| 111 } |
| 112 } |
| 113 |
99 void MinidumpSimpleStringDictionaryWriter::AddEntry( | 114 void MinidumpSimpleStringDictionaryWriter::AddEntry( |
100 scoped_ptr<MinidumpSimpleStringDictionaryEntryWriter> entry) { | 115 scoped_ptr<MinidumpSimpleStringDictionaryEntryWriter> entry) { |
101 DCHECK_GE(state(), kStateMutable); | 116 DCHECK_EQ(state(), kStateMutable); |
102 | 117 |
103 const std::string& key = entry->Key(); | 118 const std::string& key = entry->Key(); |
104 auto iterator = entries_.find(key); | 119 auto iterator = entries_.find(key); |
105 if (iterator != entries_.end()) { | 120 if (iterator != entries_.end()) { |
106 delete iterator->second; | 121 delete iterator->second; |
107 iterator->second = entry.release(); | 122 iterator->second = entry.release(); |
108 } else { | 123 } else { |
109 entries_[key] = entry.release(); | 124 entries_[key] = entry.release(); |
110 } | 125 } |
111 } | 126 } |
112 | 127 |
| 128 bool MinidumpSimpleStringDictionaryWriter::IsUseful() const { |
| 129 return !entries_.empty(); |
| 130 } |
| 131 |
113 bool MinidumpSimpleStringDictionaryWriter::Freeze() { | 132 bool MinidumpSimpleStringDictionaryWriter::Freeze() { |
114 DCHECK_EQ(state(), kStateMutable); | 133 DCHECK_EQ(state(), kStateMutable); |
115 | 134 |
116 if (!MinidumpWritable::Freeze()) { | 135 if (!MinidumpWritable::Freeze()) { |
117 return false; | 136 return false; |
118 } | 137 } |
119 | 138 |
120 size_t entry_count = entries_.size(); | 139 size_t entry_count = entries_.size(); |
121 if (!AssignIfInRange(&simple_string_dictionary_base_.count, entry_count)) { | 140 if (!AssignIfInRange(&simple_string_dictionary_base_.count, entry_count)) { |
122 LOG(ERROR) << "entry_count " << entry_count << " out of range"; | 141 LOG(ERROR) << "entry_count " << entry_count << " out of range"; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 for (const auto& key_entry : entries_) { | 176 for (const auto& key_entry : entries_) { |
158 iov.iov_base = key_entry.second->MinidumpSimpleStringDictionaryEntry(); | 177 iov.iov_base = key_entry.second->MinidumpSimpleStringDictionaryEntry(); |
159 iov.iov_len = sizeof(MinidumpSimpleStringDictionaryEntry); | 178 iov.iov_len = sizeof(MinidumpSimpleStringDictionaryEntry); |
160 iovecs.push_back(iov); | 179 iovecs.push_back(iov); |
161 } | 180 } |
162 | 181 |
163 return file_writer->WriteIoVec(&iovecs); | 182 return file_writer->WriteIoVec(&iovecs); |
164 } | 183 } |
165 | 184 |
166 } // namespace crashpad | 185 } // namespace crashpad |
OLD | NEW |