| 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 hashes to |Misspelling| objects. |    6 // |misspellings_|. This is a map from uint32 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  |   21  | 
 |   22 #include "base/stl_util.h" | 
 |   23  | 
|   22 namespace spellcheck { |   24 namespace spellcheck { | 
|   23  |   25  | 
|   24 Feedback::Feedback() { |   26 Feedback::Feedback() { | 
|   25 } |   27 } | 
|   26  |   28  | 
|   27 Feedback::~Feedback() { |   29 Feedback::~Feedback() { | 
|   28 } |   30 } | 
|   29  |   31  | 
|   30 Misspelling* Feedback::GetMisspelling(uint32 hash) { |   32 Misspelling* Feedback::GetMisspelling(uint32 hash) { | 
|   31   HashMisspellingMap::iterator misspelling_it = misspellings_.find(hash); |   33   HashMisspellingMap::iterator misspelling_it = misspellings_.find(hash); | 
|   32   if (misspelling_it == misspellings_.end()) |   34   if (misspelling_it == misspellings_.end()) | 
|   33     return NULL; |   35     return NULL; | 
|   34   return &misspelling_it->second; |   36   return &misspelling_it->second; | 
|   35 } |   37 } | 
|   36  |   38  | 
|   37 void Feedback::FinalizeRemovedMisspellings( |   39 void Feedback::FinalizeRemovedMisspellings( | 
|   38     int renderer_process_id, |   40     int renderer_process_id, | 
|   39     const std::vector<uint32>& remaining_markers) { |   41     const std::vector<uint32>& remaining_markers) { | 
|   40   RendererHashesMap::iterator renderer_it = |   42   RendererHashesMap::iterator renderer_it = | 
|   41       renderers_.find(renderer_process_id); |   43       renderers_.find(renderer_process_id); | 
|   42   if (renderer_it == renderers_.end() || renderer_it->second.empty()) |   44   if (renderer_it == renderers_.end() || renderer_it->second.empty()) | 
|   43     return; |   45     return; | 
|   44   HashCollection& renderer_hashes = renderer_it->second; |   46   HashCollection& renderer_hashes = renderer_it->second; | 
|   45   HashCollection remaining_hashes(remaining_markers.begin(), |   47   HashCollection remaining_hashes(remaining_markers.begin(), | 
|   46                                   remaining_markers.end()); |   48                                   remaining_markers.end()); | 
|   47   std::vector<uint32> removed_hashes; |   49   std::vector<uint32> removed_hashes = | 
|   48   std::set_difference(renderer_hashes.begin(), |   50       base::STLSetDifference<std::vector<uint32> >(renderer_hashes, | 
|   49                       renderer_hashes.end(), |   51                                                    remaining_hashes); | 
|   50                       remaining_hashes.begin(), |  | 
|   51                       remaining_hashes.end(), |  | 
|   52                       std::back_inserter(removed_hashes)); |  | 
|   53   for (std::vector<uint32>::const_iterator hash_it = removed_hashes.begin(); |   52   for (std::vector<uint32>::const_iterator hash_it = removed_hashes.begin(); | 
|   54        hash_it != removed_hashes.end(); |   53        hash_it != removed_hashes.end(); | 
|   55        ++hash_it) { |   54        ++hash_it) { | 
|   56     HashMisspellingMap::iterator misspelling_it = misspellings_.find(*hash_it); |   55     HashMisspellingMap::iterator misspelling_it = misspellings_.find(*hash_it); | 
|   57     if (misspelling_it != misspellings_.end() && |   56     if (misspelling_it != misspellings_.end() && | 
|   58         !misspelling_it->second.action.IsFinal()) { |   57         !misspelling_it->second.action.IsFinal()) { | 
|   59       misspelling_it->second.action.Finalize(); |   58       misspelling_it->second.action.Finalize(); | 
|   60     } |   59     } | 
|   61   } |   60   } | 
|   62 } |   61 } | 
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  177   renderers_.clear(); |  176   renderers_.clear(); | 
|  178 } |  177 } | 
|  179  |  178  | 
|  180 const std::set<uint32>& Feedback::FindMisspellings( |  179 const std::set<uint32>& Feedback::FindMisspellings( | 
|  181     const string16& misspelled_text) const { |  180     const string16& misspelled_text) const { | 
|  182   const TextHashesMap::const_iterator text_it = text_.find(misspelled_text); |  181   const TextHashesMap::const_iterator text_it = text_.find(misspelled_text); | 
|  183   return text_it == text_.end() ? empty_hash_collection_ : text_it->second; |  182   return text_it == text_.end() ? empty_hash_collection_ : text_it->second; | 
|  184 } |  183 } | 
|  185  |  184  | 
|  186 }  // namespace spellcheck |  185 }  // namespace spellcheck | 
| OLD | NEW |