1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Mozilla Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 2006
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Honza Bambas <honzab@firemni.cz>
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either of the GNU General Public License Version 2 or later (the "GPL"),
27 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : #include "nsDOMStorageBaseDB.h"
40 : #include "nsDOMStorage.h"
41 :
42 : PRUint64 nsDOMStorageBaseDB::sGlobalVersion = 1;
43 :
44 308 : nsDOMStorageBaseDB::nsDOMStorageBaseDB()
45 : {
46 308 : mScopesVersion.Init(8);
47 308 : }
48 :
49 : // public
50 :
51 : void
52 68 : nsDOMStorageBaseDB::MarkScopeCached(DOMStorageImpl* aStorage)
53 : {
54 68 : aStorage->SetCachedVersion(CachedScopeVersion(aStorage));
55 68 : }
56 :
57 : bool
58 92 : nsDOMStorageBaseDB::IsScopeDirty(DOMStorageImpl* aStorage)
59 : {
60 92 : return !aStorage->CachedVersion() ||
61 92 : (aStorage->CachedVersion() != CachedScopeVersion(aStorage));
62 : }
63 :
64 : // protected
65 :
66 : // static
67 : PRUint64
68 345 : nsDOMStorageBaseDB::NextGlobalVersion()
69 : {
70 345 : sGlobalVersion++;
71 345 : if (sGlobalVersion == 0) // Control overlap, never return 0
72 0 : sGlobalVersion = 1;
73 345 : return sGlobalVersion;
74 : }
75 :
76 : PRUint64
77 132 : nsDOMStorageBaseDB::CachedScopeVersion(DOMStorageImpl* aStorage)
78 : {
79 : PRUint64 currentVersion;
80 132 : if (mScopesVersion.Get(aStorage->GetScopeDBKey(), ¤tVersion))
81 112 : return currentVersion;
82 :
83 20 : mScopesVersion.Put(aStorage->GetScopeDBKey(), sGlobalVersion);
84 20 : return sGlobalVersion;
85 : }
86 :
87 : void
88 30 : nsDOMStorageBaseDB::MarkScopeDirty(DOMStorageImpl* aStorage)
89 : {
90 30 : PRUint64 nextVersion = NextGlobalVersion();
91 30 : mScopesVersion.Put(aStorage->GetScopeDBKey(), nextVersion);
92 :
93 : // We may do this because the storage updates its cache along with
94 : // updating the database.
95 30 : aStorage->SetCachedVersion(nextVersion);
96 30 : }
97 :
98 : void
99 315 : nsDOMStorageBaseDB::MarkAllScopesDirty()
100 : {
101 315 : mScopesVersion.Clear();
102 315 : NextGlobalVersion();
103 315 : }
|