2010-10-20 10:12:32 -07:00
|
|
|
/* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2010-10-20 10:12:32 -07:00
|
|
|
|
|
|
|
#include "OfflineCacheUpdateParent.h"
|
|
|
|
#include "nsOfflineCacheUpdate.h"
|
|
|
|
#include "nsIApplicationCache.h"
|
|
|
|
|
|
|
|
#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()
|
2010-12-22 07:44:27 -08:00
|
|
|
: mIPCClosed(false)
|
2010-10-20 10:12:32 -07:00
|
|
|
{
|
|
|
|
// 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));
|
|
|
|
}
|
|
|
|
|
2010-12-22 07:44:27 -08:00
|
|
|
void
|
|
|
|
OfflineCacheUpdateParent::ActorDestroy(ActorDestroyReason why)
|
|
|
|
{
|
|
|
|
mIPCClosed = true;
|
|
|
|
}
|
|
|
|
|
2010-10-20 10:12:32 -07:00
|
|
|
nsresult
|
|
|
|
OfflineCacheUpdateParent::Schedule(const URI& aManifestURI,
|
|
|
|
const URI& aDocumentURI,
|
|
|
|
const nsCString& aClientID,
|
|
|
|
const bool& stickDocument)
|
|
|
|
{
|
|
|
|
LOG(("OfflineCacheUpdateParent::RecvSchedule [%p]", this));
|
|
|
|
|
|
|
|
nsRefPtr<nsOfflineCacheUpdate> update;
|
|
|
|
nsCOMPtr<nsIURI> manifestURI(aManifestURI);
|
|
|
|
nsCOMPtr<nsIURI> documentURI(aDocumentURI);
|
|
|
|
|
|
|
|
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.
|
2012-06-04 07:12:24 -07:00
|
|
|
rv = update->Init(manifestURI, documentURI, nsnull, nsnull);
|
2010-10-20 10:12:32 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
rv = update->Schedule();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
update->AddObserver(this, false);
|
2010-10-20 10:12:32 -07:00
|
|
|
|
|
|
|
if (stickDocument) {
|
2010-12-22 07:44:27 -08:00
|
|
|
nsCOMPtr<nsIURI> stickURI;
|
|
|
|
documentURI->Clone(getter_AddRefs(stickURI));
|
|
|
|
update->StickDocument(stickURI);
|
2010-10-20 10:12:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::UpdateStateChanged(nsIOfflineCacheUpdate *aUpdate, PRUint32 state)
|
|
|
|
{
|
2010-12-22 07:44:27 -08:00
|
|
|
if (mIPCClosed)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2010-10-20 10:12:32 -07:00
|
|
|
LOG(("OfflineCacheUpdateParent::StateEvent [%p]", this));
|
|
|
|
|
2012-05-22 13:12:40 -07:00
|
|
|
PRUint64 byteProgress;
|
|
|
|
aUpdate->GetByteProgress(&byteProgress);
|
|
|
|
SendNotifyStateEvent(state, byteProgress);
|
2010-10-20 10:12:32 -07:00
|
|
|
|
|
|
|
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.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool isUpgrade;
|
2010-10-20 10:12:32 -07:00
|
|
|
aUpdate->GetIsUpgrade(&isUpgrade);
|
2011-09-28 23:19:26 -07:00
|
|
|
bool succeeded;
|
2010-10-20 10:12:32 -07:00
|
|
|
aUpdate->GetSucceeded(&succeeded);
|
|
|
|
|
2012-05-11 20:15:47 -07:00
|
|
|
SendFinish(succeeded, isUpgrade);
|
2010-10-20 10:12:32 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
OfflineCacheUpdateParent::ApplicationCacheAvailable(nsIApplicationCache *aApplicationCache)
|
|
|
|
{
|
2010-12-22 07:44:27 -08:00
|
|
|
if (mIPCClosed)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2010-10-20 10:12:32 -07:00
|
|
|
NS_ENSURE_ARG(aApplicationCache);
|
|
|
|
|
|
|
|
nsCString cacheClientId;
|
|
|
|
aApplicationCache->GetClientID(cacheClientId);
|
|
|
|
nsCString cacheGroupId;
|
|
|
|
aApplicationCache->GetGroupID(cacheGroupId);
|
|
|
|
|
2012-05-11 20:15:47 -07:00
|
|
|
SendAssociateDocuments(cacheGroupId, cacheClientId);
|
2010-10-20 10:12:32 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // docshell
|
2011-04-19 16:28:21 -07:00
|
|
|
} // mozilla
|