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