Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 45a97b5

Browse files
committed
Bug 1654080 - Use PBackground for syncing SessionStorageCache and use LSWriteOptimizer to send data changes; r=dom-workers-and-storage-reviewers,janv,nika
This patch does: - Use LSWriteOptimizer - Remove SessionStorageService since it's unused. - Move IPC from PContent to PBackground (by SessionStorageManager{Child, Parent} and SessionStorageCache{Child, Parent}). - Extract SessionStorageManagerBase and add PBackgroundSessionStorageManager. - Expose a getter function to get a BackgroundParentManager for top context id on the parent. IPC - Before this patch: - Copy from parent while loading a document. - Mark cache entry on the parent process as loaded by the child id. - Update change on checkpoint. - Unmark cache entry on the parent process as unloaded for the child id while the parent actor is destorying. - After this patch: - Sync IPC load in the first SessionStorage operation. - Update change on checkpoint `BackgroundSessionStorageManager`'s lifecycle on the parent process. - Create by `SessionStorageManagerParent` and register to the `sManagers`. - Hold by `SessionStorageManagerParent` and `sManagers`. - Remove from the `sManagers` while the corresponding `BrowsingContext` is destructed (on the parent process). Depends on D89341 Differential Revision: https://phabricator.services.mozilla.com/D89342
1 parent 4ca9a50 commit 45a97b5

32 files changed

Lines changed: 1382 additions & 439 deletions

docshell/base/CanonicalBrowsingContext.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "mozilla/dom/MediaControlService.h"
2121
#include "mozilla/dom/ContentPlaybackController.h"
2222
#include "mozilla/dom/SessionHistoryEntry.h"
23+
#include "mozilla/dom/SessionStorageManager.h"
2324
#include "mozilla/ipc/ProtocolUtils.h"
2425
#include "mozilla/net/DocumentLoadListener.h"
2526
#include "mozilla/NullPrincipal.h"
@@ -744,6 +745,10 @@ void CanonicalBrowsingContext::CanonicalDiscard() {
744745
mTabMediaController->Shutdown();
745746
mTabMediaController = nullptr;
746747
}
748+
749+
if (IsTop()) {
750+
BackgroundSessionStorageManager::RemoveManager(Id());
751+
}
747752
}
748753

749754
void CanonicalBrowsingContext::NotifyStartDelayedAutoplayMedia() {

dom/gamepad/ipc/GamepadEventChannelChild.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
66
#include "mozilla/dom/PGamepadEventChannelChild.h"
7+
#include "nsRefPtrHashtable.h"
78

89
#ifndef mozilla_dom_GamepadEventChannelChild_h_
910
# define mozilla_dom_GamepadEventChannelChild_h_

dom/ipc/ContentChild.cpp

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3538,20 +3538,6 @@ mozilla::ipc::IPCResult ContentChild::RecvUpdateMediaControlAction(
35383538
return IPC_OK();
35393539
}
35403540

3541-
mozilla::ipc::IPCResult ContentChild::RecvSessionStorageData(
3542-
const uint64_t aTopContextId, const nsACString& aOriginAttrs,
3543-
const nsACString& aOriginKey, const nsTArray<KeyValuePair>& aDefaultData,
3544-
const nsTArray<KeyValuePair>& aSessionData) {
3545-
if (const RefPtr<BrowsingContext> topContext =
3546-
BrowsingContext::Get(aTopContextId)) {
3547-
topContext->GetSessionStorageManager()->LoadSessionStorageData(
3548-
nullptr, aOriginAttrs, aOriginKey, aDefaultData, aSessionData);
3549-
} else {
3550-
NS_WARNING("Got session storage data for a discarded session");
3551-
}
3552-
return IPC_OK();
3553-
}
3554-
35553541
mozilla::ipc::IPCResult ContentChild::RecvOnAllowAccessFor(
35563542
const MaybeDiscarded<BrowsingContext>& aContext,
35573543
const nsCString& aTrackingOrigin, uint32_t aCookieBehavior,

dom/ipc/ContentChild.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -649,11 +649,6 @@ class ContentChild final : public PContentChild,
649649
return mBrowsingContextFieldEpoch;
650650
}
651651

652-
mozilla::ipc::IPCResult RecvSessionStorageData(
653-
uint64_t aTopContextId, const nsACString& aOriginAttrs,
654-
const nsACString& aOriginKey, const nsTArray<KeyValuePair>& aDefaultData,
655-
const nsTArray<KeyValuePair>& aSessionData);
656-
657652
mozilla::ipc::IPCResult RecvOnAllowAccessFor(
658653
const MaybeDiscarded<BrowsingContext>& aContext,
659654
const nsCString& aTrackingOrigin, uint32_t aCookieBehavior,

dom/ipc/ContentParent.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5818,11 +5818,6 @@ nsresult ContentParent::AboutToLoadHttpFtpDocumentForChild(
58185818
rv = loadInfo->GetTargetBrowsingContext(getter_AddRefs(browsingContext));
58195819
NS_ENSURE_SUCCESS(rv, rv);
58205820

5821-
if (browsingContext && !browsingContext->IsDiscarded()) {
5822-
browsingContext->GetSessionStorageManager()
5823-
->SendSessionStorageDataToContentProcess(this, principal);
5824-
}
5825-
58265821
if (!NextGenLocalStorageEnabled()) {
58275822
return NS_OK;
58285823
}
@@ -6404,20 +6399,6 @@ mozilla::ipc::IPCResult ContentParent::RecvGetModulesTrust(
64046399
#endif // defined(XP_WIN)
64056400
}
64066401

6407-
mozilla::ipc::IPCResult ContentParent::RecvSessionStorageData(
6408-
const uint64_t aTopContextId, const nsACString& aOriginAttrs,
6409-
const nsACString& aOriginKey, const nsTArray<KeyValuePair>& aDefaultData,
6410-
const nsTArray<KeyValuePair>& aSessionData) {
6411-
if (const RefPtr<BrowsingContext> topContext =
6412-
BrowsingContext::Get(aTopContextId)) {
6413-
topContext->GetSessionStorageManager()->LoadSessionStorageData(
6414-
this, aOriginAttrs, aOriginKey, aDefaultData, aSessionData);
6415-
} else {
6416-
NS_WARNING("Got session storage data for a discarded session");
6417-
}
6418-
return IPC_OK();
6419-
}
6420-
64216402
mozilla::ipc::IPCResult ContentParent::RecvCreateBrowsingContext(
64226403
uint64_t aGroupId, BrowsingContext::IPCInitializer&& aInit) {
64236404
RefPtr<WindowGlobalParent> parent;

dom/ipc/ContentParent.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,11 +1321,6 @@ class ContentParent final
13211321
ModulePaths&& aModPaths, bool aRunAtNormalPriority,
13221322
GetModulesTrustResolver&& aResolver);
13231323

1324-
mozilla::ipc::IPCResult RecvSessionStorageData(
1325-
uint64_t aTopContextId, const nsACString& aOriginAttrs,
1326-
const nsACString& aOriginKey, const nsTArray<KeyValuePair>& aDefaultData,
1327-
const nsTArray<KeyValuePair>& aSessionData);
1328-
13291324
mozilla::ipc::IPCResult RecvReportServiceWorkerShutdownProgress(
13301325
uint32_t aShutdownStateId,
13311326
ServiceWorkerShutdownState::Progress aProgress);

dom/ipc/PContent.ipdl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,6 @@ struct PostMessageData
365365
uint64_t innerWindowId;
366366
};
367367

368-
struct KeyValuePair
369-
{
370-
nsString key;
371-
nsString value;
372-
};
373-
374368
union SyncedContextInitializer
375369
{
376370
BrowsingContextInitializer;
@@ -1790,13 +1784,6 @@ both:
17901784
ClonedOrErrorMessageData aMessage,
17911785
PostMessageData aData);
17921786

1793-
/**
1794-
* Move sessionStorage data between parent and content processes. See
1795-
* SessionStorageManager documentation for more details.
1796-
*/
1797-
async SessionStorageData(uint64_t aTopContextId, nsCString aOriginAttrs,
1798-
nsCString aOriginKey, KeyValuePair[] aDefaultData,
1799-
KeyValuePair[] aSessionData);
18001787
async CommitWindowContextTransaction(MaybeDiscardedWindowContext aContext,
18011788
WindowContextTransaction aTransaction,
18021789
uint64_t aEpoch);

dom/localstorage/ActorsParent.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include "mozilla/dom/ContentParent.h"
2222
#include "mozilla/dom/ClientManagerService.h"
2323
#include "mozilla/dom/FlippedOnce.h"
24-
#include "mozilla/dom/LSWriteOptimizer.h"
24+
#include "mozilla/dom/LSWriteOptimizerImpl.h"
2525
#include "mozilla/dom/PBackgroundLSDatabaseParent.h"
2626
#include "mozilla/dom/PBackgroundLSObserverParent.h"
2727
#include "mozilla/dom/PBackgroundLSRequestParent.h"

dom/localstorage/LSSnapshot.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include "ActorsChild.h"
1010
#include "LocalStorageCommon.h"
1111
#include "LSDatabase.h"
12-
#include "LSWriteOptimizer.h"
12+
#include "LSWriteOptimizerImpl.h"
1313
#include "mozilla/dom/PBackgroundLSSnapshot.h"
1414
#include "nsContentUtils.h"
1515

dom/localstorage/LSWriteOptimizer.cpp

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -63,52 +63,5 @@ void LSWriteOptimizerBase::GetSortedWriteInfos(
6363
}
6464
}
6565

66-
template <typename T, typename U>
67-
void LSWriteOptimizer<T, U>::InsertItem(const nsAString& aKey, const T& aValue,
68-
int64_t aDelta) {
69-
AssertIsOnOwningThread();
70-
71-
WriteInfo* existingWriteInfo;
72-
UniquePtr<WriteInfo> newWriteInfo;
73-
if (mWriteInfos.Get(aKey, &existingWriteInfo) &&
74-
existingWriteInfo->GetType() == WriteInfo::DeleteItem) {
75-
// We could just simply replace the deletion with ordinary update, but that
76-
// would preserve item's original position/index. Imagine a case when we
77-
// have only one existing key k1. Now let's create a new optimizer and
78-
// remove k1, add k2 and add k1 back. The final order should be k2, k1
79-
// (ordinary update would produce k1, k2). So we need to differentiate
80-
// between normal update and "optimized" update which resulted from a
81-
// deletion followed by an insertion. We use the UpdateWithMove flag for
82-
// this.
83-
84-
newWriteInfo = MakeUnique<UpdateItemInfo>(NextSerialNumber(), aKey, aValue,
85-
/* aUpdateWithMove */ true);
86-
} else {
87-
newWriteInfo = MakeUnique<InsertItemInfo>(NextSerialNumber(), aKey, aValue);
88-
}
89-
mWriteInfos.Put(aKey, std::move(newWriteInfo));
90-
91-
mTotalDelta += aDelta;
92-
}
93-
94-
template <typename T, typename U>
95-
void LSWriteOptimizer<T, U>::UpdateItem(const nsAString& aKey, const T& aValue,
96-
int64_t aDelta) {
97-
AssertIsOnOwningThread();
98-
99-
WriteInfo* existingWriteInfo;
100-
UniquePtr<WriteInfo> newWriteInfo;
101-
if (mWriteInfos.Get(aKey, &existingWriteInfo) &&
102-
existingWriteInfo->GetType() == WriteInfo::InsertItem) {
103-
newWriteInfo = MakeUnique<InsertItemInfo>(NextSerialNumber(), aKey, aValue);
104-
} else {
105-
newWriteInfo = MakeUnique<UpdateItemInfo>(NextSerialNumber(), aKey, aValue,
106-
/* aUpdateWithMove */ false);
107-
}
108-
mWriteInfos.Put(aKey, std::move(newWriteInfo));
109-
110-
mTotalDelta += aDelta;
111-
}
112-
11366
} // namespace dom
11467
} // namespace mozilla

0 commit comments

Comments
 (0)