tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

mozPersonalDictionary.h (2473B)


      1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* This Source Code Form is subject to the terms of the Mozilla Public
      3 * License, v. 2.0. If a copy of the MPL was not distributed with this
      4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      5 
      6 #ifndef mozPersonalDictionary_h__
      7 #define mozPersonalDictionary_h__
      8 
      9 #include "nsCOMPtr.h"
     10 #include "nsString.h"
     11 #include "mozIPersonalDictionary.h"
     12 #include "nsIObserver.h"
     13 #include "nsWeakReference.h"
     14 #include "nsTHashSet.h"
     15 #include "nsCRT.h"
     16 #include "nsCycleCollectionParticipant.h"
     17 #include "nsHashKeys.h"
     18 #include <mozilla/Monitor.h>
     19 
     20 #define MOZ_PERSONALDICTIONARY_CONTRACTID \
     21  "@mozilla.org/spellchecker/personaldictionary;1"
     22 #define MOZ_PERSONALDICTIONARY_CID            \
     23  {/* 7EF52EAF-B7E1-462B-87E2-5D1DBACA9048 */ \
     24   0X7EF52EAF,                                \
     25   0XB7E1,                                    \
     26   0X462B,                                    \
     27   {0X87, 0XE2, 0X5D, 0X1D, 0XBA, 0XCA, 0X90, 0X48}}
     28 
     29 class mozPersonalDictionaryLoader;
     30 class mozPersonalDictionarySave;
     31 
     32 class mozPersonalDictionary final : public mozIPersonalDictionary,
     33                                    public nsIObserver,
     34                                    public nsSupportsWeakReference {
     35 public:
     36  NS_DECL_ISUPPORTS
     37  NS_DECL_MOZIPERSONALDICTIONARY
     38  NS_DECL_NSIOBSERVER
     39 
     40  mozPersonalDictionary();
     41 
     42  nsresult Init();
     43 
     44 protected:
     45  virtual ~mozPersonalDictionary();
     46 
     47  /* true if the dictionary has been loaded from disk */
     48  bool mIsLoaded;
     49 
     50  /* true if a dictionary save is pending */
     51  bool mSavePending;
     52 
     53  nsCOMPtr<nsIFile> mFile;
     54  mozilla::Monitor mMonitor MOZ_UNANNOTATED;
     55  mozilla::Monitor mMonitorSave MOZ_UNANNOTATED;
     56  nsTHashSet<nsString> mDictionaryTable;
     57  nsTHashSet<nsString> mIgnoreTable;
     58 
     59 private:
     60  /* wait for the asynchronous load of the dictionary to be completed */
     61  void WaitForLoad();
     62 
     63  /* enter the monitor before starting a synchronous load off the main-thread */
     64  void SyncLoad();
     65 
     66  /* launch an asynchrounous load of the dictionary from the main-thread
     67   * after successfully initializing mFile with the path of the dictionary */
     68  nsresult LoadInternal();
     69 
     70  /* perform a synchronous load of the dictionary from disk */
     71  void SyncLoadInternal();
     72 
     73  /* wait for the asynchronous save of the dictionary to be completed */
     74  void WaitForSave();
     75 
     76  friend class mozPersonalDictionaryLoader;
     77  friend class mozPersonalDictionarySave;
     78 };
     79 
     80 #endif