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. |
11 // | 11 // |
12 // When the user adds a misspelling to their custom dictionary, all of the | 12 // When the user adds a misspelling to their custom dictionary, all of the |
13 // |Misspelling| objects with the same misspelled string are updated. The | 13 // |Misspelling| objects with the same misspelled string are updated. The |
14 // |Feedback| object facilitates efficient access to these misspellings through | 14 // |Feedback| object facilitates efficient access to these misspellings through |
15 // a |text_| map of misspelled strings to a set of hashes. | 15 // a |text_| map of misspelled strings to a set of hashes. |
16 | 16 |
17 #include "chrome/browser/spellchecker/feedback.h" | 17 #include "chrome/browser/spellchecker/feedback.h" |
18 | 18 |
19 #include <algorithm> | 19 #include <algorithm> |
20 #include <iterator> | 20 #include <iterator> |
21 #include <limits> | 21 #include <limits> |
22 | 22 |
23 #include "base/logging.h" | 23 #include "base/logging.h" |
24 #include "base/stl_util.h" | 24 #include "base/stl_util.h" |
please use gerrit instead
2016/02/03 23:59:10
No longer need this include.
Kevin Bailey
2016/02/04 16:34:10
Done.
| |
25 #include "chrome/browser/spellchecker/set_difference_container.h" | |
25 | 26 |
26 namespace spellcheck { | 27 namespace spellcheck { |
27 | 28 |
28 Feedback::Feedback(size_t max_total_text_size) | 29 Feedback::Feedback(size_t max_total_text_size) |
29 : max_total_text_size_(max_total_text_size), total_text_size_(0) { | 30 : max_total_text_size_(max_total_text_size), total_text_size_(0) { |
30 DCHECK_GE(max_total_text_size, 1024U); | 31 DCHECK_GE(max_total_text_size, 1024U); |
31 } | 32 } |
32 | 33 |
33 Feedback::~Feedback() {} | 34 Feedback::~Feedback() {} |
34 | 35 |
35 Misspelling* Feedback::GetMisspelling(uint32_t hash) { | 36 Misspelling* Feedback::GetMisspelling(uint32_t hash) { |
36 HashMisspellingMap::iterator misspelling_it = misspellings_.find(hash); | 37 HashMisspellingMap::iterator misspelling_it = misspellings_.find(hash); |
37 if (misspelling_it == misspellings_.end()) | 38 if (misspelling_it == misspellings_.end()) |
38 return NULL; | 39 return NULL; |
please use gerrit instead
2016/02/03 23:59:10
Let's switch to nullptr in all of the files that y
Kevin Bailey
2016/02/04 16:34:10
Done (I think).
| |
39 return &misspelling_it->second; | 40 return &misspelling_it->second; |
40 } | 41 } |
41 | 42 |
42 void Feedback::FinalizeRemovedMisspellings( | 43 void Feedback::FinalizeRemovedMisspellings( |
43 int renderer_process_id, | 44 int renderer_process_id, |
44 const std::vector<uint32_t>& remaining_markers) { | 45 const std::vector<uint32_t>& remaining_markers) { |
45 RendererHashesMap::iterator renderer_it = | 46 RendererHashesMap::iterator renderer_it = |
46 renderers_.find(renderer_process_id); | 47 renderers_.find(renderer_process_id); |
47 if (renderer_it == renderers_.end() || renderer_it->second.empty()) | 48 if (renderer_it == renderers_.end() || renderer_it->second.empty()) |
48 return; | 49 return; |
49 HashCollection& renderer_hashes = renderer_it->second; | 50 HashCollection& renderer_hashes = renderer_it->second; |
50 HashCollection remaining_hashes(remaining_markers.begin(), | 51 HashCollection remaining_hashes(remaining_markers.begin(), |
51 remaining_markers.end()); | 52 remaining_markers.end()); |
52 std::vector<uint32_t> removed_hashes = | 53 spellcheck::set_difference_container<HashCollection, HashCollection> |
53 base::STLSetDifference<std::vector<uint32_t>>(renderer_hashes, | 54 removed_hashes(renderer_hashes, remaining_hashes); |
54 remaining_hashes); | 55 for (auto hash : removed_hashes) { |
55 for (std::vector<uint32_t>::const_iterator hash_it = removed_hashes.begin(); | 56 HashMisspellingMap::iterator misspelling_it = misspellings_.find(hash); |
56 hash_it != removed_hashes.end(); ++hash_it) { | |
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 renderers_.clear(); | 189 renderers_.clear(); |
191 } | 190 } |
192 | 191 |
193 const std::set<uint32_t>& Feedback::FindMisspellings( | 192 const std::set<uint32_t>& Feedback::FindMisspellings( |
194 const base::string16& misspelled_text) const { | 193 const base::string16& misspelled_text) const { |
195 const TextHashesMap::const_iterator text_it = text_.find(misspelled_text); | 194 const TextHashesMap::const_iterator text_it = text_.find(misspelled_text); |
196 return text_it == text_.end() ? empty_hash_collection_ : text_it->second; | 195 return text_it == text_.end() ? empty_hash_collection_ : text_it->second; |
197 } | 196 } |
198 | 197 |
199 } // namespace spellcheck | 198 } // namespace spellcheck |
OLD | NEW |