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.
5 // An object to store user feedback to spellcheck suggestions from spelling
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.
12 #ifndef CHROME_BROWSER_SPELLCHECKER_FEEDBACK_H_
13 #define CHROME_BROWSER_SPELLCHECKER_FEEDBACK_H_
19 #include "chrome/browser/spellchecker/misspelling.h"
21 namespace spellcheck
{
23 // Stores user feedback to spellcheck suggestions. Sample usage:
25 // feedback.AddMisspelling(renderer_process_id, Misspelling(
26 // base::ASCIIToUTF16("Helllo world"), 0, 6,
27 // std::vector<base::string16>(), GenerateRandomHash()));
28 // feedback.FinalizeRemovedMisspellings(renderer_process_id,
29 // std::vector<uint32>());
30 // ProcessFeedback(feedback.GetMisspellingsInRenderer(renderer_process_id));
31 // feedback.EraseFinalizedMisspellings(renderer_process_id);
34 explicit Feedback(size_t max_total_text_size
);
37 // Returns the misspelling identified by |hash|. Returns NULL if there's no
38 // misspelling identified by |hash|. Retains the ownership of the result. The
39 // caller should not modify the hash in the returned misspelling.
40 Misspelling
* GetMisspelling(uint32 hash
);
42 // Finalizes the user actions on misspellings that are removed from the
43 // renderer process with ID |renderer_process_id|.
44 void FinalizeRemovedMisspellings(
45 int renderer_process_id
,
46 const std::vector
<uint32
>& remaining_markers
);
48 // Returns true if the renderer with process ID |renderer_process_id| has
50 bool RendererHasMisspellings(int renderer_process_id
) const;
52 // Returns a copy of the misspellings in renderer with process ID
53 // |renderer_process_id|.
54 std::vector
<Misspelling
> GetMisspellingsInRenderer(
55 int renderer_process_id
) const;
57 // Erases the misspellings with final user actions in the renderer with
58 // process ID |renderer_process_id|.
59 void EraseFinalizedMisspellings(int renderer_process_id
);
61 // Returns true if there's a misspelling with |hash| identifier.
62 bool HasMisspelling(uint32 hash
) const;
64 // Adds the |misspelling| to feedback data. If the |misspelling| has a
65 // duplicate hash, then replaces the existing misspelling with the same hash.
66 void AddMisspelling(int renderer_process_id
, const Misspelling
& misspelling
);
68 // Returns true if there're no misspellings.
71 // Returns a list of process identifiers for renderers that have misspellings.
72 std::vector
<int> GetRendersWithMisspellings() const;
74 // Finalizes all misspellings.
75 void FinalizeAllMisspellings();
77 // Returns a copy of all misspellings.
78 std::vector
<Misspelling
> GetAllMisspellings() const;
80 // Removes all misspellings.
83 // Returns a list of all misspelling identifiers for |misspelled_text|.
84 const std::set
<uint32
>& FindMisspellings(
85 const base::string16
& misspelled_text
) const;
88 typedef std::map
<uint32
, Misspelling
> HashMisspellingMap
;
89 typedef std::set
<uint32
> HashCollection
;
90 typedef std::map
<int, HashCollection
> RendererHashesMap
;
91 typedef std::map
<base::string16
, HashCollection
> TextHashesMap
;
93 // An empty hash collection to return when FindMisspellings() does not find
95 const HashCollection empty_hash_collection_
;
97 // The limit on the amount of data to send to the server at once.
98 const size_t max_total_text_size_
;
100 // Size of all feedback text, used to limit the estimated amount of data sent
101 // to the server at once.
102 size_t total_text_size_
;
104 // A map of hashes that identify document markers to feedback data to be sent
105 // to spelling service.
106 HashMisspellingMap misspellings_
;
108 // A map of renderer process ID to hashes that identify misspellings.
109 RendererHashesMap renderers_
;
111 // A map of misspelled text to hashes that identify misspellings.
114 DISALLOW_COPY_AND_ASSIGN(Feedback
);
117 } // namespace spellcheck
119 #endif // CHROME_BROWSER_SPELLCHECKER_FEEDBACK_H_