Bug 1554377 - Cleanup nsCookie implementation - Get rid of ConstCookie, r=Ehsan
authorAndrea Marchesini <amarchesini@mozilla.com>
Fri, 31 May 2019 09:31:12 +0000
changeset 476337 009302f63111099382cfecfc10a1b5c0d46e11e8
parent 476336 173a179ae14b1c02aa890f358d7bbd3da41322ed
child 476338 08f5643acafa0f03a0339ea0e209829572ec5ca7
push id36092
push userarchaeopteryx@coole-files.de
push dateFri, 31 May 2019 17:03:46 +0000
treeherdermozilla-central@8384972e1f6a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1554377
milestone69.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 1554377 - Cleanup nsCookie implementation - Get rid of ConstCookie, r=Ehsan Differential Revision: https://phabricator.services.mozilla.com/D32560
netwerk/cookie/nsCookieService.cpp
netwerk/cookie/nsCookieService.h
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -1403,22 +1403,25 @@ void nsCookieService::InitDBConn() {
   // We should skip InitDBConn if we close profile during initializing DBStates
   // and then InitDBConn is called after we close the DBStates.
   if (!mInitializedDBStates || mInitializedDBConn || !mDefaultDBState) {
     return;
   }
 
   for (uint32_t i = 0; i < mReadArray.Length(); ++i) {
     CookieDomainTuple& tuple = mReadArray[i];
+    MOZ_ASSERT(!tuple.cookie->isSession());
+
     RefPtr<nsCookie> cookie = nsCookie::Create(
-        tuple.cookie->name, tuple.cookie->value, tuple.cookie->host,
-        tuple.cookie->path, tuple.cookie->expiry, tuple.cookie->lastAccessed,
-        tuple.cookie->creationTime, false, tuple.cookie->isSecure,
-        tuple.cookie->isHttpOnly, tuple.cookie->originAttributes,
-        tuple.cookie->sameSite);
+        tuple.cookie->name(), tuple.cookie->value(), tuple.cookie->host(),
+        tuple.cookie->path(), tuple.cookie->expiry(),
+        tuple.cookie->lastAccessed(), tuple.cookie->creationTime(),
+        tuple.cookie->isSession(), tuple.cookie->isSecure(),
+        tuple.cookie->isHttpOnly(), tuple.originAttributes,
+        tuple.cookie->sameSite());
 
     AddCookieToList(tuple.key, cookie, mDefaultDBState, nullptr, false);
   }
 
   if (NS_FAILED(InitDBConnInternal())) {
     COOKIE_LOGSTRING(LogLevel::Warning,
                      ("InitDBConn(): retrying InitDBConnInternal()"));
     CleanupCachedStatements();
@@ -2588,18 +2591,18 @@ nsCookieService::RemoveNative(const nsAC
 }
 
 /******************************************************************************
  * nsCookieService impl:
  * private file I/O functions
  ******************************************************************************/
 
 // Extract data from a single result row and create an nsCookie.
-mozilla::UniquePtr<ConstCookie> nsCookieService::GetCookieFromRow(
-    mozIStorageStatement* aRow, const OriginAttributes& aOriginAttributes) {
+mozilla::UniquePtr<CookieStruct> nsCookieService::GetCookieFromRow(
+    mozIStorageStatement* aRow) {
   // Skip reading 'baseDomain' -- up to the caller.
   nsCString name, value, host, path;
   DebugOnly<nsresult> rv = aRow->GetUTF8String(IDX_NAME, name);
   NS_ASSERT_SUCCESS(rv);
   rv = aRow->GetUTF8String(IDX_VALUE, value);
   NS_ASSERT_SUCCESS(rv);
   rv = aRow->GetUTF8String(IDX_HOST, host);
   NS_ASSERT_SUCCESS(rv);
@@ -2609,19 +2612,19 @@ mozilla::UniquePtr<ConstCookie> nsCookie
   int64_t expiry = aRow->AsInt64(IDX_EXPIRY);
   int64_t lastAccessed = aRow->AsInt64(IDX_LAST_ACCESSED);
   int64_t creationTime = aRow->AsInt64(IDX_CREATION_TIME);
   bool isSecure = 0 != aRow->AsInt32(IDX_SECURE);
   bool isHttpOnly = 0 != aRow->AsInt32(IDX_HTTPONLY);
   int32_t sameSite = aRow->AsInt32(IDX_SAME_SITE);
 
   // Create a new constCookie and assign the data.
-  return mozilla::MakeUnique<ConstCookie>(
-      name, value, host, path, expiry, lastAccessed, creationTime, isSecure,
-      isHttpOnly, aOriginAttributes, sameSite);
+  return mozilla::MakeUnique<CookieStruct>(
+      name, value, host, path, expiry, lastAccessed, creationTime, isHttpOnly,
+      false, isSecure, sameSite);
 }
 
 void nsCookieService::EnsureReadComplete(bool aInitDBConn) {
   MOZ_ASSERT(NS_IsMainThread());
 
   bool isAccumulated = false;
 
   if (!mInitializedDBStates) {
@@ -2722,17 +2725,18 @@ OpenDBResult nsCookieService::Read() {
     stmt->GetUTF8String(IDX_ORIGIN_ATTRIBUTES, suffix);
     // If PopulateFromSuffix failed we just ignore the OA attributes
     // that we don't support
     Unused << attrs.PopulateFromSuffix(suffix);
 
     nsCookieKey key(baseDomain, attrs);
     CookieDomainTuple* tuple = mReadArray.AppendElement();
     tuple->key = std::move(key);
-    tuple->cookie = GetCookieFromRow(stmt, attrs);
+    tuple->originAttributes = attrs;
+    tuple->cookie = GetCookieFromRow(stmt);
   }
 
   COOKIE_LOGSTRING(LogLevel::Debug,
                    ("Read(): %zu cookies read", mReadArray.Length()));
 
   return RESULT_OK;
 }
 
--- a/netwerk/cookie/nsCookieService.h
+++ b/netwerk/cookie/nsCookieService.h
@@ -83,52 +83,21 @@ class nsCookieEntry : public nsCookieKey
   inline ArrayType& GetCookies() { return mCookies; }
 
   size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
 
  private:
   ArrayType mCookies;
 };
 
-// struct for a constant cookie for threadsafe
-struct ConstCookie {
-  ConstCookie(const nsCString& aName, const nsCString& aValue,
-              const nsCString& aHost, const nsCString& aPath, int64_t aExpiry,
-              int64_t aLastAccessed, int64_t aCreationTime, bool aIsSecure,
-              bool aIsHttpOnly, const OriginAttributes& aOriginAttributes,
-              int32_t aSameSite)
-      : name(aName),
-        value(aValue),
-        host(aHost),
-        path(aPath),
-        expiry(aExpiry),
-        lastAccessed(aLastAccessed),
-        creationTime(aCreationTime),
-        isSecure(aIsSecure),
-        isHttpOnly(aIsHttpOnly),
-        originAttributes(aOriginAttributes),
-        sameSite(aSameSite) {}
-
-  const nsCString name;
-  const nsCString value;
-  const nsCString host;
-  const nsCString path;
-  const int64_t expiry;
-  const int64_t lastAccessed;
-  const int64_t creationTime;
-  const bool isSecure;
-  const bool isHttpOnly;
-  const OriginAttributes originAttributes;
-  const int32_t sameSite;
-};
-
 // encapsulates a (key, nsCookie) tuple for temporary storage purposes.
 struct CookieDomainTuple {
   nsCookieKey key;
-  mozilla::UniquePtr<ConstCookie> cookie;
+  OriginAttributes originAttributes;
+  mozilla::UniquePtr<mozilla::net::CookieStruct> cookie;
 };
 
 // encapsulates in-memory and on-disk DB states, so we can
 // conveniently switch state when entering or exiting private browsing.
 struct DBState final {
   DBState()
       : cookieCount(0),
         cookieOldestTime(INT64_MAX),
@@ -292,18 +261,18 @@ class nsCookieService final : public nsI
   nsresult CreateTableForSchemaVersion5();
   void CloseDBStates();
   void CleanupCachedStatements();
   void CleanupDefaultDBConnection();
   void HandleDBClosed(DBState* aDBState);
   void HandleCorruptDB(DBState* aDBState);
   void RebuildCorruptDB(DBState* aDBState);
   OpenDBResult Read();
-  mozilla::UniquePtr<ConstCookie> GetCookieFromRow(
-      mozIStorageStatement* aRow, const OriginAttributes& aOriginAttributes);
+  mozilla::UniquePtr<mozilla::net::CookieStruct> GetCookieFromRow(
+      mozIStorageStatement* aRow);
   void EnsureReadComplete(bool aInitDBConn);
   nsresult NormalizeHost(nsCString& aHost);
   nsresult GetCookieStringCommon(nsIURI* aHostURI, nsIChannel* aChannel,
                                  bool aHttpBound, char** aCookie);
   void GetCookieStringInternal(nsIURI* aHostURI, nsIChannel* aChannel,
                                bool aIsForeign, bool aIsTrackingResource,
                                bool aFirstPartyStorageAccessGranted,
                                uint32_t aRejectedReason,