Bug 1331680 - Part 0: Extract nsCookieKey. r=jdm
authorAmy Chung <amchung@mozilla.com>
Thu, 03 Aug 2017 17:56:33 +0800
changeset 372732 cbda2eff9f939a0ef34fc45e534a3a86b1fe4afd
parent 372731 b08731d0a74fe9204eed8ea924d433b3b30084b0
child 372733 5a87c9d62dc4658cfb14daead2cd5c5cff478a51
push id32283
push userkwierso@gmail.com
push dateFri, 04 Aug 2017 01:07:14 +0000
treeherdermozilla-central@32083f24a1bb [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs1331680
milestone57.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 1331680 - Part 0: Extract nsCookieKey. r=jdm
netwerk/cookie/nsCookieKey.h
netwerk/cookie/nsCookieService.cpp
netwerk/cookie/nsCookieService.h
new file mode 100644
--- /dev/null
+++ b/netwerk/cookie/nsCookieKey.h
@@ -0,0 +1,74 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef mozilla_net_nsCookieKey_h
+#define mozilla_net_nsCookieKey_h
+#include "nsHashKeys.h"
+#include "nsTHashtable.h"
+
+namespace mozilla {
+namespace net {
+class nsCookieKey : public PLDHashEntryHdr
+{
+public:
+  typedef const nsCookieKey& KeyType;
+  typedef const nsCookieKey* KeyTypePointer;
+
+  nsCookieKey()
+  {}
+
+  nsCookieKey(const nsCString &baseDomain, const OriginAttributes &attrs)
+    : mBaseDomain(baseDomain)
+    , mOriginAttributes(attrs)
+  {}
+
+  explicit nsCookieKey(KeyTypePointer other)
+    : mBaseDomain(other->mBaseDomain)
+    , mOriginAttributes(other->mOriginAttributes)
+  {}
+
+  nsCookieKey(KeyType other)
+    : mBaseDomain(other.mBaseDomain)
+    , mOriginAttributes(other.mOriginAttributes)
+  {}
+
+  ~nsCookieKey()
+  {}
+
+  bool KeyEquals(KeyTypePointer other) const
+  {
+    return mBaseDomain == other->mBaseDomain &&
+           mOriginAttributes == other->mOriginAttributes;
+  }
+
+  static KeyTypePointer KeyToPointer(KeyType aKey)
+  {
+    return &aKey;
+  }
+
+  static PLDHashNumber HashKey(KeyTypePointer aKey)
+  {
+    nsAutoCString temp(aKey->mBaseDomain);
+    temp.Append('#');
+    nsAutoCString suffix;
+    aKey->mOriginAttributes.CreateSuffix(suffix);
+    temp.Append(suffix);
+    return mozilla::HashString(temp);
+  }
+
+  size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
+  {
+    return mBaseDomain.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
+  }
+
+  enum { ALLOW_MEMMOVE = true };
+
+  nsCString        mBaseDomain;
+  OriginAttributes mOriginAttributes;
+};
+
+} // net
+} // mozilla
+#endif // mozilla_net_nsCookieKey_h
--- a/netwerk/cookie/nsCookieService.cpp
+++ b/netwerk/cookie/nsCookieService.cpp
@@ -602,22 +602,16 @@ public:
   }
 };
 
 NS_IMPL_ISUPPORTS(AppClearDataObserver, nsIObserver)
 
 } // namespace
 
 size_t
-nsCookieKey::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
-{
-  return mBaseDomain.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
-}
-
-size_t
 nsCookieEntry::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
 {
   size_t amount = nsCookieKey::SizeOfExcludingThis(aMallocSizeOf);
 
   amount += mCookies.ShallowSizeOfExcludingThis(aMallocSizeOf);
   for (uint32_t i = 0; i < mCookies.Length(); ++i) {
     amount += mCookies[i]->SizeOfIncludingThis(aMallocSizeOf);
   }
@@ -3435,24 +3429,24 @@ nsCookieService::GetCookieStringInternal
 
   if (!aCookieString.IsEmpty())
     COOKIE_LOGSUCCESS(GET_COOKIE, aHostURI, aCookieString, nullptr, false);
 }
 
 // processes a single cookie, and returns true if there are more cookies
 // to be processed
 bool
-nsCookieService::SetCookieInternal(nsIURI                        *aHostURI,
-                                   const nsCookieKey             &aKey,
-                                   bool                           aRequireHostMatch,
-                                   CookieStatus                   aStatus,
-                                   nsDependentCString            &aCookieHeader,
-                                   int64_t                        aServerTime,
-                                   bool                           aFromHttp,
-                                   nsIChannel                    *aChannel)
+nsCookieService::SetCookieInternal(nsIURI             *aHostURI,
+                                   const nsCookieKey  &aKey,
+                                   bool                aRequireHostMatch,
+                                   CookieStatus        aStatus,
+                                   nsDependentCString &aCookieHeader,
+                                   int64_t             aServerTime,
+                                   bool                aFromHttp,
+                                   nsIChannel         *aChannel)
 {
   NS_ASSERTION(aHostURI, "null host!");
 
   // create a stack-based nsCookieAttributes, to store all the
   // attributes parsed from the cookie
   nsCookieAttributes cookieAttributes;
 
   // init expiryTime such that session cookies won't prematurely expire
@@ -3586,22 +3580,22 @@ nsCookieService::SetCookieInternal(nsIUR
 }
 
 // this is a backend function for adding a cookie to the list, via SetCookie.
 // also used in the cookie manager, for profile migration from IE.
 // it either replaces an existing cookie; or adds the cookie to the hashtable,
 // and deletes a cookie (if maximum number of cookies has been
 // reached). also performs list maintenance by removing expired cookies.
 void
-nsCookieService::AddInternal(const nsCookieKey             &aKey,
-                             nsCookie                      *aCookie,
-                             int64_t                        aCurrentTimeInUsec,
-                             nsIURI                        *aHostURI,
-                             const char                    *aCookieHeader,
-                             bool                           aFromHttp)
+nsCookieService::AddInternal(const nsCookieKey &aKey,
+                             nsCookie          *aCookie,
+                             int64_t            aCurrentTimeInUsec,
+                             nsIURI            *aHostURI,
+                             const char        *aCookieHeader,
+                             bool               aFromHttp)
 {
   int64_t currentTime = aCurrentTimeInUsec / PR_USEC_PER_SEC;
 
   // if the new cookie is httponly, make sure we're not coming from script
   if (!aFromHttp && aCookie->IsHttpOnly()) {
     COOKIE_LOGFAILURE(SET_COOKIE, aHostURI, aCookieHeader,
       "cookie is httponly; coming from script");
     return;
@@ -4993,18 +4987,18 @@ nsCookieService::RemoveCookiesWithOrigin
   DebugOnly<nsresult> rv = transaction.Commit();
   MOZ_ASSERT(NS_SUCCEEDED(rv));
 
   return NS_OK;
 }
 
 // find an secure cookie specified by host and name
 bool
-nsCookieService::FindSecureCookie(const nsCookieKey    &aKey,
-                                  nsCookie             *aCookie)
+nsCookieService::FindSecureCookie(const nsCookieKey &aKey,
+                                  nsCookie          *aCookie)
 {
   EnsureReadDomain(aKey);
 
   nsCookieEntry *entry = mDBState->hostTable.GetEntry(aKey);
   if (!entry)
     return false;
 
   const nsCookieEntry::ArrayType &cookies = entry->GetCookies();
--- a/netwerk/cookie/nsCookieService.h
+++ b/netwerk/cookie/nsCookieService.h
@@ -26,18 +26,20 @@
 #include "mozIStorageCompletionCallback.h"
 #include "mozIStorageStatementCallback.h"
 #include "mozIStorageFunction.h"
 #include "nsIVariant.h"
 #include "nsIFile.h"
 #include "mozilla/BasePrincipal.h"
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Maybe.h"
+#include "nsCookieKey.h"
 
 using mozilla::OriginAttributes;
+using mozilla::nsCookieKey;
 
 class nsICookiePermission;
 class nsIEffectiveTLDService;
 class nsIIDNService;
 class nsIPrefBranch;
 class nsIObserverService;
 class nsIURI;
 class nsIChannel;
@@ -50,74 +52,16 @@ struct nsCookieAttributes;
 struct nsListIter;
 
 namespace mozilla {
 namespace net {
 class CookieServiceParent;
 } // namespace net
 } // namespace mozilla
 
-// hash key class
-class nsCookieKey : public PLDHashEntryHdr
-{
-public:
-  typedef const nsCookieKey& KeyType;
-  typedef const nsCookieKey* KeyTypePointer;
-
-  nsCookieKey()
-  {}
-
-  nsCookieKey(const nsCString &baseDomain, const OriginAttributes &attrs)
-    : mBaseDomain(baseDomain)
-    , mOriginAttributes(attrs)
-  {}
-
-  explicit nsCookieKey(KeyTypePointer other)
-    : mBaseDomain(other->mBaseDomain)
-    , mOriginAttributes(other->mOriginAttributes)
-  {}
-
-  nsCookieKey(KeyType other)
-    : mBaseDomain(other.mBaseDomain)
-    , mOriginAttributes(other.mOriginAttributes)
-  {}
-
-  ~nsCookieKey()
-  {}
-
-  bool KeyEquals(KeyTypePointer other) const
-  {
-    return mBaseDomain == other->mBaseDomain &&
-           mOriginAttributes == other->mOriginAttributes;
-  }
-
-  static KeyTypePointer KeyToPointer(KeyType aKey)
-  {
-    return &aKey;
-  }
-
-  static PLDHashNumber HashKey(KeyTypePointer aKey)
-  {
-    // TODO: more efficient way to generate hash?
-    nsAutoCString temp(aKey->mBaseDomain);
-    temp.Append('#');
-    nsAutoCString suffix;
-    aKey->mOriginAttributes.CreateSuffix(suffix);
-    temp.Append(suffix);
-    return mozilla::HashString(temp);
-  }
-
-  size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
-
-  enum { ALLOW_MEMMOVE = true };
-
-  nsCString        mBaseDomain;
-  OriginAttributes mOriginAttributes;
-};
-
 // Inherit from nsCookieKey so this can be stored in nsTHashTable
 // TODO: why aren't we using nsClassHashTable<nsCookieKey, ArrayType>?
 class nsCookieEntry : public nsCookieKey
 {
   public:
     // Hash methods
     typedef nsTArray< RefPtr<nsCookie> > ArrayType;
     typedef ArrayType::index_type IndexType;