OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 // The |Feedback| object keeps track of each instance of user feedback in a map | 5 // The |Feedback| object keeps track of each instance of user feedback in a map |
6 // |misspellings_|. This is a map from uint32_t hashes to |Misspelling| objects. | 6 // |misspellings_|. This is a map from uint32_t hashes to |Misspelling| objects. |
7 // | 7 // |
8 // Each misspelling should be present in only one renderer process. The | 8 // Each misspelling should be present in only one renderer process. The |
9 // |Feedback| objects keeps track of misspelling-renderer relationship in the | 9 // |Feedback| objects keeps track of misspelling-renderer relationship in the |
10 // |renderers_| map of renderer process identifiers to a set of hashes. | 10 // |renderers_| map of renderer process identifiers to a set of hashes. |
(...skipping 17 matching lines...) Expand all Loading... |
28 Feedback::Feedback(size_t max_total_text_size) | 28 Feedback::Feedback(size_t max_total_text_size) |
29 : max_total_text_size_(max_total_text_size), total_text_size_(0) { | 29 : max_total_text_size_(max_total_text_size), total_text_size_(0) { |
30 DCHECK_GE(max_total_text_size, 1024U); | 30 DCHECK_GE(max_total_text_size, 1024U); |
31 } | 31 } |
32 | 32 |
33 Feedback::~Feedback() {} | 33 Feedback::~Feedback() {} |
34 | 34 |
35 Misspelling* Feedback::GetMisspelling(uint32_t hash) { | 35 Misspelling* Feedback::GetMisspelling(uint32_t hash) { |
36 HashMisspellingMap::iterator misspelling_it = misspellings_.find(hash); | 36 HashMisspellingMap::iterator misspelling_it = misspellings_.find(hash); |
37 if (misspelling_it == misspellings_.end()) | 37 if (misspelling_it == misspellings_.end()) |
38 return NULL; | 38 return nullptr; |
39 return &misspelling_it->second; | 39 return &misspelling_it->second; |
40 } | 40 } |
41 | 41 |
42 void Feedback::FinalizeRemovedMisspellings( | 42 void Feedback::FinalizeRemovedMisspellings( |
43 int renderer_process_id, | 43 int renderer_process_id, |
44 const std::vector<uint32_t>& remaining_markers) { | 44 const std::vector<uint32_t>& remaining_markers) { |
45 RendererHashesMap::iterator renderer_it = | 45 RendererHashesMap::iterator renderer_it = |
46 renderers_.find(renderer_process_id); | 46 renderers_.find(renderer_process_id); |
47 if (renderer_it == renderers_.end() || renderer_it->second.empty()) | 47 if (renderer_it == renderers_.end() || renderer_it->second.empty()) |
48 return; | 48 return; |
49 HashCollection& renderer_hashes = renderer_it->second; | 49 HashCollection& renderer_hashes = renderer_it->second; |
50 HashCollection remaining_hashes(remaining_markers.begin(), | 50 HashCollection remaining_hashes(remaining_markers.begin(), |
51 remaining_markers.end()); | 51 remaining_markers.end()); |
52 std::vector<uint32_t> removed_hashes = | 52 std::vector<HashCollection::value_type> removed_hashes = |
53 base::STLSetDifference<std::vector<uint32_t>>(renderer_hashes, | 53 base::STLSetDifference<std::vector<HashCollection::value_type>>( |
54 remaining_hashes); | 54 renderer_hashes, remaining_hashes); |
55 for (std::vector<uint32_t>::const_iterator hash_it = removed_hashes.begin(); | 55 for (auto hash : removed_hashes) { |
56 hash_it != removed_hashes.end(); ++hash_it) { | 56 HashMisspellingMap::iterator misspelling_it = misspellings_.find(hash); |
57 HashMisspellingMap::iterator misspelling_it = misspellings_.find(*hash_it); | |
58 if (misspelling_it != misspellings_.end() && | 57 if (misspelling_it != misspellings_.end() && |
59 !misspelling_it->second.action.IsFinal()) { | 58 !misspelling_it->second.action.IsFinal()) { |
60 misspelling_it->second.action.Finalize(); | 59 misspelling_it->second.action.Finalize(); |
61 } | 60 } |
62 } | 61 } |
63 } | 62 } |
64 | 63 |
65 bool Feedback::RendererHasMisspellings(int renderer_process_id) const { | 64 bool Feedback::RendererHasMisspellings(int renderer_process_id) const { |
66 RendererHashesMap::const_iterator renderer_it = | 65 RendererHashesMap::const_iterator renderer_it = |
67 renderers_.find(renderer_process_id); | 66 renderers_.find(renderer_process_id); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 text_[GetMisspelledString(misspelling)].insert(misspelling.hash); | 149 text_[GetMisspelledString(misspelling)].insert(misspelling.hash); |
151 renderers_[renderer_process_id].insert(misspelling.hash); | 150 renderers_[renderer_process_id].insert(misspelling.hash); |
152 } | 151 } |
153 | 152 |
154 bool Feedback::Empty() const { | 153 bool Feedback::Empty() const { |
155 return misspellings_.empty(); | 154 return misspellings_.empty(); |
156 } | 155 } |
157 | 156 |
158 std::vector<int> Feedback::GetRendersWithMisspellings() const { | 157 std::vector<int> Feedback::GetRendersWithMisspellings() const { |
159 std::vector<int> renderers_with_misspellings; | 158 std::vector<int> renderers_with_misspellings; |
160 for (RendererHashesMap::const_iterator renderer_it = renderers_.begin(); | 159 for (const auto& renderer : renderers_) { |
161 renderer_it != renderers_.end(); ++renderer_it) { | 160 if (!renderer.second.empty()) |
162 if (!renderer_it->second.empty()) | 161 renderers_with_misspellings.push_back(renderer.first); |
163 renderers_with_misspellings.push_back(renderer_it->first); | |
164 } | 162 } |
165 return renderers_with_misspellings; | 163 return renderers_with_misspellings; |
166 } | 164 } |
167 | 165 |
168 void Feedback::FinalizeAllMisspellings() { | 166 void Feedback::FinalizeAllMisspellings() { |
169 for (HashMisspellingMap::iterator misspelling_it = misspellings_.begin(); | 167 for (auto& misspelling : misspellings_) { |
170 misspelling_it != misspellings_.end(); ++misspelling_it) { | 168 if (!misspelling.second.action.IsFinal()) |
171 if (!misspelling_it->second.action.IsFinal()) | 169 misspelling.second.action.Finalize(); |
172 misspelling_it->second.action.Finalize(); | |
173 } | 170 } |
174 } | 171 } |
175 | 172 |
176 std::vector<Misspelling> Feedback::GetAllMisspellings() const { | 173 std::vector<Misspelling> Feedback::GetAllMisspellings() const { |
177 std::vector<Misspelling> all_misspellings; | 174 std::vector<Misspelling> all_misspellings; |
178 for (HashMisspellingMap::const_iterator misspelling_it = | 175 for (const auto& misspelling : misspellings_) |
179 misspellings_.begin(); | 176 all_misspellings.push_back(misspelling.second); |
180 misspelling_it != misspellings_.end(); ++misspelling_it) { | |
181 all_misspellings.push_back(misspelling_it->second); | |
182 } | |
183 return all_misspellings; | 177 return all_misspellings; |
184 } | 178 } |
185 | 179 |
186 void Feedback::Clear() { | 180 void Feedback::Clear() { |
187 total_text_size_ = 0; | 181 total_text_size_ = 0; |
188 misspellings_.clear(); | 182 misspellings_.clear(); |
189 text_.clear(); | 183 text_.clear(); |
190 renderers_.clear(); | 184 renderers_.clear(); |
191 } | 185 } |
192 | 186 |
193 const std::set<uint32_t>& Feedback::FindMisspellings( | 187 const std::set<uint32_t>& Feedback::FindMisspellings( |
194 const base::string16& misspelled_text) const { | 188 const base::string16& misspelled_text) const { |
195 const TextHashesMap::const_iterator text_it = text_.find(misspelled_text); | 189 const TextHashesMap::const_iterator text_it = text_.find(misspelled_text); |
196 return text_it == text_.end() ? empty_hash_collection_ : text_it->second; | 190 return text_it == text_.end() ? empty_hash_collection_ : text_it->second; |
197 } | 191 } |
198 | 192 |
199 } // namespace spellcheck | 193 } // namespace spellcheck |
OLD | NEW |