Bug 828901 - Get the seek time as mBasePosition instead of the stream position in...
[gecko.git] / parser / html / nsHtml5AtomTable.h
bloba7df2192d14a555df8765f1056a348828cc1b04a
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 #ifndef nsHtml5AtomTable_h_
6 #define nsHtml5AtomTable_h_
8 #include "nsHashKeys.h"
9 #include "nsTHashtable.h"
10 #include "nsAutoPtr.h"
11 #include "nsIAtom.h"
12 #include "nsIThread.h"
14 class nsHtml5Atom;
16 class nsHtml5AtomEntry : public nsStringHashKey
18 public:
19 nsHtml5AtomEntry(KeyTypePointer aStr);
20 nsHtml5AtomEntry(const nsHtml5AtomEntry& aOther);
21 ~nsHtml5AtomEntry();
22 inline nsHtml5Atom* GetAtom() {
23 return mAtom;
25 private:
26 nsAutoPtr<nsHtml5Atom> mAtom;
29 /**
30 * nsHtml5AtomTable provides non-locking lookup and creation of atoms for
31 * nsHtml5Parser or nsHtml5StreamParser.
33 * The hashtable holds dynamically allocated atoms that are private to an
34 * instance of nsHtml5Parser or nsHtml5StreamParser. (Static atoms are used on
35 * interned nsHtml5ElementNames and interned nsHtml5AttributeNames. Also, when
36 * the doctype name is 'html', that identifier needs to be represented as a
37 * static atom.)
39 * Each instance of nsHtml5Parser has a single instance of nsHtml5AtomTable,
40 * and each instance of nsHtml5StreamParser has a single instance of
41 * nsHtml5AtomTable. Dynamic atoms obtained from an nsHtml5AtomTable are valid
42 * for == comparison with each other or with atoms declared in nsHtml5Atoms
43 * within the nsHtml5Tokenizer and the nsHtml5TreeBuilder instances owned by
44 * the same nsHtml5Parser/nsHtml5StreamParser instance that owns the
45 * nsHtml5AtomTable instance.
47 * Dynamic atoms (atoms whose IsStaticAtom() returns false) obtained from
48 * nsHtml5AtomTable must be re-obtained from another atom table when there's a
49 * need to migrate atoms from an nsHtml5Parser to its nsHtml5StreamParser
50 * (re-obtain from the other nsHtml5AtomTable), from an nsHtml5Parser to its
51 * owner nsHtml5Parser (re-obtain from the other nsHtml5AtomTable) or from the
52 * parser to the DOM (re-obtain from the application-wide atom table). To
53 * re-obtain an atom from another atom table, obtain a string from the atom
54 * using ToString(nsAString&) and look up an atom in the other table using that
55 * string.
57 * An instance of nsHtml5AtomTable that belongs to an nsHtml5Parser is only
58 * accessed from the main thread. An instance of nsHtml5AtomTable that belongs
59 * to an nsHtml5StreamParser is accessed both from the main thread and from the
60 * thread that executes the runnables of the nsHtml5StreamParser instance.
61 * However, the threads never access the nsHtml5AtomTable instance concurrently
62 * in the nsHtml5StreamParser case.
64 * Methods on the atoms obtained from nsHtml5AtomTable may be called on any
65 * thread, although they only need to be called on the main thread or on the
66 * thread working for the nsHtml5StreamParser when nsHtml5AtomTable belongs to
67 * an nsHtml5StreamParser.
69 * Dynamic atoms obtained from nsHtml5AtomTable are deleted when the
70 * nsHtml5AtomTable itself is destructed, which happens when the owner
71 * nsHtml5Parser or nsHtml5StreamParser is destructed.
73 class nsHtml5AtomTable
75 public:
76 nsHtml5AtomTable();
77 ~nsHtml5AtomTable();
79 /**
80 * Must be called after the constructor before use.
82 inline void Init() {
83 mTable.Init();
86 /**
87 * Obtains the atom for the given string in the scope of this atom table.
89 nsIAtom* GetAtom(const nsAString& aKey);
91 /**
92 * Empties the table.
94 void Clear() {
95 mTable.Clear();
98 #ifdef DEBUG
99 void SetPermittedLookupThread(nsIThread* aThread) {
100 mPermittedLookupThread = aThread;
102 #endif
104 private:
105 nsTHashtable<nsHtml5AtomEntry> mTable;
106 #ifdef DEBUG
107 nsCOMPtr<nsIThread> mPermittedLookupThread;
108 #endif
111 #endif // nsHtml5AtomTable_h_