blob: 01937df34b11ae7901c8ce2d236d5de658b11ddf [file] [log] [blame]
[email protected]f71e8402013-05-21 07:24:041// 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]a8e55b1e2013-05-24 06:44:199#include <set>
[email protected]f71e8402013-05-21 07:24:0410#include <vector>
11
12#include "chrome/browser/spellchecker/misspelling.h"
13
14namespace 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.
19class Feedback {
20 public:
21 Feedback();
22 ~Feedback();
23
24 // Returns the misspelling identified by |hash|. Returns NULL if there's no
[email protected]7d016b32013-05-31 15:51:0025 // misspelling identified by |hash|. Retains the ownership of the result. The
26 // caller should not modify the hash in the returned misspelling.
[email protected]f71e8402013-05-21 07:24:0427 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]7d016b32013-05-31 15:51:0071 // Returns a list of all misspelling identifiers for |misspelled_text|.
72 const std::set<uint32>& FindMisspellings(const string16& misspelled_text);
73
[email protected]f71e8402013-05-21 07:24:0474 private:
75 // A map of hashes that identify document markers to feedback data to be sent
76 // to spelling service.
[email protected]a8e55b1e2013-05-24 06:44:1977 typedef std::map<uint32, Misspelling> HashMisspellingMap;
78 HashMisspellingMap misspellings_;
[email protected]f71e8402013-05-21 07:24:0479
80 // A map of renderer process ID to hashes that identify misspellings.
[email protected]a8e55b1e2013-05-24 06:44:1981 typedef std::set<uint32> HashCollection;
82 typedef std::map<int, HashCollection> RendererHashesMap;
[email protected]7d016b32013-05-31 15:51:0083 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]f71e8402013-05-21 07:24:0488
89 DISALLOW_COPY_AND_ASSIGN(Feedback);
90};
91
92} // namespace spellcheck
93
94#endif // CHROME_BROWSER_SPELLCHECKER_FEEDBACK_H_