hunspell_engine.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (c) 2012 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. #ifndef COMPONENTS_SPELLCHECK_RENDERER_HUNSPELL_ENGINE_H_
  5. #define COMPONENTS_SPELLCHECK_RENDERER_HUNSPELL_ENGINE_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "base/strings/utf_string_conversions.h"
  10. #include "components/spellcheck/common/spellcheck_common.h"
  11. #include "components/spellcheck/renderer/spelling_engine.h"
  12. class Hunspell;
  13. namespace base {
  14. class MemoryMappedFile;
  15. }
  16. class HunspellEngine : public SpellingEngine {
  17. public:
  18. explicit HunspellEngine(
  19. service_manager::LocalInterfaceProvider* embedder_provider);
  20. ~HunspellEngine() override;
  21. void Init(base::File file) override;
  22. bool InitializeIfNeeded() override;
  23. bool IsEnabled() override;
  24. bool CheckSpelling(const std::u16string& word_to_check, int tag) override;
  25. void FillSuggestionList(
  26. const std::u16string& wrong_word,
  27. std::vector<std::u16string>* optional_suggestions) override;
  28. private:
  29. // Initializes the Hunspell dictionary, or does nothing if |hunspell_| is
  30. // non-null. This blocks.
  31. void InitializeHunspell();
  32. // We memory-map the BDict file.
  33. std::unique_ptr<base::MemoryMappedFile> bdict_file_;
  34. // The hunspell dictionary in use.
  35. std::unique_ptr<Hunspell> hunspell_;
  36. base::File file_;
  37. // This flag is true if hunspell is enabled.
  38. bool hunspell_enabled_;
  39. // This flag is true if we have been initialized.
  40. // The value indicates whether we should request a
  41. // dictionary from the browser when the render view asks us to check the
  42. // spelling of a word.
  43. bool initialized_;
  44. // This flag is true if we have requested dictionary.
  45. bool dictionary_requested_;
  46. service_manager::LocalInterfaceProvider* embedder_provider_;
  47. };
  48. #endif // COMPONENTS_SPELLCHECK_RENDERER_HUNSPELL_ENGINE_H_