gecko/uriloader/prefetch/OfflineCacheUpdateParent.cpp
Ben Turner 0727b7098c Bug 784726 - 'Remove old IPC::URI'. r=cjones+khuey.
--HG--
rename : ipc/glue/IPCSerializableParams.ipdlh => ipc/glue/InputStreamParams.ipdlh
extra : transplant_source : %A6%BC%8B%8D%3A_%7Df%2B%FE%AA%94%81%AB%CAW%15K%A7%03
2012-08-23 12:33:46 -07:00

159 lines
4.7 KiB
C++

/* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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/. */
#include "OfflineCacheUpdateParent.h"
#include "mozilla/ipc/URIUtils.h"
#include "nsOfflineCacheUpdate.h"
#include "nsIApplicationCache.h"
using namespace mozilla::ipc;
#if defined(PR_LOGGING)
//
// To enable logging (see prlog.h for full details):
//
// set NSPR_LOG_MODULES=nsOfflineCacheUpdate:5
// set NSPR_LOG_FILE=offlineupdate.log
//
// this enables PR_LOG_ALWAYS level information and places all output in
// the file offlineupdate.log
//
extern PRLogModuleInfo *gOfflineCacheUpdateLog;
#endif
#define LOG(args) PR_LOG(gOfflineCacheUpdateLog, 4, args)
#define LOG_ENABLED() PR_LOG_TEST(gOfflineCacheUpdateLog, 4)
namespace mozilla {
namespace docshell {
//-----------------------------------------------------------------------------
// OfflineCacheUpdateParent::nsISupports
//-----------------------------------------------------------------------------
NS_IMPL_ISUPPORTS1(OfflineCacheUpdateParent,
nsIOfflineCacheUpdateObserver)
//-----------------------------------------------------------------------------
// OfflineCacheUpdateParent <public>
//-----------------------------------------------------------------------------
OfflineCacheUpdateParent::OfflineCacheUpdateParent()
: mIPCClosed(false)
{
// Make sure the service has been initialized
nsOfflineCacheUpdateService* service =
nsOfflineCacheUpdateService::EnsureService();
if (!service)
return;
LOG(("OfflineCacheUpdateParent::OfflineCacheUpdateParent [%p]", this));
}
OfflineCacheUpdateParent::~OfflineCacheUpdateParent()
{
LOG(("OfflineCacheUpdateParent::~OfflineCacheUpdateParent [%p]", this));
}
void
OfflineCacheUpdateParent::ActorDestroy(ActorDestroyReason why)
{
mIPCClosed = true;
}
nsresult
OfflineCacheUpdateParent::Schedule(const URIParams& aManifestURI,
const URIParams& aDocumentURI,
const nsCString& aClientID,
const bool& stickDocument)
{
LOG(("OfflineCacheUpdateParent::RecvSchedule [%p]", this));
nsRefPtr<nsOfflineCacheUpdate> update;
nsCOMPtr<nsIURI> manifestURI = DeserializeURI(aManifestURI);
if (!manifestURI)
return NS_ERROR_FAILURE;
nsCOMPtr<nsIURI> documentURI = DeserializeURI(aDocumentURI);
if (!documentURI)
return NS_ERROR_FAILURE;
nsOfflineCacheUpdateService* service =
nsOfflineCacheUpdateService::EnsureService();
if (!service)
return NS_ERROR_FAILURE;
service->FindUpdate(manifestURI, documentURI, getter_AddRefs(update));
if (!update) {
update = new nsOfflineCacheUpdate();
nsresult rv;
// Leave aDocument argument null. Only glues and children keep
// document instances.
rv = update->Init(manifestURI, documentURI, nullptr, nullptr);
NS_ENSURE_SUCCESS(rv, rv);
rv = update->Schedule();
NS_ENSURE_SUCCESS(rv, rv);
}
update->AddObserver(this, false);
if (stickDocument) {
nsCOMPtr<nsIURI> stickURI;
documentURI->Clone(getter_AddRefs(stickURI));
update->StickDocument(stickURI);
}
return NS_OK;
}
NS_IMETHODIMP
OfflineCacheUpdateParent::UpdateStateChanged(nsIOfflineCacheUpdate *aUpdate, uint32_t state)
{
if (mIPCClosed)
return NS_ERROR_UNEXPECTED;
LOG(("OfflineCacheUpdateParent::StateEvent [%p]", this));
uint64_t byteProgress;
aUpdate->GetByteProgress(&byteProgress);
SendNotifyStateEvent(state, byteProgress);
if (state == nsIOfflineCacheUpdateObserver::STATE_FINISHED) {
// Tell the child the particulars after the update has finished.
// Sending the Finish event will release the child side of the protocol
// and notify "offline-cache-update-completed" on the child process.
bool isUpgrade;
aUpdate->GetIsUpgrade(&isUpgrade);
bool succeeded;
aUpdate->GetSucceeded(&succeeded);
SendFinish(succeeded, isUpgrade);
}
return NS_OK;
}
NS_IMETHODIMP
OfflineCacheUpdateParent::ApplicationCacheAvailable(nsIApplicationCache *aApplicationCache)
{
if (mIPCClosed)
return NS_ERROR_UNEXPECTED;
NS_ENSURE_ARG(aApplicationCache);
nsCString cacheClientId;
aApplicationCache->GetClientID(cacheClientId);
nsCString cacheGroupId;
aApplicationCache->GetGroupID(cacheGroupId);
SendAssociateDocuments(cacheGroupId, cacheClientId);
return NS_OK;
}
} // docshell
} // mozilla