Remove std::chrono completely
[WebKit.git] / Source / WebKit / UIProcess / WebStorage / StorageManager.h
1 /*
2  * Copyright (C) 2013 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. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #pragma once
27
28 #include "Connection.h"
29 #include "LocalStorageDatabaseTracker.h"
30 #include <WebCore/SecurityOriginData.h>
31 #include <WebCore/SecurityOriginHash.h>
32 #include <wtf/Forward.h>
33 #include <wtf/Function.h>
34 #include <wtf/HashSet.h>
35 #include <wtf/ThreadSafeRefCounted.h>
36 #include <wtf/text/StringHash.h>
37
38 namespace WebCore {
39 class SecurityOrigin;
40 }
41
42 namespace WebKit {
43
44 class LocalStorageDatabaseTracker;
45 class WebProcessProxy;
46
47 class StorageManager : public IPC::Connection::WorkQueueMessageReceiver {
48 public:
49     static Ref<StorageManager> create(const String& localStorageDirectory);
50     ~StorageManager();
51
52     void createSessionStorageNamespace(uint64_t storageNamespaceID, unsigned quotaInBytes);
53     void destroySessionStorageNamespace(uint64_t storageNamespaceID);
54     void setAllowedSessionStorageNamespaceConnection(uint64_t storageNamespaceID, IPC::Connection* allowedConnection);
55     void cloneSessionStorageNamespace(uint64_t storageNamespaceID, uint64_t newStorageNamespaceID);
56
57     void processWillOpenConnection(WebProcessProxy&, IPC::Connection&);
58     void processDidCloseConnection(WebProcessProxy&, IPC::Connection&);
59     void applicationWillTerminate();
60
61     void getSessionStorageOrigins(Function<void(HashSet<WebCore::SecurityOriginData>&&)>&& completionHandler);
62     void deleteSessionStorageOrigins(Function<void()>&& completionHandler);
63     void deleteSessionStorageEntriesForOrigins(const Vector<WebCore::SecurityOriginData>&, Function<void()>&& completionHandler);
64
65     void getLocalStorageOrigins(Function<void(HashSet<WebCore::SecurityOriginData>&&)>&& completionHandler);
66     void deleteLocalStorageEntriesForOrigin(WebCore::SecurityOriginData&&);
67
68     void deleteLocalStorageOriginsModifiedSince(WallTime, Function<void()>&& completionHandler);
69     void deleteLocalStorageEntriesForOrigins(const Vector<WebCore::SecurityOriginData>&, Function<void()>&& completionHandler);
70
71     void getLocalStorageOriginDetails(Function<void(Vector<LocalStorageDatabaseTracker::OriginDetails>)>&& completionHandler);
72
73 private:
74     explicit StorageManager(const String& localStorageDirectory);
75
76     // IPC::Connection::WorkQueueMessageReceiver.
77     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
78     void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>& replyEncoder) override;
79
80     // Message handlers.
81     void createLocalStorageMap(IPC::Connection&, uint64_t storageMapID, uint64_t storageNamespaceID, WebCore::SecurityOriginData&&);
82     void createTransientLocalStorageMap(IPC::Connection&, uint64_t storageMapID, uint64_t storageNamespaceID, WebCore::SecurityOriginData&& topLevelOriginData, WebCore::SecurityOriginData&&);
83     void createSessionStorageMap(IPC::Connection&, uint64_t storageMapID, uint64_t storageNamespaceID, WebCore::SecurityOriginData&&);
84     void destroyStorageMap(IPC::Connection&, uint64_t storageMapID);
85
86     void getValues(IPC::Connection&, uint64_t storageMapID, uint64_t storageMapSeed, HashMap<String, String>& values);
87     void setItem(IPC::Connection&, uint64_t storageAreaID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, const String& key, const String& value, const String& urlString);
88     void removeItem(IPC::Connection&, uint64_t storageMapID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, const String& key, const String& urlString);
89     void clear(IPC::Connection&, uint64_t storageMapID, uint64_t sourceStorageAreaID, uint64_t storageMapSeed, const String& urlString);
90
91     class StorageArea;
92     StorageArea* findStorageArea(IPC::Connection&, uint64_t) const;
93
94     class LocalStorageNamespace;
95     LocalStorageNamespace* getOrCreateLocalStorageNamespace(uint64_t storageNamespaceID);
96
97     class TransientLocalStorageNamespace;
98     TransientLocalStorageNamespace* getOrCreateTransientLocalStorageNamespace(uint64_t storageNamespaceID, WebCore::SecurityOriginData&& topLevelOrigin);
99
100     Ref<WorkQueue> m_queue;
101
102     Ref<LocalStorageDatabaseTracker> m_localStorageDatabaseTracker;
103     HashMap<uint64_t, RefPtr<LocalStorageNamespace>> m_localStorageNamespaces;
104
105     HashMap<std::pair<uint64_t, WebCore::SecurityOriginData>, RefPtr<TransientLocalStorageNamespace>> m_transientLocalStorageNamespaces;
106
107     class SessionStorageNamespace;
108     HashMap<uint64_t, RefPtr<SessionStorageNamespace>> m_sessionStorageNamespaces;
109
110     HashMap<std::pair<RefPtr<IPC::Connection>, uint64_t>, RefPtr<StorageArea>> m_storageAreasByConnection;
111 };
112
113 } // namespace WebKit