Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
nsXPINotifierImpl Class Reference

#include <nsUpdateNotification.h>

Inheritance diagram for nsXPINotifierImpl:
Inheritance graph
[legend]
Collaboration diagram for nsXPINotifierImpl:
Collaboration graph
[legend]

List of all members.

Public Member Functions

void onBeginLoad (in nsIRDFXMLSink aSink)
 Called when the load begins.
void onInterrupt (in nsIRDFXMLSink aSink)
 Called when the load is suspended (e.g., for network quantization).
void onResume (in nsIRDFXMLSink aSink)
 Called when a suspended load is resuming.
void onEndLoad (in nsIRDFXMLSink aSink)
 Called when an RDF/XML load completes successfully.
void onError (in nsIRDFXMLSink aSink, in nsresult aStatus, in wstring aErrorMsg)
 Called when an error occurs during the load.

Static Public Member Functions

static NS_IMETHODIMP New (nsISupports *aOuter, REFNSIID aIID, void **aResult)

Protected Member Functions

 nsXPINotifierImpl ()
virtual ~nsXPINotifierImpl ()
nsresult NotificationEnabled (PRBool *aReturn)
nsresult Init ()
nsresult OpenRemoteDataSource (const char *aURL, PRBool blocking, nsIRDFDataSource **aResult)
PRBool IsNewerOrUninstalled (const char *regKey, const char *versionString)
PRInt32 CompareVersions (VERSION *oldversion, VERSION *newVersion)
void StringToVersionNumbers (const nsString &version, int32 *aMajor, int32 *aMinor, int32 *aRelease, int32 *aBuild)

Protected Attributes

nsCOMPtr< nsISupports > mNotifications
nsIRDFServicemRDF
PRUint32 mPendingRefreshes

Static Protected Attributes

static nsIRDFResourcekXPI_NotifierSources = nsnull
static nsIRDFResourcekXPI_NotifierPackages = nsnull
static nsIRDFResourcekXPI_NotifierPackage_Title = nsnull
static nsIRDFResourcekXPI_NotifierPackage_Version = nsnull
static nsIRDFResourcekXPI_NotifierPackage_Description = nsnull
static nsIRDFResourcekXPI_NotifierPackage_RegKey = nsnull
static nsIRDFResourcekNC_NotificationRoot = nsnull
static nsIRDFResourcekNC_Source = nsnull
static nsIRDFResourcekNC_Name = nsnull
static nsIRDFResourcekNC_URL = nsnull
static nsIRDFResourcekNC_Child = nsnull

Detailed Description

Definition at line 66 of file nsUpdateNotification.h.


Constructor & Destructor Documentation

Definition at line 91 of file nsUpdateNotification.cpp.

    : mRDF(nsnull)
{
    mPendingRefreshes = 0;

    static NS_DEFINE_CID(kRDFInMemoryDataSourceCID, NS_RDFINMEMORYDATASOURCE_CID);
    
    mNotifications = do_CreateInstance(kRDFInMemoryDataSourceCID);
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsXPINotifierImpl::~nsXPINotifierImpl ( ) [protected, virtual]

Member Function Documentation

PRInt32 nsXPINotifierImpl::CompareVersions ( VERSION oldversion,
VERSION newVersion 
) [protected]

Definition at line 301 of file nsUpdateNotification.cpp.

{
    PRInt32 diff;
    
    if ( oldversion->major == newVersion->major ) 
    {
        if ( oldversion->minor == newVersion->minor ) 
        {
            if ( oldversion->release == newVersion->release ) 
            {
                if ( oldversion->build == newVersion->build )
                    diff = 0;
                else if ( oldversion->build > newVersion->build )
                    diff = 1;
                else
                    diff = -1;
            }
            else if ( oldversion->release > newVersion->release )
                diff = 1;
            else
                diff = -1;
        }
        else if (  oldversion->minor > newVersion->minor )
            diff = 1;
        else
            diff = -1;
    }
    else if ( oldversion->major > newVersion->major )
        diff = 1;
    else
        diff = -1;

    return diff;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 182 of file nsUpdateNotification.cpp.

{
    PRBool enabled;

    NotificationEnabled(&enabled);

    if (!enabled)
        return NS_ERROR_FAILURE;
    
    if (mNotifications == nsnull)
        return NS_ERROR_FAILURE;

    nsresult rv;
    nsCOMPtr<nsIRDFDataSource> distributors;
    nsCOMPtr<nsIRDFContainer> distributorsContainer;
    nsCOMPtr <nsISimpleEnumerator> distributorEnumerator;
    PRBool moreElements;
    
    // Read the distributor registry
    rv = CallGetService(kRDFServiceCID, &mRDF);
    if (NS_FAILED(rv)) return rv;
    
    if (! kXPI_NotifierSources)
       {
          mRDF->GetResource(NC_XPI_SOURCES,       &kXPI_NotifierSources);
       mRDF->GetResource(NC_XPI_PACKAGES,      &kXPI_NotifierPackages);
       mRDF->GetResource(NC_XPI_TITLE,         &kXPI_NotifierPackage_Title);
       mRDF->GetResource(NC_XPI_VERSION,       &kXPI_NotifierPackage_Version);
       mRDF->GetResource(NC_XPI_DESCRIPTION,   &kXPI_NotifierPackage_Description);
       mRDF->GetResource(NC_XPI_REGKEY,        &kXPI_NotifierPackage_RegKey);

       mRDF->GetResource(NC_RDF_NOTIFICATION_ROOT,  &kNC_NotificationRoot);
       
       mRDF->GetResource(NC_RDF_SOURCE,             &kNC_Source);
          mRDF->GetResource(NC_RDF_NAME,               &kNC_Name);
          mRDF->GetResource(NC_RDF_URL,                &kNC_URL);
          mRDF->GetResource(NC_RDF_CHILD,              &kNC_Child);

       }

    rv = OpenRemoteDataSource(BASE_DATASOURCE_URL, PR_TRUE, getter_AddRefs(distributors));
    if (NS_FAILED(rv)) return rv;

    distributorsContainer = do_CreateInstance(kRDFContainerCID, &rv);
    if (NS_SUCCEEDED(rv))
    {
        rv = distributorsContainer->Init(distributors, kXPI_NotifierSources);
        
        if (NS_SUCCEEDED(rv))
        {
            rv = distributorsContainer->GetElements(getter_AddRefs(distributorEnumerator));

            if (NS_SUCCEEDED(rv))
            {
                distributorEnumerator->HasMoreElements(&moreElements);
                while (moreElements) 
                {
                    nsCOMPtr<nsISupports> i;
                    rv = distributorEnumerator->GetNext(getter_AddRefs(i));
                    if (NS_FAILED(rv)) break;

                    nsCOMPtr<nsIRDFResource> aDistributor(do_QueryInterface(i, &rv));
                    if (NS_FAILED(rv)) break;

                    char* uri;
                    nsCOMPtr<nsIRDFDataSource> remoteDatasource;
                    aDistributor->GetValue(&uri);

                    rv = OpenRemoteDataSource(uri, PR_FALSE, getter_AddRefs(remoteDatasource));
                                   nsMemory::Free(uri);
                    if (NS_FAILED(rv)) break;
                    
                    distributorEnumerator->HasMoreElements(&moreElements);
                }
            }
        }
    }
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool nsXPINotifierImpl::IsNewerOrUninstalled ( const char *  regKey,
const char *  versionString 
) [protected]

Definition at line 264 of file nsUpdateNotification.cpp.

{
    PRBool needJar = PR_FALSE;

    REGERR status = VR_ValidateComponent( (char*) regKey );

    if ( status == REGERR_NOFIND || status == REGERR_NOFILE )
    {
        // either component is not in the registry or it's a file
        // node and the physical file is missing
        needJar = PR_TRUE;
    }
    else
    {
        VERSION oldVersion;

        status = VR_GetVersion( (char*)regKey, &oldVersion );
        
        if ( status != REGERR_OK )
        {
            needJar = PR_TRUE;
        }
        else 
        {
            VERSION newVersion;

            StringToVersionNumbers(versionString, &(newVersion).major, &(newVersion).minor, &(newVersion).release, &(newVersion).build);
            
            if ( CompareVersions(&oldVersion, &newVersion) < 0 )
                needJar = PR_TRUE;
        }
    }
    return needJar;
}

Here is the call graph for this function:

NS_IMETHODIMP nsXPINotifierImpl::New ( nsISupports *  aOuter,
REFNSIID  aIID,
void **  aResult 
) [static]

Definition at line 432 of file nsUpdateNotification.cpp.

{
    NS_PRECONDITION(aOuter == nsnull, "no aggregation");
    if (aOuter)
        return NS_ERROR_NO_AGGREGATION;

    nsXPINotifierImpl* result = new nsXPINotifierImpl();
    if (! result)
        return NS_ERROR_OUT_OF_MEMORY;

    NS_ADDREF(result); // stabilize

    nsresult rv;
    rv = result->Init();
    if (NS_SUCCEEDED(rv)) {
        rv = result->QueryInterface(aIID, aResult);
    }

    NS_RELEASE(result);
    return rv;
}

Here is the call graph for this function:

Definition at line 125 of file nsUpdateNotification.cpp.

{
    *aReturn = PR_FALSE;

    nsCOMPtr<nsIPrefBranch> prefBranch = do_GetService(NS_PREFSERVICE_CONTRACTID);

    if ( prefBranch )
    {
        PRBool value;
        // check to see if we are on.
        nsresult rv = prefBranch->GetBoolPref( (const char*) XPINSTALL_NOTIFICATIONS_ENABLE, &value);

        if (NS_SUCCEEDED(rv) && value)
        {
            // check to see the last time we did anything.  Since flash does not have a persistant
            // way to do poll invervals longer than a session, we will implemented that here by using the
            // preferences.  

            PRInt32 intervalHours = 0;
            
            PRTime now            = 0;
            PRInt32 nowSec        = 0;

            PRInt32 lastTime      = 0;
            
            rv = prefBranch->GetIntPref(XPINSTALL_NOTIFICATIONS_INTERVAL, &intervalHours);

            if (NS_FAILED(rv))
            {
                intervalHours = 7*24;  // default at once a week
                rv = prefBranch->SetIntPref(XPINSTALL_NOTIFICATIONS_INTERVAL, intervalHours);
            }

            rv = prefBranch->GetIntPref(XPINSTALL_NOTIFICATIONS_LASTDATE, &lastTime);
    
            now = PR_Now();

            // nowSec = now / 1000000
            LL_DIV(nowSec, now, 1000000);

            if (NS_FAILED(rv) || lastTime == 0)
            {
                rv = prefBranch->SetIntPref(XPINSTALL_NOTIFICATIONS_LASTDATE, nowSec);
                return NS_OK;
            }
            
            if ((lastTime + (intervalHours*60*24)) <= nowSec)
            {
                *aReturn = PR_TRUE;
            }
        }
    }
    
    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Called when the load begins.

Parameters:
aSinkthe RDF/XML sink on which the load is beginning.

Called when an RDF/XML load completes successfully.

Parameters:
aSinkthe RDF/XML sink that has finished loading.
void nsIRDFXMLSinkObserver::onError ( in nsIRDFXMLSink  aSink,
in nsresult  aStatus,
in wstring  aErrorMsg 
) [inherited]

Called when an error occurs during the load.

Parameters:
aSinkthe RDF/XML sink in which the error occurred
aStatusthe networking result code
aErrorMsgan error message, if applicable

Called when the load is suspended (e.g., for network quantization).

Parameters:
aSinkthe RDF/XML sink that is being interrupted.

Called when a suspended load is resuming.

Parameters:
aSinkthe RDF/XML sink that is resuming.
nsresult nsXPINotifierImpl::OpenRemoteDataSource ( const char *  aURL,
PRBool  blocking,
nsIRDFDataSource **  aResult 
) [protected]

Definition at line 395 of file nsUpdateNotification.cpp.

{
    static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
    nsresult rv;

    nsCOMPtr<nsIRDFRemoteDataSource> remote = do_CreateInstance(kRDFXMLDataSourceCID, &rv);
    if (NS_FAILED(rv)) return rv;

    rv = remote->Init(aURL);
    if (NS_SUCCEEDED(rv)) 
    {
        if (! blocking)
        {
            nsCOMPtr<nsIRDFXMLSink> sink = do_QueryInterface(remote, &rv);
            if (NS_FAILED(rv)) return rv;

            rv = sink->AddXMLSinkObserver(this);
            if (NS_FAILED(rv)) return rv;
        }

        rv = remote->Refresh(blocking);
        if (NS_FAILED(rv)) return rv;

        nsCOMPtr<nsIRDFDataSource> result = do_QueryInterface(remote, &rv);
        *aResult = result;
        NS_IF_ADDREF(*aResult);
        return rv;
    }
    else 
    {
        // we've already loaded this datasource. use cached copy
        return mRDF->GetDataSource(aURL, aResult);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsXPINotifierImpl::StringToVersionNumbers ( const nsString version,
int32 aMajor,
int32 aMinor,
int32 aRelease,
int32 aBuild 
) [protected]

Definition at line 338 of file nsUpdateNotification.cpp.

{
    PRInt32 errorCode;

    int dot = version.FindChar('.', 0);
    
    if ( dot == -1 ) 
    {
        *aMajor = version.ToInteger(&errorCode);
    }
    else  
    {
        nsString majorStr;
        version.Mid(majorStr, 0, dot);
        *aMajor  = majorStr.ToInteger(&errorCode);

        int prev = dot+1;
        dot = version.FindChar('.',prev);
        if ( dot == -1 ) 
        {
            nsString minorStr;
            version.Mid(minorStr, prev, version.Length() - prev);
            *aMinor = minorStr.ToInteger(&errorCode);
        }
        else 
        {
            nsString minorStr;
            version.Mid(minorStr, prev, dot - prev);
            *aMinor = minorStr.ToInteger(&errorCode);

            prev = dot+1;
            dot = version.FindChar('.',prev);
            if ( dot == -1 ) 
            {
                nsString releaseStr;
                version.Mid(releaseStr, prev, version.Length() - prev);
                *aRelease = releaseStr.ToInteger(&errorCode);
            }
            else 
            {
                nsString releaseStr;
                version.Mid(releaseStr, prev, dot - prev);
                *aRelease = releaseStr.ToInteger(&errorCode);
    
                prev = dot+1;
                if ( version.Length() > dot ) 
                {
                    nsString buildStr;
                    version.Mid(buildStr, prev, version.Length() - prev);
                    *aBuild = buildStr.ToInteger(&errorCode);
               }
            }
        }
    }
}

Here is the caller graph for this function:


Member Data Documentation

Definition at line 105 of file nsUpdateNotification.h.

Definition at line 103 of file nsUpdateNotification.h.

Definition at line 101 of file nsUpdateNotification.h.

Definition at line 102 of file nsUpdateNotification.h.

Definition at line 104 of file nsUpdateNotification.h.

Definition at line 98 of file nsUpdateNotification.h.

Definition at line 99 of file nsUpdateNotification.h.

Definition at line 96 of file nsUpdateNotification.h.

Definition at line 97 of file nsUpdateNotification.h.

Definition at line 95 of file nsUpdateNotification.h.

Definition at line 94 of file nsUpdateNotification.h.

nsCOMPtr<nsISupports> nsXPINotifierImpl::mNotifications [protected]

Definition at line 89 of file nsUpdateNotification.h.

Definition at line 92 of file nsUpdateNotification.h.

Definition at line 90 of file nsUpdateNotification.h.


The documentation for this class was generated from the following files: