Bug 1434206 - Make DBSserviceWorkerProxy as const as possible. r?gcp draft
authorFrancois Marier <francois@mozilla.com>
Thu, 24 May 2018 16:40:35 -0700
changeset 467874 c927a5205abe
parent 467873 220bf5cd9e2a
child 467875 6b2e9de3c9e1
child 467876 4140cd9c67b0
push id180
push userfmarier@mozilla.com
push date2018-05-29 01:16 +0000
reviewersgcp
bugs1434206
milestone62.0a1
Bug 1434206 - Make DBSserviceWorkerProxy as const as possible. r?gcp MozReview-Commit-ID: KPzzmb1Jehi
toolkit/components/url-classifier/nsUrlClassifierProxies.cpp
toolkit/components/url-classifier/nsUrlClassifierProxies.h
--- a/toolkit/components/url-classifier/nsUrlClassifierProxies.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierProxies.cpp
@@ -124,17 +124,17 @@ UrlClassifierDBServiceWorkerProxy::DoLoc
 {
   mTarget->DoLocalLookup(mSpec, mTables, mResults);
   return NS_OK;
 }
 
 nsresult
 UrlClassifierDBServiceWorkerProxy::DoLocalLookup(const nsACString& spec,
                                                  const nsACString& tables,
-                                                 LookupResultArray* results)
+                                                 LookupResultArray* results) const
 
 {
   // Run synchronously on background thread. NS_DISPATCH_SYNC does *not* do
   // what we want -- it continues processing events on the main thread loop
   // before the Dispatch returns.
   nsCOMPtr<nsIRunnable> r = new DoLocalLookupRunnable(mTarget, spec, tables, results);
   nsIThread* t = nsUrlClassifierDBService::BackgroundThread();
   if (!t)
@@ -190,47 +190,47 @@ UrlClassifierDBServiceWorkerProxy::Clear
   nsCOMPtr<nsIRunnable> r =
     NewRunnableMethod("nsUrlClassifierDBServiceWorker::ClearCache",
                       mTarget,
                       &nsUrlClassifierDBServiceWorker::ClearCache);
   return DispatchToWorkerThread(r);
 }
 
 nsresult
-UrlClassifierDBServiceWorkerProxy::OpenDb()
+UrlClassifierDBServiceWorkerProxy::OpenDb() const
 {
   nsCOMPtr<nsIRunnable> r =
     NewRunnableMethod("nsUrlClassifierDBServiceWorker::OpenDb",
                       mTarget,
                       &nsUrlClassifierDBServiceWorker::OpenDb);
   return DispatchToWorkerThread(r);
 }
 
 nsresult
-UrlClassifierDBServiceWorkerProxy::CloseDb()
+UrlClassifierDBServiceWorkerProxy::CloseDb() const
 {
   nsCOMPtr<nsIRunnable> r =
     NewRunnableMethod("nsUrlClassifierDBServiceWorker::CloseDb",
                       mTarget,
                       &nsUrlClassifierDBServiceWorker::CloseDb);
   return DispatchToWorkerThread(r);
 }
 
 nsresult
-UrlClassifierDBServiceWorkerProxy::PreShutdown()
+UrlClassifierDBServiceWorkerProxy::PreShutdown() const
 {
   nsCOMPtr<nsIRunnable> r =
     NewRunnableMethod("nsUrlClassifierDBServiceWorker::PreShutdown",
                       mTarget,
                       &nsUrlClassifierDBServiceWorker::PreShutdown);
   return DispatchToWorkerThread(r);
 }
 
 nsresult
-UrlClassifierDBServiceWorkerProxy::CacheCompletions(const ConstCacheResultArray& aEntries)
+UrlClassifierDBServiceWorkerProxy::CacheCompletions(const ConstCacheResultArray& aEntries) const
 {
   nsCOMPtr<nsIRunnable> r = new CacheCompletionsRunnable(mTarget, aEntries);
   return DispatchToWorkerThread(r);
 }
 
 NS_IMETHODIMP
 UrlClassifierDBServiceWorkerProxy::CacheCompletionsRunnable::Run()
 {
@@ -248,17 +248,17 @@ UrlClassifierDBServiceWorkerProxy::Clear
 NS_IMETHODIMP
 UrlClassifierDBServiceWorkerProxy::ClearLastResultsRunnable::Run()
 {
   return mTarget->ClearLastResults();
 }
 
 nsresult
 UrlClassifierDBServiceWorkerProxy::GetCacheInfo(const nsACString& aTable,
-                                                nsIUrlClassifierGetCacheCallback* aCallback)
+                                                nsIUrlClassifierGetCacheCallback* aCallback) const
 {
   nsCOMPtr<nsIRunnable> r = new GetCacheInfoRunnable(mTarget, aTable, aCallback);
   return DispatchToWorkerThread(r);
 }
 
 NS_IMETHODIMP
 UrlClassifierDBServiceWorkerProxy::GetCacheInfoRunnable::Run()
 {
--- a/toolkit/components/url-classifier/nsUrlClassifierProxies.h
+++ b/toolkit/components/url-classifier/nsUrlClassifierProxies.h
@@ -40,38 +40,38 @@ public:
       , mPrincipal(aPrincipal)
       , mLookupTables(aTables)
       , mCB(aCB)
     { }
 
     NS_DECL_NSIRUNNABLE
 
   private:
-    RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
-    nsCOMPtr<nsIPrincipal> mPrincipal;
-    nsCString mLookupTables;
-    nsCOMPtr<nsIUrlClassifierCallback> mCB;
+    const RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
+    const nsCOMPtr<nsIPrincipal> mPrincipal;
+    const nsCString mLookupTables;
+    const nsCOMPtr<nsIUrlClassifierCallback> mCB;
   };
 
   class GetTablesRunnable : public mozilla::Runnable
   {
   public:
     GetTablesRunnable(nsUrlClassifierDBServiceWorker* aTarget,
                       nsIUrlClassifierCallback* aCB)
       : mozilla::Runnable(
           "UrlClassifierDBServiceWorkerProxy::GetTablesRunnable")
       , mTarget(aTarget)
       , mCB(aCB)
     { }
 
     NS_DECL_NSIRUNNABLE
 
   private:
-    RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
-    nsCOMPtr<nsIUrlClassifierCallback> mCB;
+    const RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
+    const nsCOMPtr<nsIUrlClassifierCallback> mCB;
   };
 
   class BeginUpdateRunnable : public mozilla::Runnable
   {
   public:
     BeginUpdateRunnable(nsUrlClassifierDBServiceWorker* aTarget,
                         nsIUrlClassifierUpdateObserver* aUpdater,
                         const nsACString& aTables)
@@ -80,73 +80,73 @@ public:
       , mTarget(aTarget)
       , mUpdater(aUpdater)
       , mTables(aTables)
     { }
 
     NS_DECL_NSIRUNNABLE
 
   private:
-    RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
-    nsCOMPtr<nsIUrlClassifierUpdateObserver> mUpdater;
-    nsCString mTables;
+    const RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
+    const nsCOMPtr<nsIUrlClassifierUpdateObserver> mUpdater;
+    const nsCString mTables;
   };
 
   class BeginStreamRunnable : public mozilla::Runnable
   {
   public:
     BeginStreamRunnable(nsUrlClassifierDBServiceWorker* aTarget,
                         const nsACString& aTable)
       : mozilla::Runnable(
           "UrlClassifierDBServiceWorkerProxy::BeginStreamRunnable")
       , mTarget(aTarget)
       , mTable(aTable)
     { }
 
     NS_DECL_NSIRUNNABLE
 
   private:
-    RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
-    nsCString mTable;
+    const RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
+    const nsCString mTable;
   };
 
   class UpdateStreamRunnable : public mozilla::Runnable
   {
   public:
     UpdateStreamRunnable(nsUrlClassifierDBServiceWorker* aTarget,
                          const nsACString& aUpdateChunk)
       : mozilla::Runnable(
           "UrlClassifierDBServiceWorkerProxy::UpdateStreamRunnable")
       , mTarget(aTarget)
       , mUpdateChunk(aUpdateChunk)
     { }
 
     NS_DECL_NSIRUNNABLE
 
   private:
-    RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
-    nsCString mUpdateChunk;
+    const RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
+    const nsCString mUpdateChunk;
   };
 
   class CacheCompletionsRunnable : public mozilla::Runnable
   {
   public:
     CacheCompletionsRunnable(nsUrlClassifierDBServiceWorker* aTarget,
                              const mozilla::safebrowsing::ConstCacheResultArray& aEntries)
       : mozilla::Runnable(
           "UrlClassifierDBServiceWorkerProxy::CacheCompletionsRunnable")
       , mTarget(aTarget)
       , mEntries(aEntries)
     { }
 
     NS_DECL_NSIRUNNABLE
 
   private:
-    RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
-    mozilla::safebrowsing::ConstCacheResultArray mEntries;
+    const RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
+    const mozilla::safebrowsing::ConstCacheResultArray mEntries;
   };
 
   class DoLocalLookupRunnable : public mozilla::Runnable
   {
   public:
     DoLocalLookupRunnable(nsUrlClassifierDBServiceWorker* aTarget,
                           const nsACString& spec,
                           const nsACString& tables,
@@ -156,35 +156,34 @@ public:
       , mTarget(aTarget)
       , mSpec(spec)
       , mTables(tables)
       , mResults(results)
     { }
 
     NS_DECL_NSIRUNNABLE
   private:
-    RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
-
-    nsCString mSpec;
-    nsCString mTables;
-    mozilla::safebrowsing::LookupResultArray* mResults;
+    const RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
+    const nsCString mSpec;
+    const nsCString mTables;
+    mozilla::safebrowsing::LookupResultArray* const mResults;
   };
 
   class ClearLastResultsRunnable : public mozilla::Runnable
   {
   public:
     explicit ClearLastResultsRunnable(nsUrlClassifierDBServiceWorker* aTarget)
       : mozilla::Runnable(
           "UrlClassifierDBServiceWorkerProxy::ClearLastResultsRunnable")
       , mTarget(aTarget)
     { }
 
     NS_DECL_NSIRUNNABLE
   private:
-    RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
+    const RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
   };
 
   class GetCacheInfoRunnable: public mozilla::Runnable
   {
   public:
     explicit GetCacheInfoRunnable(nsUrlClassifierDBServiceWorker* aTarget,
                                   const nsACString& aTable,
                                   nsIUrlClassifierGetCacheCallback* aCallback)
@@ -194,56 +193,56 @@ public:
       , mTable(aTable)
       , mCache(nullptr)
       , mCallback(new nsMainThreadPtrHolder<nsIUrlClassifierGetCacheCallback>(
           "nsIUrlClassifierGetCacheCallback", aCallback))
     { }
 
     NS_DECL_NSIRUNNABLE
   private:
-    RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
-    nsCString mTable;
+    const RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
+    const nsCString mTable;
     nsIUrlClassifierCacheInfo* mCache;
-    nsMainThreadPtrHandle<nsIUrlClassifierGetCacheCallback> mCallback;
+    const nsMainThreadPtrHandle<nsIUrlClassifierGetCacheCallback> mCallback;
   };
 
   class GetCacheInfoCallbackRunnable: public mozilla::Runnable
   {
   public:
     explicit GetCacheInfoCallbackRunnable(nsIUrlClassifierCacheInfo* aCache,
-                                          nsMainThreadPtrHandle<nsIUrlClassifierGetCacheCallback>& aCallback)
+                                          const nsMainThreadPtrHandle<nsIUrlClassifierGetCacheCallback>& aCallback)
       : mozilla::Runnable(
           "UrlClassifierDBServiceWorkerProxy::GetCacheInfoCallbackRunnable")
       , mCache(aCache)
       , mCallback(aCallback)
     { }
 
     NS_DECL_NSIRUNNABLE
   private:
     nsIUrlClassifierCacheInfo* mCache;
-    nsMainThreadPtrHandle<nsIUrlClassifierGetCacheCallback> mCallback;
+    const nsMainThreadPtrHandle<nsIUrlClassifierGetCacheCallback> mCallback;
   };
 
 public:
   nsresult DoLocalLookup(const nsACString& spec,
                          const nsACString& tables,
-                         mozilla::safebrowsing::LookupResultArray* results);
+                         mozilla::safebrowsing::LookupResultArray* results) const;
 
-  nsresult OpenDb();
-  nsresult CloseDb();
-  nsresult PreShutdown();
+  nsresult OpenDb() const;
+  nsresult CloseDb() const;
+  nsresult PreShutdown() const;
 
-  nsresult CacheCompletions(const mozilla::safebrowsing::ConstCacheResultArray& aEntries);
+  nsresult CacheCompletions(const mozilla::safebrowsing::ConstCacheResultArray& aEntries) const;
 
   nsresult GetCacheInfo(const nsACString& aTable,
-                        nsIUrlClassifierGetCacheCallback* aCallback);
+                        nsIUrlClassifierGetCacheCallback* aCallback) const;
 private:
   ~UrlClassifierDBServiceWorkerProxy() {}
 
-  RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
+  const RefPtr<nsUrlClassifierDBServiceWorker> mTarget;
 };
 
 // The remaining classes here are all proxies to the main thread
 
 class UrlClassifierLookupCallbackProxy final :
   public nsIUrlClassifierLookupCallback
 {
 public:
@@ -265,24 +264,24 @@ public:
           "UrlClassifierLookupCallbackProxy::LookupCompleteRunnable")
       , mTarget(aTarget)
       , mResults(aResults)
     { }
 
     NS_DECL_NSIRUNNABLE
 
   private:
-    nsMainThreadPtrHandle<nsIUrlClassifierLookupCallback> mTarget;
-    mozilla::safebrowsing::LookupResultArray * mResults;
+    const nsMainThreadPtrHandle<nsIUrlClassifierLookupCallback> mTarget;
+    mozilla::safebrowsing::LookupResultArray* const mResults;
   };
 
 private:
   ~UrlClassifierLookupCallbackProxy() {}
 
-  nsMainThreadPtrHandle<nsIUrlClassifierLookupCallback> mTarget;
+  const nsMainThreadPtrHandle<nsIUrlClassifierLookupCallback> mTarget;
 };
 
 class UrlClassifierCallbackProxy final : public nsIUrlClassifierCallback
 {
 public:
   explicit UrlClassifierCallbackProxy(nsIUrlClassifierCallback* aTarget)
     : mTarget(new nsMainThreadPtrHolder<nsIUrlClassifierCallback>(
         "UrlClassifierCallbackProxy::mTarget", aTarget))
@@ -300,24 +299,24 @@ public:
       : mozilla::Runnable("UrlClassifierCallbackProxy::HandleEventRunnable")
       , mTarget(aTarget)
       , mValue(aValue)
     { }
 
     NS_DECL_NSIRUNNABLE
 
   private:
-    nsMainThreadPtrHandle<nsIUrlClassifierCallback> mTarget;
-    nsCString mValue;
+    const nsMainThreadPtrHandle<nsIUrlClassifierCallback> mTarget;
+    const nsCString mValue;
   };
 
 private:
   ~UrlClassifierCallbackProxy() {}
 
-  nsMainThreadPtrHandle<nsIUrlClassifierCallback> mTarget;
+  const nsMainThreadPtrHandle<nsIUrlClassifierCallback> mTarget;
 };
 
 class UrlClassifierUpdateObserverProxy final :
   public nsIUrlClassifierUpdateObserver
 {
 public:
   explicit UrlClassifierUpdateObserverProxy(nsIUrlClassifierUpdateObserver* aTarget)
     : mTarget(new nsMainThreadPtrHolder<nsIUrlClassifierUpdateObserver>(
@@ -339,18 +338,19 @@ public:
       , mTarget(aTarget)
       , mURL(aURL)
       , mTable(aTable)
     { }
 
     NS_DECL_NSIRUNNABLE
 
   private:
-    nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver> mTarget;
-    nsCString mURL, mTable;
+    const nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver> mTarget;
+    const nsCString mURL;
+    const nsCString mTable;
   };
 
   class StreamFinishedRunnable : public mozilla::Runnable
   {
   public:
     StreamFinishedRunnable(
       const nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver>& aTarget,
       nsresult aStatus,
@@ -360,19 +360,19 @@ public:
       , mTarget(aTarget)
       , mStatus(aStatus)
       , mDelay(aDelay)
     { }
 
     NS_DECL_NSIRUNNABLE
 
   private:
-    nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver> mTarget;
-    nsresult mStatus;
-    uint32_t mDelay;
+    const nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver> mTarget;
+    const nsresult mStatus;
+    const uint32_t mDelay;
   };
 
   class UpdateErrorRunnable : public mozilla::Runnable
   {
   public:
     UpdateErrorRunnable(
       const nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver>& aTarget,
       nsresult aError)
@@ -380,18 +380,18 @@ public:
           "UrlClassifierUpdateObserverProxy::UpdateErrorRunnable")
       , mTarget(aTarget)
       , mError(aError)
     { }
 
     NS_DECL_NSIRUNNABLE
 
   private:
-    nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver> mTarget;
-    nsresult mError;
+    const nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver> mTarget;
+    const nsresult mError;
   };
 
   class UpdateSuccessRunnable : public mozilla::Runnable
   {
   public:
     UpdateSuccessRunnable(
       const nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver>& aTarget,
       uint32_t aRequestedTimeout)
@@ -399,19 +399,19 @@ public:
           "UrlClassifierUpdateObserverProxy::UpdateSuccessRunnable")
       , mTarget(aTarget)
       , mRequestedTimeout(aRequestedTimeout)
     { }
 
     NS_DECL_NSIRUNNABLE
 
   private:
-    nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver> mTarget;
-    uint32_t mRequestedTimeout;
+    const nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver> mTarget;
+    const uint32_t mRequestedTimeout;
   };
 
 private:
   ~UrlClassifierUpdateObserverProxy() {}
 
-  nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver> mTarget;
+  const nsMainThreadPtrHandle<nsIUrlClassifierUpdateObserver> mTarget;
 };
 
 #endif // nsUrlClassifierProxies_h