| Differences between
and this patch
- WebCore/ChangeLog +59 lines
Lines 1-3 WebCore/ChangeLog_sec1
1
2009-06-16  Jeremy Orlow  <jorlow@chromium.org>
2
3
        Reviewed by NOBODY (OOPS!).
4
5
        First step in https://bugs.webkit.org/show_bug.cgi?id=25376
6
7
        Add StorageSyncManager.cpp/h
8
9
        * GNUmakefile.am:
10
        * WebCore.pro:
11
        * WebCore.vcproj/WebCore.vcproj:
12
        * WebCore.xcodeproj/project.pbxproj:
13
        * WebCoreSources.bkl:
14
15
        In preparation for combining SessionStorage and LocalStorage into a
16
        single StorageManager, move the syncing bits out of LocalStorage and
17
        into its own class.
18
19
        The next step is to combine LocalStorageArea and SessionStorageArea
20
        into one.  Then SessionStorage and LocalStorage can be combined.
21
22
        Note that combining them will cut down on code paths that must be
23
        proxied, eliminate virtual dispatch, and allow Chromium to (eventually)
24
        write historical sessionStorage to disk when memory is getting tight.
25
26
        Also remove a couple bits of cruft including code for quotas which is
27
        unnecessary (since a meta-data db is unnecessary since you can just
28
        count bytes as you read the local storage databases into memory).
29
30
        * storage/LocalStorage.cpp:
31
        (WebCore::LocalStorage::LocalStorage):
32
        (WebCore::LocalStorage::storageArea):
33
        (WebCore::LocalStorage::close):
34
        * storage/LocalStorage.h:
35
        * storage/LocalStorageArea.cpp:
36
        (WebCore::LocalStorageArea::LocalStorageArea):
37
        (WebCore::LocalStorageArea::scheduleFinalSync):
38
        (WebCore::LocalStorageArea::syncTimerFired):
39
        (WebCore::LocalStorageArea::performImport):
40
        * storage/LocalStorageArea.h:
41
        (WebCore::LocalStorageArea::create):
42
        * storage/LocalStorageTask.cpp:
43
        (WebCore::LocalStorageTask::performTask):
44
        * storage/LocalStorageTask.h:
45
        (WebCore::LocalStorageTask::):
46
        (WebCore::LocalStorageTask::createImport):
47
        * storage/LocalStorageThread.cpp:
48
        * storage/LocalStorageThread.h:
49
        * storage/SessionStorage.h:
50
        * storage/StorageSyncManager.cpp: Copied from WebCore/storage/LocalStorage.cpp.
51
        (WebCore::StorageSyncManager::create):
52
        (WebCore::StorageSyncManager::StorageSyncManager):
53
        (WebCore::StorageSyncManager::fullDatabaseFilename):
54
        (WebCore::StorageSyncManager::close):
55
        (WebCore::StorageSyncManager::scheduleImport):
56
        (WebCore::StorageSyncManager::scheduleSync):
57
        * storage/StorageSyncManager.h: Copied from WebCore/storage/LocalStorage.h.
58
        (WebCore::):
59
1
2009-06-16  Jian Li  <jianli@chromium.org>
60
2009-06-16  Jian Li  <jianli@chromium.org>
2
61
3
        Reviewed by Dimitri Glazkov.
62
        Reviewed by Dimitri Glazkov.
- WebCore/GNUmakefile.am -1 / +3 lines
Lines 2079-2085 webcore_sources += \ WebCore/GNUmakefile.am_sec1
2079
	WebCore/storage/StorageEvent.cpp \
2079
	WebCore/storage/StorageEvent.cpp \
2080
	WebCore/storage/StorageEvent.h \
2080
	WebCore/storage/StorageEvent.h \
2081
	WebCore/storage/StorageMap.cpp \
2081
	WebCore/storage/StorageMap.cpp \
2082
	WebCore/storage/StorageMap.h
2082
	WebCore/storage/StorageMap.h \
2083
	WebCore/storage/StorageSyncManager.cpp \
2084
	WebCore/storage/StorageSyncManager.h
2083
endif # END ENABLE_DOM_STORAGE
2085
endif # END ENABLE_DOM_STORAGE
2084
2086
2085
# ----
2087
# ----
- WebCore/WebCore.pro +1 lines
Lines 1364-1369 contains(DEFINES, ENABLE_DOM_STORAGE=1) WebCore/WebCore.pro_sec1
1364
        storage/StorageEvent.cpp \
1364
        storage/StorageEvent.cpp \
1365
        storage/SessionStorage.cpp \
1365
        storage/SessionStorage.cpp \
1366
        storage/SessionStorageArea.cpp \
1366
        storage/SessionStorageArea.cpp \
1367
        storage/StorageSyncManager.cpp \
1367
        bindings/js/JSStorageCustom.cpp
1368
        bindings/js/JSStorageCustom.cpp
1368
1369
1369
    IDL_BINDINGS += \
1370
    IDL_BINDINGS += \
- WebCore/WebCoreSources.bkl +1 lines
Lines 1015-1020 This file contains the list of files nee WebCore/WebCoreSources.bkl_sec1
1015
        storage/StorageMap.cpp
1015
        storage/StorageMap.cpp
1016
        storage/SessionStorage.cpp
1016
        storage/SessionStorage.cpp
1017
        storage/SessionStorageArea.cpp
1017
        storage/SessionStorageArea.cpp
1018
        storage/StorageSyncManager.cpp
1018
    </set>
1019
    </set>
1019
1020
1020
    <set append="1" var="WEBCORE_SOURCES_XML">
1021
    <set append="1" var="WEBCORE_SOURCES_XML">
- WebCore/WebCore.vcproj/WebCore.vcproj +8 lines
Lines 15659-15664 WebCore/WebCore.vcproj/WebCore.vcproj_sec1
15659
				>
15659
				>
15660
			</File>
15660
			</File>
15661
			<File
15661
			<File
15662
				RelativePath="..\storage\StorageSyncManager.cpp"
15663
				>
15664
			</File>
15665
			<File
15666
				RelativePath="..\storage\StorageSyncManager.h"
15667
				>
15668
			</File>
15669
			<File
15662
				RelativePath="..\storage\VersionChangeCallback.h"
15670
				RelativePath="..\storage\VersionChangeCallback.h"
15663
				>
15671
				>
15664
			</File>
15672
			</File>
- WebCore/WebCore.xcodeproj/project.pbxproj +8 lines
Lines 4258-4263 WebCore/WebCore.xcodeproj/project.pbxproj_sec1
4258
		C0DFC8700DB6841A003EAE7C /* JSConsoleCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0DFC86F0DB6841A003EAE7C /* JSConsoleCustom.cpp */; };
4258
		C0DFC8700DB6841A003EAE7C /* JSConsoleCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C0DFC86F0DB6841A003EAE7C /* JSConsoleCustom.cpp */; };
4259
		C105DA620F3AA68F001DD44F /* TextEncodingDetectorICU.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C105DA610F3AA68F001DD44F /* TextEncodingDetectorICU.cpp */; };
4259
		C105DA620F3AA68F001DD44F /* TextEncodingDetectorICU.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C105DA610F3AA68F001DD44F /* TextEncodingDetectorICU.cpp */; };
4260
		C105DA640F3AA6B8001DD44F /* TextEncodingDetector.h in Headers */ = {isa = PBXBuildFile; fileRef = C105DA630F3AA6B8001DD44F /* TextEncodingDetector.h */; };
4260
		C105DA640F3AA6B8001DD44F /* TextEncodingDetector.h in Headers */ = {isa = PBXBuildFile; fileRef = C105DA630F3AA6B8001DD44F /* TextEncodingDetector.h */; };
4261
		C5102D940FD9AA2D00FAFF04 /* StorageSyncManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C5102D920FD9AA2D00FAFF04 /* StorageSyncManager.h */; };
4262
		C5102D950FD9AA2D00FAFF04 /* StorageSyncManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C5102D930FD9AA2D00FAFF04 /* StorageSyncManager.cpp */; };
4261
		C6D74AD509AA282E000B0A52 /* ModifySelectionListLevel.h in Headers */ = {isa = PBXBuildFile; fileRef = C6D74AD309AA282E000B0A52 /* ModifySelectionListLevel.h */; };
4263
		C6D74AD509AA282E000B0A52 /* ModifySelectionListLevel.h in Headers */ = {isa = PBXBuildFile; fileRef = C6D74AD309AA282E000B0A52 /* ModifySelectionListLevel.h */; };
4262
		C6D74AE409AA290A000B0A52 /* ModifySelectionListLevel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D74AE309AA290A000B0A52 /* ModifySelectionListLevel.cpp */; };
4264
		C6D74AE409AA290A000B0A52 /* ModifySelectionListLevel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D74AE309AA290A000B0A52 /* ModifySelectionListLevel.cpp */; };
4263
		D05CED290A40BB2C00C5AF38 /* FormatBlockCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D05CED270A40BB2C00C5AF38 /* FormatBlockCommand.cpp */; };
4265
		D05CED290A40BB2C00C5AF38 /* FormatBlockCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = D05CED270A40BB2C00C5AF38 /* FormatBlockCommand.cpp */; };
Lines 9057-9062 WebCore/WebCore.xcodeproj/project.pbxproj_sec2
9057
		C0DFC86F0DB6841A003EAE7C /* JSConsoleCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSConsoleCustom.cpp; sourceTree = "<group>"; };
9059
		C0DFC86F0DB6841A003EAE7C /* JSConsoleCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSConsoleCustom.cpp; sourceTree = "<group>"; };
9058
		C105DA610F3AA68F001DD44F /* TextEncodingDetectorICU.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextEncodingDetectorICU.cpp; sourceTree = "<group>"; };
9060
		C105DA610F3AA68F001DD44F /* TextEncodingDetectorICU.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextEncodingDetectorICU.cpp; sourceTree = "<group>"; };
9059
		C105DA630F3AA6B8001DD44F /* TextEncodingDetector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextEncodingDetector.h; sourceTree = "<group>"; };
9061
		C105DA630F3AA6B8001DD44F /* TextEncodingDetector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextEncodingDetector.h; sourceTree = "<group>"; };
9062
		C5102D920FD9AA2D00FAFF04 /* StorageSyncManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StorageSyncManager.h; sourceTree = "<group>"; };
9063
		C5102D930FD9AA2D00FAFF04 /* StorageSyncManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StorageSyncManager.cpp; sourceTree = "<group>"; };
9060
		C6D74AD309AA282E000B0A52 /* ModifySelectionListLevel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ModifySelectionListLevel.h; sourceTree = "<group>"; };
9064
		C6D74AD309AA282E000B0A52 /* ModifySelectionListLevel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ModifySelectionListLevel.h; sourceTree = "<group>"; };
9061
		C6D74AE309AA290A000B0A52 /* ModifySelectionListLevel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ModifySelectionListLevel.cpp; sourceTree = "<group>"; };
9065
		C6D74AE309AA290A000B0A52 /* ModifySelectionListLevel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ModifySelectionListLevel.cpp; sourceTree = "<group>"; };
9062
		D05CED270A40BB2C00C5AF38 /* FormatBlockCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FormatBlockCommand.cpp; sourceTree = "<group>"; };
9066
		D05CED270A40BB2C00C5AF38 /* FormatBlockCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FormatBlockCommand.cpp; sourceTree = "<group>"; };
Lines 9646-9651 WebCore/WebCore.xcodeproj/project.pbxproj_sec3
9646
				51E0BABD0DA5548400A9E417 /* StorageEvent.idl */,
9650
				51E0BABD0DA5548400A9E417 /* StorageEvent.idl */,
9647
				51E0BB370DA5ACB600A9E417 /* StorageMap.cpp */,
9651
				51E0BB370DA5ACB600A9E417 /* StorageMap.cpp */,
9648
				51E0BB360DA5ACB600A9E417 /* StorageMap.h */,
9652
				51E0BB360DA5ACB600A9E417 /* StorageMap.h */,
9653
				C5102D920FD9AA2D00FAFF04 /* StorageSyncManager.h */,
9654
				C5102D930FD9AA2D00FAFF04 /* StorageSyncManager.cpp */,
9649
			);
9655
			);
9650
			indentWidth = 4;
9656
			indentWidth = 4;
9651
			path = storage;
9657
			path = storage;
Lines 16795-16800 WebCore/WebCore.xcodeproj/project.pbxproj_sec4
16795
				081EBF3B0FD34F4100DA7559 /* SVGFilterBuilder.h in Headers */,
16801
				081EBF3B0FD34F4100DA7559 /* SVGFilterBuilder.h in Headers */,
16796
				18F831B80FD48C7800D8C56B /* WorkerLoaderProxy.h in Headers */,
16802
				18F831B80FD48C7800D8C56B /* WorkerLoaderProxy.h in Headers */,
16797
				A89CCC530F44E98100B5DA10 /* ReplaceNodeWithSpanCommand.h in Headers */,
16803
				A89CCC530F44E98100B5DA10 /* ReplaceNodeWithSpanCommand.h in Headers */,
16804
				C5102D940FD9AA2D00FAFF04 /* StorageSyncManager.h in Headers */,
16798
				2EA768040FE7126400AB9C8A /* WorkerScriptLoaderClient.h in Headers */,
16805
				2EA768040FE7126400AB9C8A /* WorkerScriptLoaderClient.h in Headers */,
16799
			);
16806
			);
16800
			runOnlyForDeploymentPostprocessing = 0;
16807
			runOnlyForDeploymentPostprocessing = 0;
Lines 18789-18794 WebCore/WebCore.xcodeproj/project.pbxproj_sec5
18789
				845E72FB0FD2623900A87D79 /* SVGFilter.cpp in Sources */,
18796
				845E72FB0FD2623900A87D79 /* SVGFilter.cpp in Sources */,
18790
				081EBF3A0FD34F4100DA7559 /* SVGFilterBuilder.cpp in Sources */,
18797
				081EBF3A0FD34F4100DA7559 /* SVGFilterBuilder.cpp in Sources */,
18791
				A89CCC520F44E98100B5DA10 /* ReplaceNodeWithSpanCommand.cpp in Sources */,
18798
				A89CCC520F44E98100B5DA10 /* ReplaceNodeWithSpanCommand.cpp in Sources */,
18799
				C5102D950FD9AA2D00FAFF04 /* StorageSyncManager.cpp in Sources */,
18792
			);
18800
			);
18793
			runOnlyForDeploymentPostprocessing = 0;
18801
			runOnlyForDeploymentPostprocessing = 0;
18794
		};
18802
		};
- WebCore/storage/LocalStorage.cpp -68 / +8 lines
Lines 37-42 WebCore/storage/LocalStorage.cpp_sec1
37
#include "Page.h"
37
#include "Page.h"
38
#include "PageGroup.h"
38
#include "PageGroup.h"
39
#include "StorageArea.h"
39
#include "StorageArea.h"
40
#include "StorageSyncManager.h"
40
#include <wtf/StdLibExtras.h>
41
#include <wtf/StdLibExtras.h>
41
42
42
namespace WebCore {
43
namespace WebCore {
Lines 64-78 PassRefPtr<LocalStorage> LocalStorage::l WebCore/storage/LocalStorage.cpp_sec2
64
65
65
LocalStorage::LocalStorage(const String& path)
66
LocalStorage::LocalStorage(const String& path)
66
    : m_path(path.copy())
67
    : m_path(path.copy())
68
    , m_syncManager(0)
67
{
69
{
68
    // If the path is empty, we know we're never going to be using the thread for anything, so don't start it.
70
    if (!m_path.isEmpty())
69
    // In the future, we might also want to consider removing it from the DOM in that case - <rdar://problem/5960470>
71
        m_syncManager = StorageSyncManager::create(m_path);
70
    if (path.isEmpty())
71
        return;
72
73
    m_thread = LocalStorageThread::create();
74
    m_thread->start();
75
    m_thread->scheduleImport(this);
76
}
72
}
77
73
78
LocalStorage::~LocalStorage()
74
LocalStorage::~LocalStorage()
Lines 92-145 PassRefPtr<StorageArea> LocalStorage::st WebCore/storage/LocalStorage.cpp_sec3
92
    // To know if an area has previously been established, we need to wait until this LocalStorage 
88
    // To know if an area has previously been established, we need to wait until this LocalStorage 
93
    // object has finished it's AreaImport task.
89
    // object has finished it's AreaImport task.
94
90
95
96
    // FIXME: If the storage area is being established for the first time here, we need to 
91
    // FIXME: If the storage area is being established for the first time here, we need to 
97
    // sync its existance and quota out to disk via an task of type AreaSync
92
    // sync its existance and quota out to disk via an task of type AreaSync
98
93
99
    RefPtr<LocalStorageArea> storageArea;
94
    RefPtr<LocalStorageArea> storageArea;
100
    if (storageArea = m_storageAreaMap.get(origin))
95
    if (storageArea = m_storageAreaMap.get(origin))
101
        return storageArea.release();
96
        return storageArea.release();
102
        
97
    
103
    storageArea = LocalStorageArea::create(origin, this);
98
    storageArea = LocalStorageArea::create(origin, m_syncManager);
104
    m_storageAreaMap.set(origin, storageArea);
99
    m_storageAreaMap.set(origin, storageArea);
105
    return storageArea.release();
100
    return storageArea.release();
106
}
101
}
107
102
108
String LocalStorage::fullDatabaseFilename(SecurityOrigin* origin)
109
{
110
    // FIXME: Once we actually track origin/quota entries to see which origins have local storage established,
111
    // we will return an empty path name if the origin isn't allowed to have LocalStorage.
112
    // We'll need to wait here until the AreaImport task to complete before making that decision.
113
114
    if (m_path.isEmpty())
115
        return String();
116
117
    ASSERT(origin);
118
    if (!origin)
119
        return String();
120
121
    if (!makeAllDirectories(m_path)) {
122
        LOG_ERROR("Unabled to create LocalStorage database path %s", m_path.utf8().data());
123
        return String();
124
    }
125
126
    return pathByAppendingComponent(m_path, origin->databaseIdentifier() + ".localstorage");
127
}
128
129
void LocalStorage::performImport()
130
{
131
    ASSERT(!isMainThread());
132
133
    // FIXME: Import all known local storage origins here along with their quotas
134
}
135
136
void LocalStorage::performSync()
137
{
138
    ASSERT(!isMainThread());
139
140
    // FIXME: Write out new origins and quotas here
141
}
142
143
void LocalStorage::close()
103
void LocalStorage::close()
144
{
104
{
145
    ASSERT(isMainThread());
105
    ASSERT(isMainThread());
Lines 147-174 void LocalStorage::close() WebCore/storage/LocalStorage.cpp_sec4
147
    LocalStorageAreaMap::iterator end = m_storageAreaMap.end();
107
    LocalStorageAreaMap::iterator end = m_storageAreaMap.end();
148
    for (LocalStorageAreaMap::iterator it = m_storageAreaMap.begin(); it != end; ++it)
108
    for (LocalStorageAreaMap::iterator it = m_storageAreaMap.begin(); it != end; ++it)
149
        it->second->scheduleFinalSync();
109
        it->second->scheduleFinalSync();
150
110
    
151
    if (m_thread) {
111
    m_syncManager = 0;
152
        m_thread->terminate();
153
        m_thread = 0;
154
    }
155
}
156
157
bool LocalStorage::scheduleImport(PassRefPtr<LocalStorageArea> area)
158
{
159
    ASSERT(isMainThread());
160
161
    if (m_thread)
162
        m_thread->scheduleImport(area);
163
164
    return m_thread;
165
}
166
167
void LocalStorage::scheduleSync(PassRefPtr<LocalStorageArea> area)
168
{
169
    ASSERT(isMainThread());
170
    if (m_thread)
171
        m_thread->scheduleSync(area);
172
}
112
}
173
113
174
} // namespace WebCore
114
} // namespace WebCore
- WebCore/storage/LocalStorage.h -23 / +4 lines
Lines 29-48 WebCore/storage/LocalStorage.h_sec1
29
#if ENABLE(DOM_STORAGE)
29
#if ENABLE(DOM_STORAGE)
30
30
31
#include "LocalStorageArea.h"
31
#include "LocalStorageArea.h"
32
#include "LocalStorageTask.h"
33
#include "LocalStorageThread.h"
34
#include "SecurityOriginHash.h"
32
#include "SecurityOriginHash.h"
35
33
36
#include <wtf/HashMap.h>
34
#include <wtf/HashMap.h>
37
#include <wtf/HashSet.h>
35
#include <wtf/RefCounted.h>
38
#include <wtf/Threading.h>
39
36
40
namespace WebCore {
37
namespace WebCore {
41
38
42
    class PageGroup;
43
    class StorageArea;
39
    class StorageArea;
40
    class StorageSyncManager;
44
41
45
    class LocalStorage : public ThreadSafeShared<LocalStorage> {
42
    class LocalStorage : public RefCounted<LocalStorage> {
46
    public:
43
    public:
47
        ~LocalStorage();
44
        ~LocalStorage();
48
45
Lines 50-58 namespace WebCore { WebCore/storage/LocalStorage.h_sec2
50
47
51
        PassRefPtr<StorageArea> storageArea(SecurityOrigin*);
48
        PassRefPtr<StorageArea> storageArea(SecurityOrigin*);
52
49
53
        bool scheduleImport(PassRefPtr<LocalStorageArea>);
54
        void scheduleSync(PassRefPtr<LocalStorageArea>);
55
56
        void close();
50
        void close();
57
51
58
    private:
52
    private:
Lines 61-81 namespace WebCore { WebCore/storage/LocalStorage.h_sec3
61
        typedef HashMap<RefPtr<SecurityOrigin>, RefPtr<LocalStorageArea>, SecurityOriginHash> LocalStorageAreaMap;
55
        typedef HashMap<RefPtr<SecurityOrigin>, RefPtr<LocalStorageArea>, SecurityOriginHash> LocalStorageAreaMap;
62
        LocalStorageAreaMap m_storageAreaMap;
56
        LocalStorageAreaMap m_storageAreaMap;
63
57
64
        RefPtr<LocalStorageThread> m_thread;
65
66
    // The following members are subject to thread synchronization issues
67
    public:
68
        // To be called from the background thread:
69
        String fullDatabaseFilename(SecurityOrigin*);
70
71
        void performImport();
72
        void performSync();
73
74
    private:
75
        String m_path;
58
        String m_path;
76
59
        RefPtr<StorageSyncManager> m_syncManager;
77
        typedef HashMap<RefPtr<SecurityOrigin>, unsigned long long, SecurityOriginHash> SecurityOriginQuoteMap;
78
        SecurityOriginQuoteMap m_securityOriginQuoteMap;
79
    };
60
    };
80
61
81
} // namespace WebCore
62
} // namespace WebCore
- WebCore/storage/LocalStorageArea.cpp -8 / +14 lines
Lines 46-64 namespace WebCore { WebCore/storage/LocalStorageArea.cpp_sec1
46
// Instead, queue up a batch of items to sync and actually do the sync at the following interval.
46
// Instead, queue up a batch of items to sync and actually do the sync at the following interval.
47
static const double LocalStorageSyncInterval = 1.0;
47
static const double LocalStorageSyncInterval = 1.0;
48
48
49
LocalStorageArea::LocalStorageArea(SecurityOrigin* origin, LocalStorage* localStorage)
49
LocalStorageArea::LocalStorageArea(SecurityOrigin* origin, PassRefPtr<StorageSyncManager> syncManager)
50
    : StorageArea(origin)
50
    : StorageArea(origin)
51
    , m_syncTimer(this, &LocalStorageArea::syncTimerFired)
51
    , m_syncTimer(this, &LocalStorageArea::syncTimerFired)
52
    , m_itemsCleared(false)
52
    , m_itemsCleared(false)
53
    , m_finalSyncScheduled(false)
53
    , m_finalSyncScheduled(false)
54
    , m_localStorage(localStorage)
54
    , m_syncManager(syncManager)
55
    , m_clearItemsWhileSyncing(false)
55
    , m_clearItemsWhileSyncing(false)
56
    , m_syncScheduled(false)
56
    , m_syncScheduled(false)
57
    , m_importComplete(false)
57
    , m_importComplete(false)
58
{
58
{
59
    ASSERT(m_localStorage);
59
    if (!m_syncManager || !m_syncManager->scheduleImport(this))
60
    
61
    if (!m_localStorage->scheduleImport(this))
62
        m_importComplete = true;
60
        m_importComplete = true;
63
}
61
}
64
62
Lines 69-74 LocalStorageArea::~LocalStorageArea() WebCore/storage/LocalStorageArea.cpp_sec2
69
67
70
void LocalStorageArea::scheduleFinalSync()
68
void LocalStorageArea::scheduleFinalSync()
71
{
69
{
70
    ASSERT(isMainThread());
71
    if (!m_syncManager)
72
        return;
73
    
72
    if (m_syncTimer.isActive())
74
    if (m_syncTimer.isActive())
73
        m_syncTimer.stop();
75
        m_syncTimer.stop();
74
    else {
76
    else {
Lines 269-274 void LocalStorageArea::scheduleClear() WebCore/storage/LocalStorageArea.cpp_sec3
269
void LocalStorageArea::syncTimerFired(Timer<LocalStorageArea>*)
271
void LocalStorageArea::syncTimerFired(Timer<LocalStorageArea>*)
270
{
272
{
271
    ASSERT(isMainThread());
273
    ASSERT(isMainThread());
274
    if (!m_syncManager)
275
        return;
272
276
273
    HashMap<String, String>::iterator it = m_changedItems.begin();
277
    HashMap<String, String>::iterator it = m_changedItems.begin();
274
    HashMap<String, String>::iterator end = m_changedItems.end();
278
    HashMap<String, String>::iterator end = m_changedItems.end();
Lines 292-298 void LocalStorageArea::syncTimerFired(Ti WebCore/storage/LocalStorageArea.cpp_sec4
292
            // performSync function.
296
            // performSync function.
293
            disableSuddenTermination();
297
            disableSuddenTermination();
294
298
295
            m_localStorage->scheduleSync(this);
299
            m_syncManager->scheduleSync(this);
296
        }
300
        }
297
    }
301
    }
298
302
Lines 307-315 void LocalStorageArea::performImport() WebCore/storage/LocalStorageArea.cpp_sec5
307
{
311
{
308
    ASSERT(!isMainThread());
312
    ASSERT(!isMainThread());
309
    ASSERT(!m_database.isOpen());
313
    ASSERT(!m_database.isOpen());
314
    if (!m_syncManager)
315
        return;
316
317
    String databaseFilename = m_syncManager->fullDatabaseFilename(securityOrigin());
310
318
311
    String databaseFilename = m_localStorage->fullDatabaseFilename(securityOrigin());
312
    
313
    if (databaseFilename.isEmpty()) {
319
    if (databaseFilename.isEmpty()) {
314
        LOG_ERROR("Filename for local storage database is empty - cannot open for persistent storage");
320
        LOG_ERROR("Filename for local storage database is empty - cannot open for persistent storage");
315
        markImported();
321
        markImported();
- WebCore/storage/LocalStorageArea.h -4 / +5 lines
Lines 31-53 WebCore/storage/LocalStorageArea.h_sec1
31
#include "SQLiteDatabase.h"
31
#include "SQLiteDatabase.h"
32
#include "StorageArea.h"
32
#include "StorageArea.h"
33
#include "StringHash.h"
33
#include "StringHash.h"
34
#include "StorageSyncManager.h"
34
#include "Timer.h"
35
#include "Timer.h"
35
#include <wtf/HashMap.h>
36
#include <wtf/HashMap.h>
36
37
37
namespace WebCore {
38
namespace WebCore {
38
    
39
    
39
    class LocalStorage;
40
    class StorageSyncManager;
40
    
41
    
41
    class LocalStorageArea : public StorageArea {
42
    class LocalStorageArea : public StorageArea {
42
    public:
43
    public:
43
        virtual ~LocalStorageArea();
44
        virtual ~LocalStorageArea();
44
45
45
        static PassRefPtr<LocalStorageArea> create(SecurityOrigin* origin, LocalStorage* localStorage) { return adoptRef(new LocalStorageArea(origin, localStorage)); }
46
        static PassRefPtr<LocalStorageArea> create(SecurityOrigin* origin, PassRefPtr<StorageSyncManager> syncManager) { return adoptRef(new LocalStorageArea(origin, syncManager)); }
46
47
47
        void scheduleFinalSync();
48
        void scheduleFinalSync();
48
49
49
    private:
50
    private:
50
        LocalStorageArea(SecurityOrigin*, LocalStorage*);
51
        LocalStorageArea(SecurityOrigin*, PassRefPtr<StorageSyncManager> syncManager);
51
52
52
        virtual void itemChanged(const String& key, const String& oldValue, const String& newValue, Frame* sourceFrame);
53
        virtual void itemChanged(const String& key, const String& oldValue, const String& newValue, Frame* sourceFrame);
53
        virtual void itemRemoved(const String& key, const String& oldValue, Frame* sourceFrame);
54
        virtual void itemRemoved(const String& key, const String& oldValue, Frame* sourceFrame);
Lines 63-69 namespace WebCore { WebCore/storage/LocalStorageArea.h_sec2
63
        
64
        
64
        bool m_finalSyncScheduled;
65
        bool m_finalSyncScheduled;
65
66
66
        LocalStorage* m_localStorage;
67
        RefPtr<StorageSyncManager> m_syncManager;
67
68
68
        // The database handle will only ever be opened and used on the background thread.
69
        // The database handle will only ever be opened and used on the background thread.
69
        SQLiteDatabase m_database;
70
        SQLiteDatabase m_database;
- WebCore/storage/LocalStorageTask.cpp -16 lines
Lines 42-55 LocalStorageTask::LocalStorageTask(Type WebCore/storage/LocalStorageTask.cpp_sec1
42
    ASSERT(m_type == AreaImport || m_type == AreaSync);
42
    ASSERT(m_type == AreaImport || m_type == AreaSync);
43
}
43
}
44
44
45
LocalStorageTask::LocalStorageTask(Type type, PassRefPtr<LocalStorage> storage)
46
    : m_type(type)
47
    , m_storage(storage)
48
{
49
    ASSERT(m_storage);
50
    ASSERT(m_type == StorageImport || m_type == StorageSync);
51
}
52
53
LocalStorageTask::LocalStorageTask(Type type, PassRefPtr<LocalStorageThread> thread)
45
LocalStorageTask::LocalStorageTask(Type type, PassRefPtr<LocalStorageThread> thread)
54
    : m_type(type)
46
    : m_type(type)
55
    , m_thread(thread)
47
    , m_thread(thread)
Lines 61-74 LocalStorageTask::LocalStorageTask(Type WebCore/storage/LocalStorageTask.cpp_sec2
61
void LocalStorageTask::performTask()
53
void LocalStorageTask::performTask()
62
{
54
{
63
    switch (m_type) {
55
    switch (m_type) {
64
        case StorageImport:
65
            ASSERT(m_storage);
66
            m_storage->performImport();
67
            break;
68
        case StorageSync:
69
            ASSERT(m_storage);
70
            m_storage->performSync();
71
            break;
72
        case AreaImport:
56
        case AreaImport:
73
            ASSERT(m_area);
57
            ASSERT(m_area);
74
            m_area->performImport();
58
            m_area->performImport();
- WebCore/storage/LocalStorageTask.h -6 / +1 lines
Lines 34-50 WebCore/storage/LocalStorageTask.h_sec1
34
34
35
namespace WebCore {
35
namespace WebCore {
36
36
37
    class LocalStorage;
38
    class LocalStorageArea;
37
    class LocalStorageArea;
39
    class LocalStorageThread;
38
    class LocalStorageThread;
40
39
41
    class LocalStorageTask : public ThreadSafeShared<LocalStorageTask> {
40
    class LocalStorageTask : public ThreadSafeShared<LocalStorageTask> {
42
    public:
41
    public:
43
        enum Type { StorageImport, StorageSync, AreaImport, AreaSync, TerminateThread };
42
        enum Type { AreaImport, AreaSync, TerminateThread };
44
43
45
        static PassRefPtr<LocalStorageTask> createImport(PassRefPtr<LocalStorage> storage) { return adoptRef(new LocalStorageTask(StorageImport, storage)); }
46
        static PassRefPtr<LocalStorageTask> createImport(PassRefPtr<LocalStorageArea> area) { return adoptRef(new LocalStorageTask(AreaImport, area)); }
44
        static PassRefPtr<LocalStorageTask> createImport(PassRefPtr<LocalStorageArea> area) { return adoptRef(new LocalStorageTask(AreaImport, area)); }
47
        static PassRefPtr<LocalStorageTask> createSync(PassRefPtr<LocalStorage> storage) { return adoptRef(new LocalStorageTask(StorageSync, storage)); }
48
        static PassRefPtr<LocalStorageTask> createSync(PassRefPtr<LocalStorageArea> area) { return adoptRef(new LocalStorageTask(AreaSync, area)); }
45
        static PassRefPtr<LocalStorageTask> createSync(PassRefPtr<LocalStorageArea> area) { return adoptRef(new LocalStorageTask(AreaSync, area)); }
49
        static PassRefPtr<LocalStorageTask> createTerminate(PassRefPtr<LocalStorageThread> thread) { return adoptRef(new LocalStorageTask(TerminateThread, thread)); }
46
        static PassRefPtr<LocalStorageTask> createTerminate(PassRefPtr<LocalStorageThread> thread) { return adoptRef(new LocalStorageTask(TerminateThread, thread)); }
50
47
Lines 52-63 namespace WebCore { WebCore/storage/LocalStorageTask.h_sec2
52
49
53
    private:
50
    private:
54
        LocalStorageTask(Type, PassRefPtr<LocalStorageArea>);
51
        LocalStorageTask(Type, PassRefPtr<LocalStorageArea>);
55
        LocalStorageTask(Type, PassRefPtr<LocalStorage>);
56
        LocalStorageTask(Type, PassRefPtr<LocalStorageThread>);
52
        LocalStorageTask(Type, PassRefPtr<LocalStorageThread>);
57
53
58
        Type m_type;
54
        Type m_type;
59
        RefPtr<LocalStorageArea> m_area;
55
        RefPtr<LocalStorageArea> m_area;
60
        RefPtr<LocalStorage> m_storage;
61
        RefPtr<LocalStorageThread> m_thread;
56
        RefPtr<LocalStorageThread> m_thread;
62
    };
57
    };
63
58
- WebCore/storage/LocalStorageThread.cpp -12 lines
Lines 87-104 void* LocalStorageThread::localStorageTh WebCore/storage/LocalStorageThread.cpp_sec1
87
    return 0;
87
    return 0;
88
}
88
}
89
89
90
void LocalStorageThread::scheduleImport(PassRefPtr<LocalStorage> storage)
91
{
92
    ASSERT(!m_queue.killed() && m_threadID);
93
    m_queue.append(LocalStorageTask::createImport(storage));
94
}
95
96
void LocalStorageThread::scheduleSync(PassRefPtr<LocalStorage> storage)
97
{
98
    ASSERT(!m_queue.killed() && m_threadID);
99
    m_queue.append(LocalStorageTask::createSync(storage));
100
}
101
102
void LocalStorageThread::scheduleImport(PassRefPtr<LocalStorageArea> area)
90
void LocalStorageThread::scheduleImport(PassRefPtr<LocalStorageArea> area)
103
{
91
{
104
    ASSERT(!m_queue.killed() && m_threadID);
92
    ASSERT(!m_queue.killed() && m_threadID);
- WebCore/storage/LocalStorageThread.h -3 lines
Lines 35-41 WebCore/storage/LocalStorageThread.h_sec1
35
35
36
namespace WebCore {
36
namespace WebCore {
37
37
38
    class LocalStorage;
39
    class LocalStorageArea;
38
    class LocalStorageArea;
40
    class LocalStorageTask;
39
    class LocalStorageTask;
41
40
Lines 45-52 namespace WebCore { WebCore/storage/LocalStorageThread.h_sec2
45
44
46
        bool start();
45
        bool start();
47
46
48
        void scheduleImport(PassRefPtr<LocalStorage>);
49
        void scheduleSync(PassRefPtr<LocalStorage>);
50
        void scheduleImport(PassRefPtr<LocalStorageArea>);
47
        void scheduleImport(PassRefPtr<LocalStorageArea>);
51
        void scheduleSync(PassRefPtr<LocalStorageArea>);
48
        void scheduleSync(PassRefPtr<LocalStorageArea>);
52
49
- WebCore/storage/SessionStorage.h -1 lines
Lines 32-38 WebCore/storage/SessionStorage.h_sec1
32
#include "SessionStorageArea.h"
32
#include "SessionStorageArea.h"
33
33
34
#include <wtf/HashMap.h>
34
#include <wtf/HashMap.h>
35
#include <wtf/HashSet.h>
36
#include <wtf/RefCounted.h>
35
#include <wtf/RefCounted.h>
37
36
38
namespace WebCore {
37
namespace WebCore {
- WebCore/storage/StorageSyncManager.cpp +177 lines
Line 0 WebCore/storage/StorageSyncManager.cpp_sec1
1
/*
2
 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24
 */
25
26
#include "config.h"
27
#include "LocalStorage.h"
28
29
#if ENABLE(DOM_STORAGE)
30
31
#include "CString.h"
32
#include "EventNames.h"
33
#include "FileSystem.h"
34
#include "Frame.h"
35
#include "FrameTree.h"
36
#include "LocalStorageArea.h"
37
#include "Page.h"
38
#include "PageGroup.h"
39
#include "StorageArea.h"
40
#include <wtf/StdLibExtras.h>
41
42
namespace WebCore {
43
44
typedef HashMap<String, LocalStorage*> LocalStorageMap;
45
46
static LocalStorageMap& localStorageMap()
47
{
48
    DEFINE_STATIC_LOCAL(LocalStorageMap, localStorageMap, ());
49
    return localStorageMap;
50
}
51
52
PassRefPtr<LocalStorage> LocalStorage::localStorage(const String& path)
53
{
54
    const String lookupPath = path.isNull() ? String("") : path;
55
    LocalStorageMap::iterator it = localStorageMap().find(lookupPath);
56
    if (it == localStorageMap().end()) {
57
        RefPtr<LocalStorage> localStorage = adoptRef(new LocalStorage(lookupPath));
58
        localStorageMap().set(lookupPath, localStorage.get());
59
        return localStorage.release();
60
    }
61
    
62
    return it->second;
63
}
64
65
LocalStorage::LocalStorage(const String& path)
66
    : m_path(path.copy())
67
{
68
    // If the path is empty, we know we're never going to be using the thread for anything, so don't start it.
69
    // In the future, we might also want to consider removing it from the DOM in that case - <rdar://problem/5960470>
70
    if (path.isEmpty())
71
        return;
72
73
    m_thread = LocalStorageThread::create();
74
    m_thread->start();
75
    m_thread->scheduleImport(this);
76
}
77
78
LocalStorage::~LocalStorage()
79
{
80
    ASSERT(localStorageMap().get(m_path) == this);
81
    localStorageMap().remove(m_path);
82
}
83
84
PassRefPtr<StorageArea> LocalStorage::storageArea(SecurityOrigin* origin)
85
{
86
    ASSERT(isMainThread());
87
88
    // FIXME: If the security origin in question has never had a storage area established,
89
    // we need to ask a client call if establishing it is okay.  If the client denies the request,
90
    // this method will return null.
91
    // The sourceFrame argument exists for the purpose of asking a client.
92
    // To know if an area has previously been established, we need to wait until this LocalStorage 
93
    // object has finished it's AreaImport task.
94
95
96
    // FIXME: If the storage area is being established for the first time here, we need to 
97
    // sync its existance and quota out to disk via an task of type AreaSync
98
99
    RefPtr<LocalStorageArea> storageArea;
100
    if (storageArea = m_storageAreaMap.get(origin))
101
        return storageArea.release();
102
        
103
    storageArea = LocalStorageArea::create(origin, this);
104
    m_storageAreaMap.set(origin, storageArea);
105
    return storageArea.release();
106
}
107
108
String LocalStorage::fullDatabaseFilename(SecurityOrigin* origin)
109
{
110
    // FIXME: Once we actually track origin/quota entries to see which origins have local storage established,
111
    // we will return an empty path name if the origin isn't allowed to have LocalStorage.
112
    // We'll need to wait here until the AreaImport task to complete before making that decision.
113
114
    if (m_path.isEmpty())
115
        return String();
116
117
    ASSERT(origin);
118
    if (!origin)
119
        return String();
120
121
    if (!makeAllDirectories(m_path)) {
122
        LOG_ERROR("Unabled to create LocalStorage database path %s", m_path.utf8().data());
123
        return String();
124
    }
125
126
    return pathByAppendingComponent(m_path, origin->databaseIdentifier() + ".localstorage");
127
}
128
129
void LocalStorage::performImport()
130
{
131
    ASSERT(!isMainThread());
132
133
    // FIXME: Import all known local storage origins here along with their quotas
134
}
135
136
void LocalStorage::performSync()
137
{
138
    ASSERT(!isMainThread());
139
140
    // FIXME: Write out new origins and quotas here
141
}
142
143
void LocalStorage::close()
144
{
145
    ASSERT(isMainThread());
146
147
    LocalStorageAreaMap::iterator end = m_storageAreaMap.end();
148
    for (LocalStorageAreaMap::iterator it = m_storageAreaMap.begin(); it != end; ++it)
149
        it->second->scheduleFinalSync();
150
151
    if (m_thread) {
152
        m_thread->terminate();
153
        m_thread = 0;
154
    }
155
}
156
157
bool LocalStorage::scheduleImport(PassRefPtr<LocalStorageArea> area)
158
{
159
    ASSERT(isMainThread());
160
161
    if (m_thread)
162
        m_thread->scheduleImport(area);
163
164
    return m_thread;
165
}
166
167
void LocalStorage::scheduleSync(PassRefPtr<LocalStorageArea> area)
168
{
169
    ASSERT(isMainThread());
170
    if (m_thread)
171
        m_thread->scheduleSync(area);
172
}
173
174
} // namespace WebCore
175
176
#endif // ENABLE(DOM_STORAGE)
177
- WebCore/storage/StorageSyncManager.cpp -94 / +12 lines
Lines 24-39 WebCore/storage/StorageSyncManager.cpp_sec1
24
 */
24
 */
25
25
26
#include "config.h"
26
#include "config.h"
27
#include "LocalStorage.h"
27
#include "StorageSyncManager.h"
28
29
#if ENABLE(DOM_STORAGE)
30
28
31
#include "CString.h"
29
#include "CString.h"
32
#include "EventNames.h"
30
#include "EventNames.h"
33
#include "FileSystem.h"
31
#include "FileSystem.h"
34
#include "Frame.h"
32
#include "Frame.h"
35
#include "FrameTree.h"
33
#include "FrameTree.h"
36
#include "LocalStorageArea.h"
37
#include "Page.h"
34
#include "Page.h"
38
#include "PageGroup.h"
35
#include "PageGroup.h"
39
#include "StorageArea.h"
36
#include "StorageArea.h"
Lines 41-122 WebCore/storage/StorageSyncManager.cpp_sec2
41
38
42
namespace WebCore {
39
namespace WebCore {
43
40
44
typedef HashMap<String, LocalStorage*> LocalStorageMap;
41
PassRefPtr<StorageSyncManager> StorageSyncManager::create(const String& path)
45
46
static LocalStorageMap& localStorageMap()
47
{
48
    DEFINE_STATIC_LOCAL(LocalStorageMap, localStorageMap, ());
49
    return localStorageMap;
50
}
51
52
PassRefPtr<LocalStorage> LocalStorage::localStorage(const String& path)
53
{
42
{
54
    const String lookupPath = path.isNull() ? String("") : path;
43
    return adoptRef(new StorageSyncManager(path));
55
    LocalStorageMap::iterator it = localStorageMap().find(lookupPath);
56
    if (it == localStorageMap().end()) {
57
        RefPtr<LocalStorage> localStorage = adoptRef(new LocalStorage(lookupPath));
58
        localStorageMap().set(lookupPath, localStorage.get());
59
        return localStorage.release();
60
    }
61
    
62
    return it->second;
63
}
44
}
64
45
65
LocalStorage::LocalStorage(const String& path)
46
StorageSyncManager::StorageSyncManager(const String& path)
66
    : m_path(path.copy())
47
    : m_path(path.copy())
67
{
48
{
68
    // If the path is empty, we know we're never going to be using the thread for anything, so don't start it.
49
    ASSERT(!m_path.isEmpty());
69
    // In the future, we might also want to consider removing it from the DOM in that case - <rdar://problem/5960470>
70
    if (path.isEmpty())
71
        return;
72
50
73
    m_thread = LocalStorageThread::create();
51
    m_thread = LocalStorageThread::create();
74
    m_thread->start();
52
    m_thread->start();
75
    m_thread->scheduleImport(this);
76
}
77
78
LocalStorage::~LocalStorage()
79
{
80
    ASSERT(localStorageMap().get(m_path) == this);
81
    localStorageMap().remove(m_path);
82
}
53
}
83
54
84
PassRefPtr<StorageArea> LocalStorage::storageArea(SecurityOrigin* origin)
55
String StorageSyncManager::fullDatabaseFilename(SecurityOrigin* origin)
85
{
56
{
86
    ASSERT(isMainThread());
87
88
    // FIXME: If the security origin in question has never had a storage area established,
89
    // we need to ask a client call if establishing it is okay.  If the client denies the request,
90
    // this method will return null.
91
    // The sourceFrame argument exists for the purpose of asking a client.
92
    // To know if an area has previously been established, we need to wait until this LocalStorage 
93
    // object has finished it's AreaImport task.
94
95
96
    // FIXME: If the storage area is being established for the first time here, we need to 
97
    // sync its existance and quota out to disk via an task of type AreaSync
98
99
    RefPtr<LocalStorageArea> storageArea;
100
    if (storageArea = m_storageAreaMap.get(origin))
101
        return storageArea.release();
102
        
103
    storageArea = LocalStorageArea::create(origin, this);
104
    m_storageAreaMap.set(origin, storageArea);
105
    return storageArea.release();
106
}
107
108
String LocalStorage::fullDatabaseFilename(SecurityOrigin* origin)
109
{
110
    // FIXME: Once we actually track origin/quota entries to see which origins have local storage established,
111
    // we will return an empty path name if the origin isn't allowed to have LocalStorage.
112
    // We'll need to wait here until the AreaImport task to complete before making that decision.
113
114
    if (m_path.isEmpty())
115
        return String();
116
117
    ASSERT(origin);
57
    ASSERT(origin);
118
    if (!origin)
119
        return String();
120
58
121
    if (!makeAllDirectories(m_path)) {
59
    if (!makeAllDirectories(m_path)) {
122
        LOG_ERROR("Unabled to create LocalStorage database path %s", m_path.utf8().data());
60
        LOG_ERROR("Unabled to create LocalStorage database path %s", m_path.utf8().data());
Lines 126-177 String LocalStorage::fullDatabaseFilenam WebCore/storage/StorageSyncManager.cpp_sec3
126
    return pathByAppendingComponent(m_path, origin->databaseIdentifier() + ".localstorage");
64
    return pathByAppendingComponent(m_path, origin->databaseIdentifier() + ".localstorage");
127
}
65
}
128
66
129
void LocalStorage::performImport()
67
void StorageSyncManager::close()
130
{
131
    ASSERT(!isMainThread());
132
133
    // FIXME: Import all known local storage origins here along with their quotas
134
}
135
136
void LocalStorage::performSync()
137
{
138
    ASSERT(!isMainThread());
139
140
    // FIXME: Write out new origins and quotas here
141
}
142
143
void LocalStorage::close()
144
{
68
{
145
    ASSERT(isMainThread());
69
    ASSERT(isMainThread());
146
70
    
147
    LocalStorageAreaMap::iterator end = m_storageAreaMap.end();
148
    for (LocalStorageAreaMap::iterator it = m_storageAreaMap.begin(); it != end; ++it)
149
        it->second->scheduleFinalSync();
150
151
    if (m_thread) {
71
    if (m_thread) {
152
        m_thread->terminate();
72
        m_thread->terminate();
153
        m_thread = 0;
73
        m_thread = 0;
154
    }
74
    }
155
}
75
}
156
76
157
bool LocalStorage::scheduleImport(PassRefPtr<LocalStorageArea> area)
77
bool StorageSyncManager::scheduleImport(PassRefPtr<LocalStorageArea> area)
158
{
78
{
159
    ASSERT(isMainThread());
79
    ASSERT(isMainThread());
160
80
    
161
    if (m_thread)
81
    if (m_thread)
162
        m_thread->scheduleImport(area);
82
        m_thread->scheduleImport(area);
163
83
164
    return m_thread;
84
    return m_thread;
165
}
85
}
166
86
167
void LocalStorage::scheduleSync(PassRefPtr<LocalStorageArea> area)
87
void StorageSyncManager::scheduleSync(PassRefPtr<LocalStorageArea> area)
168
{
88
{
169
    ASSERT(isMainThread());
89
    ASSERT(isMainThread());
90
    
170
    if (m_thread)
91
    if (m_thread)
171
        m_thread->scheduleSync(area);
92
        m_thread->scheduleSync(area);
172
}
93
}
173
94
174
} // namespace WebCore
95
} // namespace WebCore
175
176
#endif // ENABLE(DOM_STORAGE)
177
- WebCore/storage/StorageSyncManager.h +85 lines
Line 0 WebCore/storage/StorageSyncManager.h_sec1
1
/*
2
 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24
 */
25
26
#ifndef LocalStorage_h
27
#define LocalStorage_h
28
29
#if ENABLE(DOM_STORAGE)
30
31
#include "LocalStorageArea.h"
32
#include "LocalStorageTask.h"
33
#include "LocalStorageThread.h"
34
#include "SecurityOriginHash.h"
35
36
#include <wtf/HashMap.h>
37
#include <wtf/HashSet.h>
38
#include <wtf/Threading.h>
39
40
namespace WebCore {
41
42
    class PageGroup;
43
    class StorageArea;
44
45
    class LocalStorage : public ThreadSafeShared<LocalStorage> {
46
    public:
47
        ~LocalStorage();
48
49
        static PassRefPtr<LocalStorage> localStorage(const String& path);
50
51
        PassRefPtr<StorageArea> storageArea(SecurityOrigin*);
52
53
        bool scheduleImport(PassRefPtr<LocalStorageArea>);
54
        void scheduleSync(PassRefPtr<LocalStorageArea>);
55
56
        void close();
57
58
    private:
59
        LocalStorage(const String& path);
60
61
        typedef HashMap<RefPtr<SecurityOrigin>, RefPtr<LocalStorageArea>, SecurityOriginHash> LocalStorageAreaMap;
62
        LocalStorageAreaMap m_storageAreaMap;
63
64
        RefPtr<LocalStorageThread> m_thread;
65
66
    // The following members are subject to thread synchronization issues
67
    public:
68
        // To be called from the background thread:
69
        String fullDatabaseFilename(SecurityOrigin*);
70
71
        void performImport();
72
        void performSync();
73
74
    private:
75
        String m_path;
76
77
        typedef HashMap<RefPtr<SecurityOrigin>, unsigned long long, SecurityOriginHash> SecurityOriginQuoteMap;
78
        SecurityOriginQuoteMap m_securityOriginQuoteMap;
79
    };
80
81
} // namespace WebCore
82
83
#endif // ENABLE(DOM_STORAGE)
84
85
#endif // LocalStorage_h
- WebCore/storage/StorageSyncManager.h -29 / +6 lines
Lines 23-54 WebCore/storage/StorageSyncManager.h_sec1
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
23
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
24
 */
24
 */
25
25
26
#ifndef LocalStorage_h
26
#ifndef StorageSyncManager_h
27
#define LocalStorage_h
27
#define StorageSyncManager_h
28
29
#if ENABLE(DOM_STORAGE)
30
28
31
#include "LocalStorageArea.h"
29
#include "LocalStorageArea.h"
32
#include "LocalStorageTask.h"
30
#include "LocalStorageTask.h"
33
#include "LocalStorageThread.h"
31
#include "LocalStorageThread.h"
34
#include "SecurityOriginHash.h"
35
32
36
#include <wtf/HashMap.h>
37
#include <wtf/HashSet.h>
38
#include <wtf/Threading.h>
33
#include <wtf/Threading.h>
39
34
40
namespace WebCore {
35
namespace WebCore {
41
36
42
    class PageGroup;
37
    class StorageSyncManager: public ThreadSafeShared<StorageSyncManager> {
43
    class StorageArea;
44
45
    class LocalStorage : public ThreadSafeShared<LocalStorage> {
46
    public:
38
    public:
47
        ~LocalStorage();
39
        static PassRefPtr<StorageSyncManager> create(const String& path);
48
49
        static PassRefPtr<LocalStorage> localStorage(const String& path);
50
51
        PassRefPtr<StorageArea> storageArea(SecurityOrigin*);
52
40
53
        bool scheduleImport(PassRefPtr<LocalStorageArea>);
41
        bool scheduleImport(PassRefPtr<LocalStorageArea>);
54
        void scheduleSync(PassRefPtr<LocalStorageArea>);
42
        void scheduleSync(PassRefPtr<LocalStorageArea>);
Lines 56-65 namespace WebCore { WebCore/storage/StorageSyncManager.h_sec2
56
        void close();
44
        void close();
57
45
58
    private:
46
    private:
59
        LocalStorage(const String& path);
47
        StorageSyncManager(const String& path);
60
61
        typedef HashMap<RefPtr<SecurityOrigin>, RefPtr<LocalStorageArea>, SecurityOriginHash> LocalStorageAreaMap;
62
        LocalStorageAreaMap m_storageAreaMap;
63
48
64
        RefPtr<LocalStorageThread> m_thread;
49
        RefPtr<LocalStorageThread> m_thread;
65
50
Lines 68-85 namespace WebCore { WebCore/storage/StorageSyncManager.h_sec3
68
        // To be called from the background thread:
53
        // To be called from the background thread:
69
        String fullDatabaseFilename(SecurityOrigin*);
54
        String fullDatabaseFilename(SecurityOrigin*);
70
55
71
        void performImport();
72
        void performSync();
73
74
    private:
56
    private:
75
        String m_path;
57
        String m_path;
76
77
        typedef HashMap<RefPtr<SecurityOrigin>, unsigned long long, SecurityOriginHash> SecurityOriginQuoteMap;
78
        SecurityOriginQuoteMap m_securityOriginQuoteMap;
79
    };
58
    };
80
59
81
} // namespace WebCore
60
} // namespace WebCore
82
61
83
#endif // ENABLE(DOM_STORAGE)
62
#endif // StorageSyncManager_h
84
85
#endif // LocalStorage_h

Return to Bug 25376