blob: 243a8076c9de521edb04b115c21ea5aee940c0d3 [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
25 // misspelling identified by |hash|. Retains the ownership of the result.
26 Misspelling* GetMisspelling(uint32 hash);
27
28 // Finalizes the user actions on misspellings that are removed from the
29 // renderer process with ID |renderer_process_id|.
30 void FinalizeRemovedMisspellings(
31 int renderer_process_id,
32 const std::vector<uint32>& remaining_markers);
33
34 // Returns true if the renderer with process ID |renderer_process_id| has
35 // misspellings. Otherwise returns false.
36 bool RendererHasMisspellings(int renderer_process_id) const;
37
38 // Returns a copy of the misspellings in renderer with process ID
39 // |renderer_process_id|.
40 std::vector<Misspelling> GetMisspellingsInRenderer(
41 int renderer_process_id) const;
42
43 // Erases the misspellings with final user actions in the renderer with
44 // process ID |renderer_process_id|.
45 void EraseFinalizedMisspellings(int renderer_process_id);
46
47 // Returns true if there's a misspelling with |hash| identifier. Otherwise
48 // returns false.
49 bool HasMisspelling(uint32 hash) const;
50
51 // Adds the |misspelling| to feedback data. If the |misspelling| has a
52 // duplicate hash, then replaces the existing misspelling with the same hash.
53 void AddMisspelling(int renderer_process_id, const Misspelling& misspelling);
54
55 // Returns true if there're no misspellings. Otherwise returns false.
56 bool Empty() const;
57
58 // Returns a list of process identifiers for renderers that have misspellings.
59 std::vector<int> GetRendersWithMisspellings() const;
60
61 // Finalizes all misspellings.
62 void FinalizeAllMisspellings();
63
64 // Returns a copy of all misspellings.
65 std::vector<Misspelling> GetAllMisspellings() const;
66
67 // Removes all misspellings.
68 void Clear();
69
70 private:
71 // A map of hashes that identify document markers to feedback data to be sent
72 // to spelling service.
[email protected]a8e55b1e2013-05-24 06:44:1973 typedef std::map<uint32, Misspelling> HashMisspellingMap;
74 HashMisspellingMap misspellings_;
[email protected]f71e8402013-05-21 07:24:0475
76 // A map of renderer process ID to hashes that identify misspellings.
[email protected]a8e55b1e2013-05-24 06:44:1977 typedef std::set<uint32> HashCollection;
78 typedef std::map<int, HashCollection> RendererHashesMap;
79 RendererHashesMap hashes_;
[email protected]f71e8402013-05-21 07:24:0480
81 DISALLOW_COPY_AND_ASSIGN(Feedback);
82};
83
84} // namespace spellcheck
85
86#endif // CHROME_BROWSER_SPELLCHECKER_FEEDBACK_H_