[Amarok] c1caa14 Temporarily work around NAM causing inifinte loops

Rick W. Chen stuffcorpse at archlinux.us
Wed Jun 23 08:46:18 CEST 2010


commit c1caa149a1ed0cbe9f628a44eeffcd71ed802edf
Author: Rick W. Chen <stuffcorpse at archlinux.us>
Date:   Wed Jun 23 18:35:17 2010 +1200

    Temporarily work around NAM causing inifinte loops with empty urls
    
    First pointed out by Mathias Panzenböck with high cpu usage and
    unresponsive UI, turns out it was caused by bad URL handling of replies
    in the similar artists engine (and possibly elsewhere). The timeout code
    can also trigger this behaviour and is thus reverted. This is a
    temporary work around until I find a better solution for using the
    NAM proxy.
    
    CCMAIL: grosser.meister.morti at gmx.net
    CCMAIL: amarok-devel at kde.org
    
    Revert "Add stringent timeout to NAM requests"
    
    This reverts commit 2e21aa28964438b26ed429930c5f87d4cc81a4d9.
    
    Conflicts:
    
    	src/network/NetworkAccessManagerProxy.cpp
    	src/network/NetworkAccessManagerProxy.h

diff --git a/src/context/applets/similarartists/ArtistWidget.cpp b/src/context/applets/similarartists/ArtistWidget.cpp
index 690e8c9..3b41924 100644
--- a/src/context/applets/similarartists/ArtistWidget.cpp
+++ b/src/context/applets/similarartists/ArtistWidget.cpp
@@ -183,7 +183,7 @@ void
 ArtistWidget::setImageFromInternet( QNetworkReply *reply )
 {
     const KUrl url = reply->request().url();
-    if( m_url != url )
+    if( !url.isValid() || m_url != url )
         return;
 
     m_url.clear();
diff --git a/src/context/engines/similarartists/SimilarArtistsEngine.cpp b/src/context/engines/similarartists/SimilarArtistsEngine.cpp
index 6db06da..62f9427 100644
--- a/src/context/engines/similarartists/SimilarArtistsEngine.cpp
+++ b/src/context/engines/similarartists/SimilarArtistsEngine.cpp
@@ -281,7 +281,7 @@ void
 SimilarArtistsEngine::parseSimilarArtists( QNetworkReply *reply ) // SLOT
 {
     const KUrl url = reply->request().url();
-    if( m_similarArtistsUrl != url )
+    if( !url.isValid() || m_similarArtistsUrl != url )
         return;
 
     m_similarArtistsUrl.clear();
@@ -416,7 +416,7 @@ void
 SimilarArtistsEngine::parseArtistDescription( QNetworkReply *reply )
 {
     const KUrl url = reply->request().url();
-    if( !m_artistDescriptionUrls.contains( url ) )
+    if( !url.isValid() || !m_artistDescriptionUrls.contains( url ) )
         return;
 
     m_artistDescriptionUrls.remove( url );
diff --git a/src/context/widgets/DropPixmapItem.cpp b/src/context/widgets/DropPixmapItem.cpp
index 649052c..75a5d40 100644
--- a/src/context/widgets/DropPixmapItem.cpp
+++ b/src/context/widgets/DropPixmapItem.cpp
@@ -75,7 +75,7 @@ void DropPixmapItem::dropEvent(QGraphicsSceneDragDropEvent* event)
 void DropPixmapItem::imageDownloadResult( QNetworkReply *reply )
 {
     const KUrl url = reply->request().url();
-    if( m_url != url )
+    if( !url.isValid() || m_url != url )
         return;
 
     m_url.clear();
diff --git a/src/network/NetworkAccessManagerProxy.cpp b/src/network/NetworkAccessManagerProxy.cpp
index 700f020..482eb91 100644
--- a/src/network/NetworkAccessManagerProxy.cpp
+++ b/src/network/NetworkAccessManagerProxy.cpp
@@ -15,9 +15,6 @@
  * this program.  If not, see <http://www.gnu.org/licenses/>.                           *
  ****************************************************************************************/
 
-#define DEBUG_PREFIX "NetworkAccessManagerProxy"
-
-#include "core/support/Debug.h"
 #include "NetworkAccessManagerProxy.h"
 #ifdef DEBUG_BUILD_TYPE
 #include "NetworkAccessViewer.h"
@@ -25,9 +22,7 @@
 
 #include <KProtocolManager>
 
-#include <QBasicTimer>
 #include <QNetworkReply>
-#include <QPointer>
 
 NetworkAccessManagerProxy *NetworkAccessManagerProxy::s_instance = 0;
 
@@ -51,64 +46,20 @@ class NetworkAccessManagerProxy::NetworkAccessManagerProxyPrivate
 {
 public:
 #ifdef DEBUG_BUILD_TYPE
-    NetworkAccessManagerProxyPrivate( NetworkAccessManagerProxy *parent ) : viewer( 0 ), q( parent ) {}
+    NetworkAccessManagerProxyPrivate() : viewer( 0 ) {}
+    NetworkAccessViewer *viewer;
 #else
-    NetworkAccessManagerProxyPrivate( NetworkAccessManagerProxy *parent ) : q( parent ) {}
+    NetworkAccessManagerProxyPrivate( NetworkAccessManagerProxy *parent ) {}
 #endif // DEBUG_BUILD_TYPE
 
-    ~NetworkAccessManagerProxyPrivate()
-    {
-        qDeleteAll( replyTimer.values() );
-        qDeleteAll( timerIds.values() );
-    }
-
-    void addReplyTimeout( QPointer<QNetworkReply> reply )
-    {
-        QBasicTimer *timer = new QBasicTimer();
-        timer->start( 15000, q );
-        int id = timer->timerId();
-        replyTimer.insert( id, reply );
-        timerIds.insert( id, timer );
-    }
-
-    void restartTimeout( QPointer<QNetworkReply> reply )
-    {
-        const int timerId  = replyTimer.key( reply );
-        QBasicTimer *timer = timerIds.value( timerId );
-        timer->stop();
-        timer->start( 15000, q );
-    }
+    ~NetworkAccessManagerProxyPrivate() {}
 
-    void removeReply( QPointer<QNetworkReply> reply )
-    {
-        const int timerId = replyTimer.key( reply );
-        replyTimer.remove( timerId );
-        QBasicTimer *timer = timerIds.take( timerId );
-        delete timer;
-    }
-
-    void pruneReplies()
-    {
-        foreach( const QPointer<QNetworkReply> &reply, replyTimer )
-        {
-            if( reply.isNull() )
-                removeReply( reply );
-        }
-    }
-
-#ifdef DEBUG_BUILD_TYPE
-    NetworkAccessViewer *viewer;
-#endif // DEBUG_BUILD_TYPE
-    QHash<int, QPointer<QNetworkReply> > replyTimer;
-    QHash<int, QBasicTimer*> timerIds;
     QString userAgent;
-
-    NetworkAccessManagerProxy *const q;
 };
 
 NetworkAccessManagerProxy::NetworkAccessManagerProxy( QObject *parent )
     : KIO::Integration::AccessManager( parent )
-    , d( new NetworkAccessManagerProxyPrivate( this ) )
+    , d( new NetworkAccessManagerProxyPrivate() )
 {
     setCache(0);   // disable QtWebKit cache to just use KIO one..
     d->userAgent = KProtocolManager::defaultUserAgent();
@@ -169,25 +120,6 @@ NetworkAccessManagerProxy::createRequest( Operation op, const QNetworkRequest &r
     }
 
     QNetworkReply *reply = KIO::Integration::AccessManager::createRequest( op, request, outgoingData );
-    connect( reply, SIGNAL(finished()), SLOT(replyFinished()) );
-
-    switch( reply->operation() )
-    {
-    case QNetworkAccessManager::GetOperation:
-    case QNetworkAccessManager::HeadOperation:
-        connect( reply, SIGNAL(downloadProgress(qint64,qint64)), SLOT(updateProgress(qint64,qint64)) );
-        d->addReplyTimeout( reply );
-        break;
-
-    case QNetworkAccessManager::PutOperation:
-    case QNetworkAccessManager::PostOperation:
-        connect( reply, SIGNAL(uploadProgress(qint64,qint64)), SLOT(updateProgress(qint64,qint64)) );
-        d->addReplyTimeout( reply );
-        break;
-
-    default:
-        break;
-    }
 
 #ifdef DEBUG_BUILD_TYPE
     if( d->viewer )
@@ -196,43 +128,6 @@ NetworkAccessManagerProxy::createRequest( Operation op, const QNetworkRequest &r
     return reply;
 }
 
-void
-NetworkAccessManagerProxy::timerEvent( QTimerEvent *event )
-{
-    const int tid = event->timerId();
-    if( d->timerIds.contains( tid ) )
-    {
-        // timeout reached
-        QBasicTimer *timer   = d->timerIds.take( tid );
-        QPointer<QNetworkReply> reply = d->replyTimer.take( tid );
-        if( reply )
-            reply->abort();
-        delete timer;
-    }
-    else
-    {
-        KIO::Integration::AccessManager::timerEvent( event );
-    }
-}
-
-void
-NetworkAccessManagerProxy::replyFinished()
-{
-    d->removeReply( qobject_cast<QNetworkReply*>(sender()) );
-    d->pruneReplies();
-}
-
-void
-NetworkAccessManagerProxy::updateProgress( qint64 bytes, qint64 total )
-{
-    Q_UNUSED( bytes )
-    Q_UNUSED( total )
-
-    QPointer<QNetworkReply> reply = qobject_cast<QNetworkReply*>( sender() );
-    if( reply )
-        d->restartTimeout( reply );
-}
-
 namespace The
 {
     NetworkAccessManagerProxy *networkAccessManager()
diff --git a/src/network/NetworkAccessManagerProxy.h b/src/network/NetworkAccessManagerProxy.h
index 71c405c..7895ccb 100644
--- a/src/network/NetworkAccessManagerProxy.h
+++ b/src/network/NetworkAccessManagerProxy.h
@@ -49,11 +49,6 @@ public:
 
 protected:
     virtual QNetworkReply *createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData = 0);
-    virtual void timerEvent( QTimerEvent *event );
-
-private slots:
-    void replyFinished();
-    void updateProgress( qint64 bytes, qint64 total );
 
 private:
     NetworkAccessManagerProxy( QObject *parent = 0 );
@@ -61,7 +56,6 @@ private:
 
     class NetworkAccessManagerProxyPrivate;
     NetworkAccessManagerProxyPrivate* const d;
-    friend class NetworkAccessManagerProxyPrivate;
 
     Q_DISABLE_COPY( NetworkAccessManagerProxy )
 };


More information about the Amarok-devel mailing list