LCOV - code coverage report
Current view: directory - uriloader/prefetch - OfflineCacheUpdateParent.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 54 0 0.0 %
Date: 2012-06-02 Functions: 10 0 0.0 %

       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
       4                 :  *
       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/
       9                 :  *
      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
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Mozilla Corporation
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2010
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Honza Bambas <honzab@firemni.cz>
      24                 :  *
      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.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #include "OfflineCacheUpdateParent.h"
      40                 : #include "nsOfflineCacheUpdate.h"
      41                 : #include "nsIApplicationCache.h"
      42                 : 
      43                 : #if defined(PR_LOGGING)
      44                 : //
      45                 : // To enable logging (see prlog.h for full details):
      46                 : //
      47                 : //    set NSPR_LOG_MODULES=nsOfflineCacheUpdate:5
      48                 : //    set NSPR_LOG_FILE=offlineupdate.log
      49                 : //
      50                 : // this enables PR_LOG_ALWAYS level information and places all output in
      51                 : // the file offlineupdate.log
      52                 : //
      53                 : extern PRLogModuleInfo *gOfflineCacheUpdateLog;
      54                 : #endif
      55                 : #define LOG(args) PR_LOG(gOfflineCacheUpdateLog, 4, args)
      56                 : #define LOG_ENABLED() PR_LOG_TEST(gOfflineCacheUpdateLog, 4)
      57                 : 
      58                 : namespace mozilla {
      59                 : namespace docshell {
      60                 : 
      61                 : //-----------------------------------------------------------------------------
      62                 : // OfflineCacheUpdateParent::nsISupports
      63                 : //-----------------------------------------------------------------------------
      64                 : 
      65               0 : NS_IMPL_ISUPPORTS1(OfflineCacheUpdateParent,
      66                 :                    nsIOfflineCacheUpdateObserver)
      67                 : 
      68                 : //-----------------------------------------------------------------------------
      69                 : // OfflineCacheUpdateParent <public>
      70                 : //-----------------------------------------------------------------------------
      71                 : 
      72               0 : OfflineCacheUpdateParent::OfflineCacheUpdateParent()
      73               0 :     : mIPCClosed(false)
      74                 : {
      75                 :     // Make sure the service has been initialized
      76                 :     nsOfflineCacheUpdateService* service =
      77               0 :         nsOfflineCacheUpdateService::EnsureService();
      78               0 :     if (!service)
      79               0 :         return;
      80                 : 
      81               0 :     LOG(("OfflineCacheUpdateParent::OfflineCacheUpdateParent [%p]", this));
      82                 : }
      83                 : 
      84               0 : OfflineCacheUpdateParent::~OfflineCacheUpdateParent()
      85                 : {
      86               0 :     LOG(("OfflineCacheUpdateParent::~OfflineCacheUpdateParent [%p]", this));
      87               0 : }
      88                 : 
      89                 : void
      90               0 : OfflineCacheUpdateParent::ActorDestroy(ActorDestroyReason why)
      91                 : {
      92               0 :     mIPCClosed = true;
      93               0 : }
      94                 : 
      95                 : nsresult
      96               0 : OfflineCacheUpdateParent::Schedule(const URI& aManifestURI,
      97                 :                                    const URI& aDocumentURI,
      98                 :                                    const nsCString& aClientID,
      99                 :                                    const bool& stickDocument)
     100                 : {
     101               0 :     LOG(("OfflineCacheUpdateParent::RecvSchedule [%p]", this));
     102                 : 
     103               0 :     nsRefPtr<nsOfflineCacheUpdate> update;
     104               0 :     nsCOMPtr<nsIURI> manifestURI(aManifestURI);
     105               0 :     nsCOMPtr<nsIURI> documentURI(aDocumentURI);
     106                 : 
     107                 :     nsOfflineCacheUpdateService* service =
     108               0 :         nsOfflineCacheUpdateService::EnsureService();
     109               0 :     if (!service)
     110               0 :         return NS_ERROR_FAILURE;
     111                 : 
     112               0 :     service->FindUpdate(manifestURI, documentURI, getter_AddRefs(update));
     113               0 :     if (!update) {
     114               0 :         update = new nsOfflineCacheUpdate();
     115                 : 
     116                 :         nsresult rv;
     117                 :         // Leave aDocument argument null. Only glues and children keep 
     118                 :         // document instances.
     119               0 :         rv = update->Init(manifestURI, documentURI, nsnull);
     120               0 :         NS_ENSURE_SUCCESS(rv, rv);
     121                 : 
     122               0 :         rv = update->Schedule();
     123               0 :         NS_ENSURE_SUCCESS(rv, rv);
     124                 :     }
     125                 : 
     126               0 :     update->AddObserver(this, false);
     127                 : 
     128               0 :     if (stickDocument) {
     129               0 :         nsCOMPtr<nsIURI> stickURI;
     130               0 :         documentURI->Clone(getter_AddRefs(stickURI));
     131               0 :         update->StickDocument(stickURI);
     132                 :     }
     133                 : 
     134               0 :     return NS_OK;
     135                 : }
     136                 : 
     137                 : NS_IMETHODIMP
     138               0 : OfflineCacheUpdateParent::UpdateStateChanged(nsIOfflineCacheUpdate *aUpdate, PRUint32 state)
     139                 : {
     140               0 :     if (mIPCClosed)
     141               0 :         return NS_ERROR_UNEXPECTED;
     142                 : 
     143               0 :     LOG(("OfflineCacheUpdateParent::StateEvent [%p]", this));
     144                 : 
     145               0 :     SendNotifyStateEvent(state);
     146                 : 
     147               0 :     if (state == nsIOfflineCacheUpdateObserver::STATE_FINISHED) {
     148                 :         // Tell the child the particulars after the update has finished.
     149                 :         // Sending the Finish event will release the child side of the protocol
     150                 :         // and notify "offline-cache-update-completed" on the child process.
     151                 :         bool isUpgrade;
     152               0 :         aUpdate->GetIsUpgrade(&isUpgrade);
     153                 :         bool succeeded;
     154               0 :         aUpdate->GetSucceeded(&succeeded);
     155                 : 
     156               0 :         SendFinish(succeeded, isUpgrade);
     157                 :     }
     158                 : 
     159               0 :     return NS_OK;
     160                 : }
     161                 : 
     162                 : NS_IMETHODIMP
     163               0 : OfflineCacheUpdateParent::ApplicationCacheAvailable(nsIApplicationCache *aApplicationCache)
     164                 : {
     165               0 :     if (mIPCClosed)
     166               0 :         return NS_ERROR_UNEXPECTED;
     167                 : 
     168               0 :     NS_ENSURE_ARG(aApplicationCache);
     169                 : 
     170               0 :     nsCString cacheClientId;
     171               0 :     aApplicationCache->GetClientID(cacheClientId);
     172               0 :     nsCString cacheGroupId;
     173               0 :     aApplicationCache->GetGroupID(cacheGroupId);
     174                 : 
     175               0 :     SendAssociateDocuments(cacheGroupId, cacheClientId);
     176               0 :     return NS_OK;
     177                 : }
     178                 : 
     179                 : } // docshell
     180                 : } // mozilla

Generated by: LCOV version 1.7