Bug 1311682 - Rename LOG in PackagedAppService.cpp to avoid redefine of LOG directing to nsHttp log module. r=valentin, a=ritu
authorHonza Bambas <honzab.moz@firemni.cz>
Thu, 20 Oct 2016 06:47:00 -0400
changeset 350794 892beac44c850cacb2cbc5a6f2576ebba33efcea
parent 350793 a258a83d217da0622d056c07ee329a7fc39a63c9
child 350795 ca14ab5a7f99b1d7caf841868ee46188fb44f5db
push id1230
push userjlund@mozilla.com
push dateMon, 31 Oct 2016 18:13:35 +0000
treeherdermozilla-release@5e06e3766db2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvalentin, ritu
bugs1311682
milestone50.0
Bug 1311682 - Rename LOG in PackagedAppService.cpp to avoid redefine of LOG directing to nsHttp log module. r=valentin, a=ritu
netwerk/protocol/http/PackagedAppService.cpp
--- a/netwerk/protocol/http/PackagedAppService.cpp
+++ b/netwerk/protocol/http/PackagedAppService.cpp
@@ -29,18 +29,17 @@
 #include "nsIStreamConverterService.h"
 #include "nsMimeTypes.h"
 
 namespace mozilla {
 namespace net {
 
 static PackagedAppService *gPackagedAppService = nullptr;
 static LazyLogModule gPASLog("PackagedAppService");
-#undef LOG
-#define LOG(args) MOZ_LOG(gPASLog, mozilla::LogLevel::Debug, args)
+#define LOG_PAS(args) MOZ_LOG(gPASLog, mozilla::LogLevel::Debug, args)
 
 NS_IMPL_ISUPPORTS(PackagedAppService, nsIPackagedAppService)
 
 NS_IMPL_ISUPPORTS(PackagedAppService::CacheEntryWriter, nsIStreamListener)
 
 static void
 LogURI(const char *aFunctionName, void *self, nsIURI *aURI, nsILoadContextInfo *aInfo = nullptr)
 {
@@ -53,17 +52,17 @@ LogURI(const char *aFunctionName, void *
     }
 
     nsAutoCString prefix;
     if (aInfo) {
       CacheFileUtils::AppendKeyPrefix(aInfo, prefix);
       prefix += ":";
     }
 
-    LOG(("[%p] %s > %s%s\n", self, aFunctionName, prefix.get(), spec.get()));
+    LOG_PAS(("[%p] %s > %s%s\n", self, aFunctionName, prefix.get(), spec.get()));
   }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
 /* static */ nsresult
 PackagedAppService::CacheEntryWriter::Create(nsIURI *aURI,
                                              nsICacheStorage *aStorage,
@@ -360,17 +359,17 @@ PackagedAppService::PackagedAppChannelLi
 {
   bool isFromCache = false;
   nsCOMPtr<nsICacheInfoChannel> cacheChan = do_QueryInterface(aRequest);
   if (cacheChan) {
       cacheChan->IsFromCache(&isFromCache);
   }
 
   mDownloader->SetIsFromCache(isFromCache);
-  LOG(("[%p] Downloader isFromCache: %d\n", mDownloader.get(), isFromCache));
+  LOG_PAS(("[%p] Downloader isFromCache: %d\n", mDownloader.get(), isFromCache));
 
   // XXX: This is the place to suspend the channel, doom existing cache entries
   // for previous resources, and then resume the channel.
   return mListener->OnStartRequest(aRequest, aContext);
 }
 
 NS_IMETHODIMP
 PackagedAppService::PackagedAppChannelListener::OnStopRequest(nsIRequest *aRequest,
@@ -424,17 +423,17 @@ PackagedAppService::PackagedAppDownloade
 
 void
 PackagedAppService::PackagedAppDownloader::EnsureVerifier(nsIRequest *aRequest)
 {
   if (mVerifier) {
     return;
   }
 
-  LOG(("Creating PackagedAppVerifier."));
+  LOG_PAS(("Creating PackagedAppVerifier."));
 
   nsCOMPtr<nsIMultiPartChannel> multiChannel(do_QueryInterface(aRequest));
   nsCString signature = GetSignatureFromChannel(multiChannel);
   nsCOMPtr<nsICacheEntry> packageCacheEntry = GetPackageCacheEntry(aRequest);
 
   mVerifier = new PackagedAppVerifier(this,
                                       mPackageOrigin,
                                       signature,
@@ -550,17 +549,17 @@ PackagedAppService::PackagedAppDownloade
   partURI.forget(aResult);
   return NS_OK;
 }
 
 void
 PackagedAppService::PackagedAppDownloader::OnError(EErrorType aError)
 {
   // TODO: Handler verification error properly.
-  LOG(("PackagedAppDownloader::OnError > %d", aError));
+  LOG_PAS(("PackagedAppDownloader::OnError > %d", aError));
 
   FinalizeDownload(NS_ERROR_SIGNED_APP_MANIFEST_INVALID);
 }
 
 void
 PackagedAppService::PackagedAppDownloader::FinalizeDownload(nsresult aStatusCode)
 {
   // If this is the last part of the package, it means the requested resources
@@ -591,17 +590,17 @@ nsCString
 PackagedAppService::PackagedAppDownloader::GetSignatureFromChannel(nsIMultiPartChannel* aMulitChannel)
 {
   if (mIsFromCache) {
     // We don't need the signature if the resource is loaded from cache.
     return EmptyCString();
   }
 
   if (!aMulitChannel) {
-    LOG(("The package is either not loaded from cache or malformed."));
+    LOG_PAS(("The package is either not loaded from cache or malformed."));
     return EmptyCString();
   }
 
   nsCString packageHeader;
   aMulitChannel->GetPreamble(packageHeader);
 
   return packageHeader;
 }
@@ -609,33 +608,33 @@ PackagedAppService::PackagedAppDownloade
 NS_IMETHODIMP
 PackagedAppService::PackagedAppDownloader::OnStopRequest(nsIRequest *aRequest,
                                                          nsISupports *aContext,
                                                          nsresult aStatusCode)
 {
   nsCOMPtr<nsIMultiPartChannel> multiChannel(do_QueryInterface(aRequest));
   nsresult rv;
 
-  LOG(("[%p] PackagedAppDownloader::OnStopRequest > status:%X multiChannel:%p\n",
+  LOG_PAS(("[%p] PackagedAppDownloader::OnStopRequest > status:%X multiChannel:%p\n",
        this, aStatusCode, multiChannel.get()));
 
   mProcessingFirstRequest = false;
 
   // lastPart will be true if this is the last part in the package,
   // or if aRequest isn't a multipart channel
   bool lastPart = true;
   if (multiChannel) {
     multiChannel->GetIsLastPart(&lastPart);
   }
 
   // The request is normally a multiPartChannel. If it isn't, it generally means
   // an error has occurred in nsMultiMixedConv.
   // If an error occurred in OnStartRequest, mWriter could be null.
   if (!multiChannel || !mWriter) {
-    LOG(("Either the package was loaded from cache or malformed"));
+    LOG_PAS(("Either the package was loaded from cache or malformed"));
     if (lastPart) {
       // Chances to get here:
       //   1) Very likely the package has been cached or
       //   2) Less likely the package is malformed.
       if (!mVerifier || !mVerifier->WouldVerify()) {
         FinalizeDownload(aStatusCode);
       } else {
         // We've got a broken last part and some resources might be still
@@ -643,17 +642,17 @@ PackagedAppService::PackagedAppDownloade
         // verifier so this broken resource will be processed in the correct
         // order.
         mVerifier->SetHasBrokenLastPart(aStatusCode);
       }
     }
     return NS_OK;
   }
 
-  LOG(("We are going to finish the resource and process it in the verifier."));
+  LOG_PAS(("We are going to finish the resource and process it in the verifier."));
 
   // We've got a resource downloaded. Finalize this resource cache and delegate to
   // PackagedAppVerifier rather than serving this resource right away.
   mWriter->OnStopRequest(aRequest, aContext, aStatusCode);
 
   nsCOMPtr<nsIURI> uri;
   rv = GetSubresourceURI(aRequest, getter_AddRefs(uri));
   if (NS_WARN_IF(NS_FAILED(rv))) {
@@ -734,36 +733,36 @@ nsresult
 PackagedAppService::PackagedAppDownloader::AddCallback(nsIURI *aURI,
                                                        nsICacheEntryOpenCallback *aCallback)
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread(), "mCallbacks hashtable is not thread safe");
   nsAutoCString spec;
   aURI->GetSpecIgnoringRef(spec);
 
   LogURI("PackagedAppDownloader::AddCallback", this, aURI);
-  LOG(("[%p]    > callback: %p\n", this, aCallback));
+  LOG_PAS(("[%p]    > callback: %p\n", this, aCallback));
 
   // Check if we already have a resource waiting for this resource
   nsCOMArray<nsICacheEntryOpenCallback>* array = mCallbacks.Get(spec);
   if (array) {
     if (array->Length() == 0) {
       // The download of this resource has already completed, hence we don't
       // need to wait for it to be inserted in the cache and we can serve it
       // right now, directly.  See also the CallCallbacks method bellow.
-      LOG(("[%p]    > already downloaded\n", this));
+      LOG_PAS(("[%p]    > already downloaded\n", this));
 
       mCacheStorage->AsyncOpenURI(aURI, EmptyCString(),
                                   nsICacheStorage::OPEN_READONLY, aCallback);
     } else {
-      LOG(("[%p]    > adding to array\n", this));
+      LOG_PAS(("[%p]    > adding to array\n", this));
       // Add this resource to the callback array
       array->AppendObject(aCallback);
     }
   } else {
-    LOG(("[%p]    > creating array\n", this));
+    LOG_PAS(("[%p]    > creating array\n", this));
     // This is the first callback for this URI.
     // Create a new array and add the callback
     nsCOMArray<nsICacheEntryOpenCallback>* newArray =
       new nsCOMArray<nsICacheEntryOpenCallback>();
     newArray->AppendObject(aCallback);
     mCallbacks.Put(spec, newArray);
   }
 
@@ -775,17 +774,17 @@ PackagedAppService::PackagedAppDownloade
                                                          nsICacheEntry *aEntry,
                                                          nsresult aResult)
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread(), "mCallbacks hashtable is not thread safe");
   // Hold on to this entry while calling the callbacks
   nsCOMPtr<nsICacheEntry> handle(aEntry);
 
   LogURI("PackagedAppService::PackagedAppDownloader::CallCallbacks", this, aURI);
-  LOG(("[%p]    > status:%X\n", this, aResult));
+  LOG_PAS(("[%p]    > status:%X\n", this, aResult));
 
   nsAutoCString spec;
   aURI->GetAsciiSpec(spec);
 
   nsCOMArray<nsICacheEntryOpenCallback>* array = mCallbacks.Get(spec);
   if (array) {
     uint32_t callbacksNum = array->Length();
     // Call all the callbacks for this URI
@@ -794,62 +793,62 @@ PackagedAppService::PackagedAppDownloade
       // We call to AsyncOpenURI which automatically calls the callback.
       mCacheStorage->AsyncOpenURI(aURI, EmptyCString(),
                                   nsICacheStorage::OPEN_READONLY, callback);
     }
     // Clear the array but leave it in the hashtable
     // An empty array means that the resource was already downloaded, and a
     // new call to AddCallback can simply return it from the cache.
     array->Clear();
-    LOG(("[%p]    > called callbacks (%d)\n", this, callbacksNum));
+    LOG_PAS(("[%p]    > called callbacks (%d)\n", this, callbacksNum));
   } else {
     // There were no listeners waiting for this resource, but we insert a new
     // empty array into the hashtable so if any new callbacks are added while
     // downloading the package, we can simply return it from the cache.
     nsCOMArray<nsICacheEntryOpenCallback>* newArray =
       new nsCOMArray<nsICacheEntryOpenCallback>();
     mCallbacks.Put(spec, newArray);
-    LOG(("[%p]    > created array\n", this));
+    LOG_PAS(("[%p]    > created array\n", this));
   }
 
   aEntry->ForceValidFor(0);
   return NS_OK;
 }
 
 nsresult
 PackagedAppService::PackagedAppDownloader::ClearCallbacks(nsresult aResult)
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread(), "mCallbacks hashtable is not thread safe");
-  LOG(("[%p] PackagedAppService::PackagedAppDownloader::ClearCallbacks > packageKey:%s status:%X\n",
+  LOG_PAS(("[%p] PackagedAppService::PackagedAppDownloader::ClearCallbacks > packageKey:%s status:%X\n",
        this, mPackageKey.get(), aResult));
 
   // Clear the registered callbacks which are not called at all. If the package is already
   // in the cache, the requested resource will be called back here.
   for (auto iter = mCallbacks.Iter(); !iter.Done(); iter.Next()) {
     const nsACString& key = iter.Key();
     const nsCOMArray<nsICacheEntryOpenCallback>* callbackArray = iter.UserData();
 
     if (NS_SUCCEEDED(aResult)) {
       // For success conditions we try to open the cache entry.
       // This can occur when the package metadata is served from the cache,
       // as it hasn't changed, but the entries are still in the cache.
       nsCOMPtr<nsIURI> uri;
       DebugOnly<nsresult> rv = NS_NewURI(getter_AddRefs(uri), key);
       MOZ_ASSERT(NS_SUCCEEDED(rv));
 
-      LOG(("[%p]    > calling AsyncOpenURI for %s\n", this, key.BeginReading()));
+      LOG_PAS(("[%p]    > calling AsyncOpenURI for %s\n", this, key.BeginReading()));
       for (uint32_t i = 0; i < callbackArray->Length(); ++i) {
         nsCOMPtr<nsICacheEntryOpenCallback> callback = callbackArray->ObjectAt(i);
         mCacheStorage->AsyncOpenURI(uri, EmptyCString(),
                                     nsICacheStorage::OPEN_READONLY, callback);
       }
 
     } else { // an error has occured
       // We just call all the callbacks and pass the error result
-      LOG(("[%p]    > passing NULL cache entry for %s\n", this, key.BeginReading()));
+      LOG_PAS(("[%p]    > passing NULL cache entry for %s\n", this, key.BeginReading()));
       for (uint32_t i = 0; i < callbackArray->Length(); ++i) {
         nsCOMPtr<nsICacheEntryOpenCallback> callback = callbackArray->ObjectAt(i);
         callback->OnCacheEntryAvailable(nullptr, false, nullptr, aResult);
       }
     }
 
     // Finally, we remove this entry from the hashtable.
     iter.Remove();
@@ -874,24 +873,24 @@ AddPackageIdToOrigin(nsACString& aOrigin
   return true;
 }
 
 void
 PackagedAppService::PackagedAppDownloader::InstallSignedPackagedApp(const ResourceCacheInfo* aInfo)
 {
   // TODO: Bug 1178533 to register permissions, system messages etc on navigation to
   //       signed packages.
-  LOG(("Install this packaged app."));
+  LOG_PAS(("Install this packaged app."));
   bool isSuccess = false;
 
   nsCOMPtr<nsIInstallPackagedWebapp> installer =
     do_GetService("@mozilla.org/newapps/installpackagedwebapp;1");
 
   if (!installer) {
-    LOG(("InstallSignedPackagedApp: fail to get InstallPackagedWebapp service"));
+    LOG_PAS(("InstallSignedPackagedApp: fail to get InstallPackagedWebapp service"));
     return OnError(ERROR_GET_INSTALLER_FAILED);
   }
 
   nsCString manifestURL;
   aInfo->mURI->GetAsciiSpec(manifestURL);
 
 
   nsCString originWithPackageId = mPackageOrigin;
@@ -899,21 +898,21 @@ PackagedAppService::PackagedAppDownloade
     NS_WARNING("mPackageOrigin is malformed.");
   }
 
   installer->InstallPackagedWebapp(mManifestContent.get(),
                                    originWithPackageId.get(),
                                    manifestURL.get(),
                                    &isSuccess);
   if (!isSuccess) {
-    LOG(("InstallSignedPackagedApp: failed to install permissions"));
+    LOG_PAS(("InstallSignedPackagedApp: failed to install permissions"));
     return OnError(ERROR_INSTALL_RESOURCE_FAILED);
   }
 
-  LOG(("InstallSignedPackagedApp: success."));
+  LOG_PAS(("InstallSignedPackagedApp: success."));
 }
 
 //------------------------------------------------------------------
 // nsIPackagedAppVerifierListener
 //------------------------------------------------------------------
 NS_IMETHODIMP
 PackagedAppService::PackagedAppDownloader::OnVerified(bool aIsManifest,
                                                       nsIURI* aUri,
@@ -954,17 +953,17 @@ PackagedAppService::PackagedAppDownloade
     FinalizeDownload(aInfo->mStatusCode);
     return;
   }
 
   bool isPackagedSigned;
   mVerifier->GetIsPackageSigned(&isPackagedSigned);
   if (!isPackagedSigned) {
     // A verified but unsigned manifest means this package has no signature.
-    LOG(("No signature in the package. Just run normally."));
+    LOG_PAS(("No signature in the package. Just run normally."));
     return;
   }
 
   InstallSignedPackagedApp(aInfo);
 }
 
 void
 PackagedAppService::PackagedAppDownloader::OnResourceVerified(const ResourceCacheInfo* aInfo,
@@ -973,32 +972,32 @@ PackagedAppService::PackagedAppDownloade
   if (!aSuccess) {
     return OnError(ERROR_RESOURCE_VERIFIED_FAILED);
   }
 
   // Serve this resource to all listeners.
   CallCallbacks(aInfo->mURI, aInfo->mCacheEntry, aInfo->mStatusCode);
 
   if (aInfo->mIsLastPart) {
-    LOG(("This is the last part. FinalizeDownload (%d)", aInfo->mStatusCode));
+    LOG_PAS(("This is the last part. FinalizeDownload (%d)", aInfo->mStatusCode));
     FinalizeDownload(aInfo->mStatusCode);
   }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
 PackagedAppService::PackagedAppService()
 {
   gPackagedAppService = this;
-  LOG(("[%p] Created PackagedAppService\n", this));
+  LOG_PAS(("[%p] Created PackagedAppService\n", this));
 }
 
 PackagedAppService::~PackagedAppService()
 {
-  LOG(("[%p] Destroying PackagedAppService\n", this));
+  LOG_PAS(("[%p] Destroying PackagedAppService\n", this));
   gPackagedAppService = nullptr;
 }
 
 /* static */ nsresult
 PackagedAppService::GetPackageURI(nsIURI *aURI, nsIURI **aPackageURI)
 {
   nsCOMPtr<nsIURL> url = do_QueryInterface(aURI);
   if (!url) {
@@ -1032,57 +1031,57 @@ PackagedAppService::GetPackageURI(nsIURI
   return NS_OK;
 }
 
 NS_IMETHODIMP
 PackagedAppService::GetResource(nsIChannel *aChannel,
                                 nsICacheEntryOpenCallback *aCallback)
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread(), "mDownloadingPackages hashtable is not thread safe");
-  LOG(("[%p] PackagedAppService::GetResource(aChannel: %p, aCallback: %p)\n",
+  LOG_PAS(("[%p] PackagedAppService::GetResource(aChannel: %p, aCallback: %p)\n",
        this, aChannel, aCallback));
 
   if (!aChannel || !aCallback) {
     return NS_ERROR_INVALID_ARG;
   }
 
   nsresult rv;
   nsIScriptSecurityManager *securityManager =
     nsContentUtils::GetSecurityManager();
   if (!securityManager) {
-    LOG(("[%p]    > No securityManager\n", this));
+    LOG_PAS(("[%p]    > No securityManager\n", this));
     return NS_ERROR_UNEXPECTED;
   }
   nsCOMPtr<nsIPrincipal> principal;
   rv = securityManager->GetChannelURIPrincipal(aChannel, getter_AddRefs(principal));
   if (NS_FAILED(rv) || !principal) {
-    LOG(("[%p]    > Error getting principal rv=%X principal=%p\n",
+    LOG_PAS(("[%p]    > Error getting principal rv=%X principal=%p\n",
          this, rv, principal.get()));
     return NS_FAILED(rv) ? rv : NS_ERROR_NULL_POINTER;
   }
 
   nsCOMPtr<nsILoadContextInfo> loadContextInfo = GetLoadContextInfo(aChannel);
   if (!loadContextInfo) {
-    LOG(("[%p]    > Channel has no loadContextInfo\n", this));
+    LOG_PAS(("[%p]    > Channel has no loadContextInfo\n", this));
     return NS_ERROR_NULL_POINTER;
   }
 
   nsLoadFlags loadFlags = 0;
   rv = aChannel->GetLoadFlags(&loadFlags);
   if (NS_FAILED(rv)) {
-    LOG(("[%p]    > Error calling GetLoadFlags rv=%X\n", this, rv));
+    LOG_PAS(("[%p]    > Error calling GetLoadFlags rv=%X\n", this, rv));
     return rv;
   }
 
   nsCOMPtr<nsILoadInfo> loadInfo = aChannel->GetLoadInfo();
 
   nsCOMPtr<nsIURI> uri;
   rv = aChannel->GetURI(getter_AddRefs(uri));
   if (NS_WARN_IF(NS_FAILED(rv))) {
-    LOG(("[%p]    > Error calling GetURI rv=%X\n", this, rv));
+    LOG_PAS(("[%p]    > Error calling GetURI rv=%X\n", this, rv));
     return rv;
   }
 
   LogURI("PackagedAppService::GetResource", this, uri, loadContextInfo);
   nsCOMPtr<nsIURI> packageURI;
   rv = GetPackageURI(uri, getter_AddRefs(packageURI));
   if (NS_FAILED(rv)) {
     return rv;
@@ -1163,14 +1162,14 @@ PackagedAppService::GetResource(nsIChann
   return NS_MaybeOpenChannelUsingAsyncOpen2(channel, listener);
 }
 
 nsresult
 PackagedAppService::NotifyPackageDownloaded(nsCString aKey)
 {
   MOZ_RELEASE_ASSERT(NS_IsMainThread(), "mDownloadingPackages hashtable is not thread safe");
   mDownloadingPackages.Remove(aKey);
-  LOG(("[%p] PackagedAppService::NotifyPackageDownloaded > %s\n", this, aKey.get()));
+  LOG_PAS(("[%p] PackagedAppService::NotifyPackageDownloaded > %s\n", this, aKey.get()));
   return NS_OK;
 }
 
 } // namespace net
 } // namespace mozilla