Bug 1534538 - Avoid sending CookieSettings from parent to child if not needed, r=Ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Thu, 14 Mar 2019 06:57:45 +0000
changeset 521850 33d53c6ee1362f77a600c3486646ae6e3816d8fb
parent 521849 36c6a7178a5c8e1ee75821396f904583c3ecba7a
child 521851 4d0c32fbf17c2146a1c1a51afc458de79c10b705
push id10870
push usernbeleuzu@mozilla.com
push dateFri, 15 Mar 2019 20:00:07 +0000
treeherdermozilla-beta@c594aee5b7a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1534538
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1534538 - Avoid sending CookieSettings from parent to child if not needed, r=Ehsan Differential Revision: https://phabricator.services.mozilla.com/D23121
ipc/glue/BackgroundUtils.cpp
netwerk/cookie/CookieSettings.cpp
netwerk/cookie/CookieSettings.h
--- a/ipc/glue/BackgroundUtils.cpp
+++ b/ipc/glue/BackgroundUtils.cpp
@@ -728,19 +728,20 @@ void LoadInfoToParentLoadInfoForwarder(
 
   nsILoadInfo::CrossOriginOpenerPolicy openerPolicy =
       aLoadInfo->GetOpenerPolicy();
 
   Maybe<CookieSettingsArgs> cookieSettingsArgs;
 
   nsCOMPtr<nsICookieSettings> cookieSettings;
   nsresult rv = aLoadInfo->GetCookieSettings(getter_AddRefs(cookieSettings));
-  if (NS_SUCCEEDED(rv) && cookieSettings) {
+  CookieSettings* cs = static_cast<CookieSettings*>(cookieSettings.get());
+  if (NS_SUCCEEDED(rv) && cookieSettings && cs->HasBeenChanged()) {
     CookieSettingsArgs args;
-    static_cast<CookieSettings*>(cookieSettings.get())->Serialize(args);
+    cs->Serialize(args);
     cookieSettingsArgs = Some(args);
   }
 
   *aForwarderArgsOut = ParentLoadInfoForwarderArgs(
       aLoadInfo->GetAllowInsecureRedirectToDataURI(), ipcController, tainting,
       aLoadInfo->GetServiceWorkerTaintingSynthesized(),
       aLoadInfo->GetDocumentHasUserInteracted(),
       aLoadInfo->GetDocumentHasLoaded(), openerPolicy, cookieSettingsArgs);
--- a/netwerk/cookie/CookieSettings.cpp
+++ b/netwerk/cookie/CookieSettings.cpp
@@ -73,17 +73,17 @@ already_AddRefed<nsICookieSettings> Cook
   MOZ_ASSERT(NS_IsMainThread());
 
   RefPtr<CookieSettings> cookieSettings = new CookieSettings(
       StaticPrefs::network_cookie_cookieBehavior(), eProgressive);
   return cookieSettings.forget();
 }
 
 CookieSettings::CookieSettings(uint32_t aCookieBehavior, State aState)
-    : mCookieBehavior(aCookieBehavior), mState(aState) {
+    : mCookieBehavior(aCookieBehavior), mState(aState), mToBeMerged(false) {
   MOZ_ASSERT(NS_IsMainThread());
 }
 
 CookieSettings::~CookieSettings() {
   if (!NS_IsMainThread() && !mCookiePermissions.IsEmpty()) {
     nsCOMPtr<nsIEventTarget> systemGroupEventTarget =
         mozilla::SystemGroup::EventTargetFor(mozilla::TaskCategory::Other);
     MOZ_ASSERT(systemGroupEventTarget);
@@ -144,16 +144,17 @@ CookieSettings::CookiePermission(nsIPrin
   // race conditions.
 
   nsCOMPtr<nsIPermission> permission = nsPermission::Create(
       aPrincipal, NS_LITERAL_CSTRING("cookie"), *aCookiePermission, 0, 0);
   if (permission) {
     mCookiePermissions.AppendElement(permission);
   }
 
+  mToBeMerged = true;
   return NS_OK;
 }
 
 void CookieSettings::Serialize(CookieSettingsArgs& aData) {
   MOZ_ASSERT(NS_IsMainThread());
 
   aData.isFixed() = mState == eFixed;
   aData.cookieBehavior() = mCookieBehavior;
@@ -175,16 +176,18 @@ void CookieSettings::Serialize(CookieSet
     rv = permission->GetCapability(&cookiePermission);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       continue;
     }
 
     aData.cookiePermissions().AppendElement(
         CookiePermissionData(principalInfo, cookiePermission));
   }
+
+  mToBeMerged = false;
 }
 
 /* static */ void CookieSettings::Deserialize(
     const CookieSettingsArgs& aData, nsICookieSettings** aCookieSettings) {
   MOZ_ASSERT(NS_IsMainThread());
 
   CookiePermissionList list;
   for (const CookiePermissionData& data : aData.cookiePermissions()) {
--- a/netwerk/cookie/CookieSettings.h
+++ b/netwerk/cookie/CookieSettings.h
@@ -115,16 +115,21 @@ class CookieSettings final : public nsIC
 
   void Serialize(CookieSettingsArgs& aData);
 
   static void Deserialize(const CookieSettingsArgs& aData,
                           nsICookieSettings** aCookieSettings);
 
   void Merge(const CookieSettingsArgs& aData);
 
+  // We don't want to send this object from parent to child process if there are
+  // no reasons. HasBeenChanged() returns true if the object has changed its
+  // internal state and it must be sent beck to the content process.
+  bool HasBeenChanged() const { return mToBeMerged; }
+
  private:
   enum State {
     // No cookie permissions are allowed to be stored in this object.
     eFixed,
 
     // Cookie permissions can be stored in case they are unknown when they are
     // asked or when they are sent from the parent process.
     eProgressive,
@@ -132,14 +137,16 @@ class CookieSettings final : public nsIC
 
   CookieSettings(uint32_t aCookieBehavior, State aState);
   ~CookieSettings();
 
   uint32_t mCookieBehavior;
   CookiePermissionList mCookiePermissions;
 
   State mState;
+
+  bool mToBeMerged;
 };
 
 }  // namespace net
 }  // namespace mozilla
 
 #endif  // mozilla_net_CookieSettings_h