| 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 // An object to store user feedback to spellcheck suggestions from spelling | 5 // An object to store user feedback to spellcheck suggestions from spelling |
| 6 // service. | 6 // service. |
| 7 // | 7 // |
| 8 // Stores feedback for the spelling service in |Misspelling| objects. Each | 8 // Stores feedback for the spelling service in |Misspelling| objects. Each |
| 9 // |Misspelling| object is identified by a |hash| and corresponds to a document | 9 // |Misspelling| object is identified by a |hash| and corresponds to a document |
| 10 // marker with the same |hash| identifier in the renderer. | 10 // marker with the same |hash| identifier in the renderer. |
| 11 | 11 |
| 12 #ifndef CHROME_BROWSER_SPELLCHECKER_FEEDBACK_H_ | 12 #ifndef CHROME_BROWSER_SPELLCHECKER_FEEDBACK_H_ |
| 13 #define CHROME_BROWSER_SPELLCHECKER_FEEDBACK_H_ | 13 #define CHROME_BROWSER_SPELLCHECKER_FEEDBACK_H_ |
| 14 | 14 |
| 15 #include <stddef.h> |
| 16 #include <stdint.h> |
| 17 |
| 15 #include <map> | 18 #include <map> |
| 16 #include <set> | 19 #include <set> |
| 17 #include <vector> | 20 #include <vector> |
| 18 | 21 |
| 22 #include "base/macros.h" |
| 19 #include "chrome/browser/spellchecker/misspelling.h" | 23 #include "chrome/browser/spellchecker/misspelling.h" |
| 20 | 24 |
| 21 namespace spellcheck { | 25 namespace spellcheck { |
| 22 | 26 |
| 23 // Stores user feedback to spellcheck suggestions. Sample usage: | 27 // Stores user feedback to spellcheck suggestions. Sample usage: |
| 24 // Feedback feedback; | 28 // Feedback feedback; |
| 25 // feedback.AddMisspelling(renderer_process_id, Misspelling( | 29 // feedback.AddMisspelling(renderer_process_id, Misspelling( |
| 26 // base::ASCIIToUTF16("Helllo world"), 0, 6, | 30 // base::ASCIIToUTF16("Helllo world"), 0, 6, |
| 27 // std::vector<base::string16>(), GenerateRandomHash())); | 31 // std::vector<base::string16>(), GenerateRandomHash())); |
| 28 // feedback.FinalizeRemovedMisspellings(renderer_process_id, | 32 // feedback.FinalizeRemovedMisspellings(renderer_process_id, |
| 29 // std::vector<uint32>()); | 33 // std::vector<uint32_t>()); |
| 30 // ProcessFeedback(feedback.GetMisspellingsInRenderer(renderer_process_id)); | 34 // ProcessFeedback(feedback.GetMisspellingsInRenderer(renderer_process_id)); |
| 31 // feedback.EraseFinalizedMisspellings(renderer_process_id); | 35 // feedback.EraseFinalizedMisspellings(renderer_process_id); |
| 32 class Feedback { | 36 class Feedback { |
| 33 public: | 37 public: |
| 34 explicit Feedback(size_t max_total_text_size); | 38 explicit Feedback(size_t max_total_text_size); |
| 35 ~Feedback(); | 39 ~Feedback(); |
| 36 | 40 |
| 37 // Returns the misspelling identified by |hash|. Returns NULL if there's no | 41 // Returns the misspelling identified by |hash|. Returns NULL if there's no |
| 38 // misspelling identified by |hash|. Retains the ownership of the result. The | 42 // misspelling identified by |hash|. Retains the ownership of the result. The |
| 39 // caller should not modify the hash in the returned misspelling. | 43 // caller should not modify the hash in the returned misspelling. |
| 40 Misspelling* GetMisspelling(uint32 hash); | 44 Misspelling* GetMisspelling(uint32_t hash); |
| 41 | 45 |
| 42 // Finalizes the user actions on misspellings that are removed from the | 46 // Finalizes the user actions on misspellings that are removed from the |
| 43 // renderer process with ID |renderer_process_id|. | 47 // renderer process with ID |renderer_process_id|. |
| 44 void FinalizeRemovedMisspellings( | 48 void FinalizeRemovedMisspellings( |
| 45 int renderer_process_id, | 49 int renderer_process_id, |
| 46 const std::vector<uint32>& remaining_markers); | 50 const std::vector<uint32_t>& remaining_markers); |
| 47 | 51 |
| 48 // Returns true if the renderer with process ID |renderer_process_id| has | 52 // Returns true if the renderer with process ID |renderer_process_id| has |
| 49 // misspellings. | 53 // misspellings. |
| 50 bool RendererHasMisspellings(int renderer_process_id) const; | 54 bool RendererHasMisspellings(int renderer_process_id) const; |
| 51 | 55 |
| 52 // Returns a copy of the misspellings in renderer with process ID | 56 // Returns a copy of the misspellings in renderer with process ID |
| 53 // |renderer_process_id|. | 57 // |renderer_process_id|. |
| 54 std::vector<Misspelling> GetMisspellingsInRenderer( | 58 std::vector<Misspelling> GetMisspellingsInRenderer( |
| 55 int renderer_process_id) const; | 59 int renderer_process_id) const; |
| 56 | 60 |
| 57 // Erases the misspellings with final user actions in the renderer with | 61 // Erases the misspellings with final user actions in the renderer with |
| 58 // process ID |renderer_process_id|. | 62 // process ID |renderer_process_id|. |
| 59 void EraseFinalizedMisspellings(int renderer_process_id); | 63 void EraseFinalizedMisspellings(int renderer_process_id); |
| 60 | 64 |
| 61 // Returns true if there's a misspelling with |hash| identifier. | 65 // Returns true if there's a misspelling with |hash| identifier. |
| 62 bool HasMisspelling(uint32 hash) const; | 66 bool HasMisspelling(uint32_t hash) const; |
| 63 | 67 |
| 64 // Adds the |misspelling| to feedback data. If the |misspelling| has a | 68 // Adds the |misspelling| to feedback data. If the |misspelling| has a |
| 65 // duplicate hash, then replaces the existing misspelling with the same hash. | 69 // duplicate hash, then replaces the existing misspelling with the same hash. |
| 66 void AddMisspelling(int renderer_process_id, const Misspelling& misspelling); | 70 void AddMisspelling(int renderer_process_id, const Misspelling& misspelling); |
| 67 | 71 |
| 68 // Returns true if there're no misspellings. | 72 // Returns true if there're no misspellings. |
| 69 bool Empty() const; | 73 bool Empty() const; |
| 70 | 74 |
| 71 // Returns a list of process identifiers for renderers that have misspellings. | 75 // Returns a list of process identifiers for renderers that have misspellings. |
| 72 std::vector<int> GetRendersWithMisspellings() const; | 76 std::vector<int> GetRendersWithMisspellings() const; |
| 73 | 77 |
| 74 // Finalizes all misspellings. | 78 // Finalizes all misspellings. |
| 75 void FinalizeAllMisspellings(); | 79 void FinalizeAllMisspellings(); |
| 76 | 80 |
| 77 // Returns a copy of all misspellings. | 81 // Returns a copy of all misspellings. |
| 78 std::vector<Misspelling> GetAllMisspellings() const; | 82 std::vector<Misspelling> GetAllMisspellings() const; |
| 79 | 83 |
| 80 // Removes all misspellings. | 84 // Removes all misspellings. |
| 81 void Clear(); | 85 void Clear(); |
| 82 | 86 |
| 83 // Returns a list of all misspelling identifiers for |misspelled_text|. | 87 // Returns a list of all misspelling identifiers for |misspelled_text|. |
| 84 const std::set<uint32>& FindMisspellings( | 88 const std::set<uint32_t>& FindMisspellings( |
| 85 const base::string16& misspelled_text) const; | 89 const base::string16& misspelled_text) const; |
| 86 | 90 |
| 87 private: | 91 private: |
| 88 typedef std::map<uint32, Misspelling> HashMisspellingMap; | 92 typedef std::map<uint32_t, Misspelling> HashMisspellingMap; |
| 89 typedef std::set<uint32> HashCollection; | 93 typedef std::set<uint32_t> HashCollection; |
| 90 typedef std::map<int, HashCollection> RendererHashesMap; | 94 typedef std::map<int, HashCollection> RendererHashesMap; |
| 91 typedef std::map<base::string16, HashCollection> TextHashesMap; | 95 typedef std::map<base::string16, HashCollection> TextHashesMap; |
| 92 | 96 |
| 93 // An empty hash collection to return when FindMisspellings() does not find | 97 // An empty hash collection to return when FindMisspellings() does not find |
| 94 // misspellings. | 98 // misspellings. |
| 95 const HashCollection empty_hash_collection_; | 99 const HashCollection empty_hash_collection_; |
| 96 | 100 |
| 97 // The limit on the amount of data to send to the server at once. | 101 // The limit on the amount of data to send to the server at once. |
| 98 const size_t max_total_text_size_; | 102 const size_t max_total_text_size_; |
| 99 | 103 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 110 | 114 |
| 111 // A map of misspelled text to hashes that identify misspellings. | 115 // A map of misspelled text to hashes that identify misspellings. |
| 112 TextHashesMap text_; | 116 TextHashesMap text_; |
| 113 | 117 |
| 114 DISALLOW_COPY_AND_ASSIGN(Feedback); | 118 DISALLOW_COPY_AND_ASSIGN(Feedback); |
| 115 }; | 119 }; |
| 116 | 120 |
| 117 } // namespace spellcheck | 121 } // namespace spellcheck |
| 118 | 122 |
| 119 #endif // CHROME_BROWSER_SPELLCHECKER_FEEDBACK_H_ | 123 #endif // CHROME_BROWSER_SPELLCHECKER_FEEDBACK_H_ |
| OLD | NEW |