1 /* -*- mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
19 * Portions created by the Initial Developer are Copyright (C) 2010
20 * the Initial Developer. All Rights Reserved.
23 * Honza Bambas <honzab@firemni.cz>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #include "OfflineCacheUpdateParent.h"
40 #include "nsOfflineCacheUpdate.h"
41 #include "nsIApplicationCache.h"
43 static nsOfflineCacheUpdateService
*gOfflineCacheUpdateService
= nsnull
;
45 #if defined(PR_LOGGING)
47 // To enable logging (see prlog.h for full details):
49 // set NSPR_LOG_MODULES=nsOfflineCacheUpdate:5
50 // set NSPR_LOG_FILE=offlineupdate.log
52 // this enables PR_LOG_ALWAYS level information and places all output in
53 // the file offlineupdate.log
55 extern PRLogModuleInfo
*gOfflineCacheUpdateLog
;
57 #define LOG(args) PR_LOG(gOfflineCacheUpdateLog, 4, args)
58 #define LOG_ENABLED() PR_LOG_TEST(gOfflineCacheUpdateLog, 4)
63 //-----------------------------------------------------------------------------
64 // OfflineCacheUpdateParent::nsISupports
65 //-----------------------------------------------------------------------------
67 NS_IMPL_ISUPPORTS1(OfflineCacheUpdateParent
,
68 nsIOfflineCacheUpdateObserver
)
70 //-----------------------------------------------------------------------------
71 // OfflineCacheUpdateParent <public>
72 //-----------------------------------------------------------------------------
74 OfflineCacheUpdateParent::OfflineCacheUpdateParent()
77 // Make sure the service has been initialized
78 nsOfflineCacheUpdateService
* service
=
79 nsOfflineCacheUpdateService::EnsureService();
83 LOG(("OfflineCacheUpdateParent::OfflineCacheUpdateParent [%p]", this));
86 OfflineCacheUpdateParent::~OfflineCacheUpdateParent()
88 LOG(("OfflineCacheUpdateParent::~OfflineCacheUpdateParent [%p]", this));
92 OfflineCacheUpdateParent::ActorDestroy(ActorDestroyReason why
)
98 OfflineCacheUpdateParent::Schedule(const URI
& aManifestURI
,
99 const URI
& aDocumentURI
,
100 const nsCString
& aClientID
,
101 const bool& stickDocument
)
103 LOG(("OfflineCacheUpdateParent::RecvSchedule [%p]", this));
105 nsRefPtr
<nsOfflineCacheUpdate
> update
;
106 nsCOMPtr
<nsIURI
> manifestURI(aManifestURI
);
107 nsCOMPtr
<nsIURI
> documentURI(aDocumentURI
);
109 nsOfflineCacheUpdateService
* service
=
110 nsOfflineCacheUpdateService::EnsureService();
112 return NS_ERROR_FAILURE
;
114 service
->FindUpdate(manifestURI
, documentURI
, getter_AddRefs(update
));
116 update
= new nsOfflineCacheUpdate();
119 // Leave aDocument argument null. Only glues and children keep
120 // document instances.
121 rv
= update
->Init(manifestURI
, documentURI
, nsnull
);
122 NS_ENSURE_SUCCESS(rv
, rv
);
124 rv
= update
->Schedule();
125 NS_ENSURE_SUCCESS(rv
, rv
);
128 update
->AddObserver(this, PR_FALSE
);
131 nsCOMPtr
<nsIURI
> stickURI
;
132 documentURI
->Clone(getter_AddRefs(stickURI
));
133 update
->StickDocument(stickURI
);
140 OfflineCacheUpdateParent::UpdateStateChanged(nsIOfflineCacheUpdate
*aUpdate
, PRUint32 state
)
143 return NS_ERROR_UNEXPECTED
;
145 LOG(("OfflineCacheUpdateParent::StateEvent [%p]", this));
147 SendNotifyStateEvent(state
);
149 if (state
== nsIOfflineCacheUpdateObserver::STATE_FINISHED
) {
150 // Tell the child the particulars after the update has finished.
151 // Sending the Finish event will release the child side of the protocol
152 // and notify "offline-cache-update-completed" on the child process.
154 aUpdate
->GetIsUpgrade(&isUpgrade
);
156 aUpdate
->GetSucceeded(&succeeded
);
158 SendFinish(succeeded
, isUpgrade
);
165 OfflineCacheUpdateParent::ApplicationCacheAvailable(nsIApplicationCache
*aApplicationCache
)
168 return NS_ERROR_UNEXPECTED
;
170 NS_ENSURE_ARG(aApplicationCache
);
172 nsCString cacheClientId
;
173 aApplicationCache
->GetClientID(cacheClientId
);
174 nsCString cacheGroupId
;
175 aApplicationCache
->GetGroupID(cacheGroupId
);
177 SendAssociateDocuments(cacheGroupId
, cacheClientId
);