Bug 1362498 - cache some networking mozilla::services r=bagder

MozReview-Commit-ID: G61lDIOKcm

--HG--
extra : rebase_source : 83d3f8258234f85145f485ae35e6ac07e77bac98
This commit is contained in:
Patrick McManus 2017-05-05 14:32:19 -04:00
Родитель 5495d41e27
Коммит 580ef98764
9 изменённых файлов: 58 добавлений и 27 удалений

Просмотреть файл

@ -18,7 +18,7 @@ struct PRFileDesc;
[ptr] native PRFileDescPtr(PRFileDesc);
[ptr] native nsASocketHandlerPtr(nsASocketHandler);
[scriptable, uuid(ad56b25f-e6bb-4db3-9f7b-5b7db33fd2b1)]
[builtinclass, scriptable, uuid(ad56b25f-e6bb-4db3-9f7b-5b7db33fd2b1)]
interface nsISocketTransportService : nsISupports
{
/**
@ -119,7 +119,7 @@ interface nsISocketTransportService : nsISupports
[noscript] void notifyWhenCanAttachSocket(in nsIRunnable aEvent);
};
[scriptable, uuid(c5204623-5b58-4a16-8b2e-67c34dd02e3f)]
[builtinclass, scriptable, uuid(c5204623-5b58-4a16-8b2e-67c34dd02e3f)]
interface nsIRoutedSocketTransportService : nsISocketTransportService
{
// use this instead of createTransport when you have a transport

Просмотреть файл

@ -15,7 +15,7 @@ interface nsIOutputStream;
* into a fully asynchronous stream that can be read/written without
* blocking the main thread.
*/
[scriptable, uuid(5e0adf7d-9785-45c3-a193-04f25a75da8f)]
[builtinclass, scriptable, uuid(5e0adf7d-9785-45c3-a193-04f25a75da8f)]
interface nsIStreamTransportService : nsISupports
{
/**

Просмотреть файл

@ -10,7 +10,7 @@
* This is a private interface used by the internals of the networking library.
* It will never be frozen. Do not use it in external code.
*/
[scriptable, uuid(18f73bf1-b35b-4b7b-aa9a-11bcbdbc389c)]
[builtinclass, scriptable, uuid(18f73bf1-b35b-4b7b-aa9a-11bcbdbc389c)]
interface nsPISocketTransportService : nsIRoutedSocketTransportService
{

Просмотреть файл

@ -1208,6 +1208,16 @@ nsProtocolProxyService::AsyncResolveInternal(nsIChannel *channel, uint32_t flags
nsCOMPtr<nsIProxyInfo> pi;
bool usePACThread;
// adapt to realtime changes in the system proxy service
if (mProxyConfig == PROXYCONFIG_SYSTEM) {
nsCOMPtr<nsISystemProxySettings> sp2 =
do_GetService(NS_SYSTEMPROXYSETTINGS_CONTRACTID);
if (sp2 != mSystemProxySettings) {
mSystemProxySettings = sp2;
ResetPACThread();
}
}
// SystemProxySettings and PAC files can block the main thread
// but if neither of them are in use, we can just do the work
// right here and directly invoke the callback

Просмотреть файл

@ -140,8 +140,6 @@ static uint32_t sRCWNSmallResourceSizeKB = 256;
((mFirstResponseSource == RESPONSE_FROM_NETWORK) && (req != mTransactionPump))))
static NS_DEFINE_CID(kStreamListenerTeeCID, NS_STREAMLISTENERTEE_CID);
static NS_DEFINE_CID(kStreamTransportServiceCID,
NS_STREAMTRANSPORTSERVICE_CID);
enum CacheDisposition {
kCacheHit = 1,
@ -3483,9 +3481,10 @@ nsHttpChannel::OpenCacheEntry(bool isHttps)
}
}
nsCOMPtr<nsICacheStorageService> cacheStorageService =
do_GetService("@mozilla.org/netwerk/cache-storage-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsICacheStorageService> cacheStorageService(services::GetCacheStorageService());
if (!cacheStorageService) {
return NS_ERROR_NOT_AVAILABLE;
}
nsCOMPtr<nsICacheStorage> cacheStorage;
nsCOMPtr<nsIURI> openURI;
@ -4696,8 +4695,8 @@ nsHttpChannel::OpenCacheInputStream(nsICacheEntry* cacheEntry, bool startBufferi
nsCOMPtr<nsITransport> transport;
nsCOMPtr<nsIInputStream> wrapper;
nsCOMPtr<nsIStreamTransportService> sts =
do_GetService(kStreamTransportServiceCID, &rv);
nsCOMPtr<nsIStreamTransportService> sts(services::GetStreamTransportService());
rv = sts ? NS_OK : NS_ERROR_NOT_AVAILABLE;
if (NS_SUCCEEDED(rv)) {
rv = sts->CreateInputTransport(stream, int64_t(-1), int64_t(-1),
true, getter_AddRefs(transport));
@ -5238,9 +5237,10 @@ nsHttpChannel::InstallCacheListener(int64_t offset)
nsCOMPtr<nsIEventTarget> cacheIOTarget;
if (!CacheObserver::UseNewCache()) {
nsCOMPtr<nsICacheStorageService> serv =
do_GetService("@mozilla.org/netwerk/cache-storage-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsICacheStorageService> serv(services::GetCacheStorageService());
if (!serv) {
return NS_ERROR_NOT_AVAILABLE;
}
serv->GetIoTarget(getter_AddRefs(cacheIOTarget));
}
@ -5992,7 +5992,7 @@ nsHttpChannel::InitLocalBlockList(const InitLocalBlockListCallback& aCallback)
}
// Check to see if this principal exists on local blocklists.
nsCOMPtr<nsIURIClassifier> classifier = do_GetService(NS_URICLASSIFIERSERVICE_CONTRACTID);
nsCOMPtr<nsIURIClassifier> classifier(services::GetURIClassifier());
RefPtr<nsChannelClassifier> channelClassifier = new nsChannelClassifier(this);
bool tpEnabled = false;
channelClassifier->ShouldEnableTrackingProtection(&tpEnabled);
@ -8269,8 +8269,8 @@ nsHttpChannel::DoInvalidateCacheEntry(nsIURI* aURI)
LOG(("DoInvalidateCacheEntry [channel=%p key=%s]", this, key.get()));
nsCOMPtr<nsICacheStorageService> cacheStorageService =
do_GetService("@mozilla.org/netwerk/cache-storage-service;1", &rv);
nsCOMPtr<nsICacheStorageService> cacheStorageService(services::GetCacheStorageService());
rv = cacheStorageService ? NS_OK : NS_ERROR_FAILURE;
nsCOMPtr<nsICacheStorage> cacheStorage;
if (NS_SUCCEEDED(rv)) {

Просмотреть файл

@ -22,6 +22,7 @@
#include "mozilla/net/DNS.h"
#include "nsISocketTransport.h"
#include "nsISSLSocketControl.h"
#include "mozilla/Services.h"
#include "mozilla/Telemetry.h"
#include "mozilla/net/DashboardTypes.h"
#include "NullHttpTransaction.h"
@ -133,11 +134,13 @@ nsHttpConnectionMgr::~nsHttpConnectionMgr()
nsresult
nsHttpConnectionMgr::EnsureSocketThreadTarget()
{
nsresult rv;
nsCOMPtr<nsIEventTarget> sts;
nsCOMPtr<nsIIOService> ioService = do_GetIOService(&rv);
if (NS_SUCCEEDED(rv))
sts = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
nsCOMPtr<nsIIOService> ioService = services::GetIOService();
if (ioService) {
nsCOMPtr<nsISocketTransportService> realSTS =
services::GetSocketTransportService();
sts = do_QueryInterface(realSTS);
}
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
@ -147,7 +150,7 @@ nsHttpConnectionMgr::EnsureSocketThreadTarget()
mSocketThreadTarget = sts;
return rv;
return sts ? NS_OK : NS_ERROR_NOT_AVAILABLE;
}
nsresult
@ -3113,8 +3116,10 @@ nsHalfOpenSocket::SetupStreams(nsISocketTransport **transport,
nsCOMPtr<nsISocketTransport> socketTransport;
nsCOMPtr<nsISocketTransportService> sts;
sts = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
sts = services::GetSocketTransportService();
if (!sts) {
return NS_ERROR_NOT_AVAILABLE;
}
LOG(("nsHalfOpenSocket::SetupStreams [this=%p ent=%s] "
"setup routed transport to origin %s:%d via %s:%d\n",

Просмотреть файл

@ -28,7 +28,6 @@
#include "nsStringStream.h"
#include "nsComponentManagerUtils.h" // do_CreateInstance
#include "nsServiceManagerUtils.h" // do_GetService
#include "nsIHttpActivityObserver.h"
#include "nsSocketTransportService2.h"
#include "nsICancelable.h"
@ -217,8 +216,10 @@ nsHttpTransaction::Init(uint32_t caps,
mTopLevelOuterContentWindowId = topLevelOuterContentWindowId;
mActivityDistributor = do_GetService(NS_HTTPACTIVITYDISTRIBUTOR_CONTRACTID, &rv);
if (NS_FAILED(rv)) return rv;
mActivityDistributor = services::GetActivityDistributor();
if (!mActivityDistributor) {
return NS_ERROR_NOT_AVAILABLE;
}
bool activityDistributorActive;
rv = mActivityDistributor->GetIsActive(&activityDistributorActive);

Просмотреть файл

@ -33,6 +33,16 @@ MOZ_SERVICE(UUIDGenerator, nsIUUIDGenerator,
"@mozilla.org/uuid-generator;1");
MOZ_SERVICE(GfxInfo, nsIGfxInfo,
"@mozilla.org/gfx/info;1");
MOZ_SERVICE(SocketTransportService, nsISocketTransportService,
"@mozilla.org/network/socket-transport-service;1");
MOZ_SERVICE(StreamTransportService, nsIStreamTransportService,
"@mozilla.org/network/stream-transport-service;1");
MOZ_SERVICE(CacheStorageService, nsICacheStorageService,
"@mozilla.org/netwerk/cache-storage-service;1");
MOZ_SERVICE(URIClassifier, nsIURIClassifier,
"@mozilla.org/uriclassifierservice");
MOZ_SERVICE(ActivityDistributor, nsIHttpActivityDistributor,
"@mozilla.org/network/http-activity-distributor;1");
#ifdef MOZ_USE_NAMESPACE
namespace mozilla {

Просмотреть файл

@ -22,6 +22,11 @@
#include "inIDOMUtils.h"
#include "nsIPermissionManager.h"
#include "nsIServiceWorkerManager.h"
#include "nsICacheStorageService.h"
#include "nsIStreamTransportService.h"
#include "nsISocketTransportService.h"
#include "nsIURIClassifier.h"
#include "nsIHttpActivityObserver.h"
#include "nsIAsyncShutdown.h"
#include "nsIUUIDGenerator.h"
#include "nsIGfxInfo.h"