[email protected] | f71e840 | 2013-05-21 07:24:04 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CHROME_BROWSER_SPELLCHECKER_FEEDBACK_H_ |
| 6 | #define CHROME_BROWSER_SPELLCHECKER_FEEDBACK_H_ |
| 7 | |
| 8 | #include <map> |
[email protected] | a8e55b1e | 2013-05-24 06:44:19 | [diff] [blame] | 9 | #include <set> |
[email protected] | f71e840 | 2013-05-21 07:24:04 | [diff] [blame] | 10 | #include <vector> |
| 11 | |
| 12 | #include "chrome/browser/spellchecker/misspelling.h" |
| 13 | |
| 14 | namespace spellcheck { |
| 15 | |
| 16 | // Stores feedback for the spelling service in |Misspelling| objects. Each |
| 17 | // |Misspelling| object is identified by a |hash| and corresponds to a document |
| 18 | // marker with the same |hash| identifier in the renderer. |
| 19 | class Feedback { |
| 20 | public: |
| 21 | Feedback(); |
| 22 | ~Feedback(); |
| 23 | |
| 24 | // Returns the misspelling identified by |hash|. Returns NULL if there's no |
[email protected] | 7d016b3 | 2013-05-31 15:51:00 | [diff] [blame^] | 25 | // misspelling identified by |hash|. Retains the ownership of the result. The |
| 26 | // caller should not modify the hash in the returned misspelling. |
[email protected] | f71e840 | 2013-05-21 07:24:04 | [diff] [blame] | 27 | Misspelling* GetMisspelling(uint32 hash); |
| 28 | |
| 29 | // Finalizes the user actions on misspellings that are removed from the |
| 30 | // renderer process with ID |renderer_process_id|. |
| 31 | void FinalizeRemovedMisspellings( |
| 32 | int renderer_process_id, |
| 33 | const std::vector<uint32>& remaining_markers); |
| 34 | |
| 35 | // Returns true if the renderer with process ID |renderer_process_id| has |
| 36 | // misspellings. Otherwise returns false. |
| 37 | bool RendererHasMisspellings(int renderer_process_id) const; |
| 38 | |
| 39 | // Returns a copy of the misspellings in renderer with process ID |
| 40 | // |renderer_process_id|. |
| 41 | std::vector<Misspelling> GetMisspellingsInRenderer( |
| 42 | int renderer_process_id) const; |
| 43 | |
| 44 | // Erases the misspellings with final user actions in the renderer with |
| 45 | // process ID |renderer_process_id|. |
| 46 | void EraseFinalizedMisspellings(int renderer_process_id); |
| 47 | |
| 48 | // Returns true if there's a misspelling with |hash| identifier. Otherwise |
| 49 | // returns false. |
| 50 | bool HasMisspelling(uint32 hash) const; |
| 51 | |
| 52 | // Adds the |misspelling| to feedback data. If the |misspelling| has a |
| 53 | // duplicate hash, then replaces the existing misspelling with the same hash. |
| 54 | void AddMisspelling(int renderer_process_id, const Misspelling& misspelling); |
| 55 | |
| 56 | // Returns true if there're no misspellings. Otherwise returns false. |
| 57 | bool Empty() const; |
| 58 | |
| 59 | // Returns a list of process identifiers for renderers that have misspellings. |
| 60 | std::vector<int> GetRendersWithMisspellings() const; |
| 61 | |
| 62 | // Finalizes all misspellings. |
| 63 | void FinalizeAllMisspellings(); |
| 64 | |
| 65 | // Returns a copy of all misspellings. |
| 66 | std::vector<Misspelling> GetAllMisspellings() const; |
| 67 | |
| 68 | // Removes all misspellings. |
| 69 | void Clear(); |
| 70 | |
[email protected] | 7d016b3 | 2013-05-31 15:51:00 | [diff] [blame^] | 71 | // Returns a list of all misspelling identifiers for |misspelled_text|. |
| 72 | const std::set<uint32>& FindMisspellings(const string16& misspelled_text); |
| 73 | |
[email protected] | f71e840 | 2013-05-21 07:24:04 | [diff] [blame] | 74 | private: |
| 75 | // A map of hashes that identify document markers to feedback data to be sent |
| 76 | // to spelling service. |
[email protected] | a8e55b1e | 2013-05-24 06:44:19 | [diff] [blame] | 77 | typedef std::map<uint32, Misspelling> HashMisspellingMap; |
| 78 | HashMisspellingMap misspellings_; |
[email protected] | f71e840 | 2013-05-21 07:24:04 | [diff] [blame] | 79 | |
| 80 | // A map of renderer process ID to hashes that identify misspellings. |
[email protected] | a8e55b1e | 2013-05-24 06:44:19 | [diff] [blame] | 81 | typedef std::set<uint32> HashCollection; |
| 82 | typedef std::map<int, HashCollection> RendererHashesMap; |
[email protected] | 7d016b3 | 2013-05-31 15:51:00 | [diff] [blame^] | 83 | RendererHashesMap renderers_; |
| 84 | |
| 85 | // A map of misspelled text to hashes that identify misspellings. |
| 86 | typedef std::map<string16, HashCollection> TextHashesMap; |
| 87 | TextHashesMap text_; |
[email protected] | f71e840 | 2013-05-21 07:24:04 | [diff] [blame] | 88 | |
| 89 | DISALLOW_COPY_AND_ASSIGN(Feedback); |
| 90 | }; |
| 91 | |
| 92 | } // namespace spellcheck |
| 93 | |
| 94 | #endif // CHROME_BROWSER_SPELLCHECKER_FEEDBACK_H_ |