Bug 57049 - [Qt] QNetworkReplyHandler refactoring: signal sequence.
Summary: [Qt] QNetworkReplyHandler refactoring: signal sequence.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P3 Normal
Assignee: Luiz Agostini
URL:
Keywords: Qt
Depends on:
Blocks: 57075
  Show dependency treegraph
 
Reported: 2011-03-24 13:28 PDT by Luiz Agostini
Modified: 2011-03-30 16:41 PDT (History)
10 users (show)

See Also:


Attachments
patch (21.63 KB, patch)
2011-03-24 13:46 PDT, Luiz Agostini
no flags Details | Formatted Diff | Diff
patch (21.92 KB, patch)
2011-03-29 11:54 PDT, Luiz Agostini
kenneth: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Luiz Agostini 2011-03-24 13:28:44 PDT
This is the first step in QNetworkReplyHandler. The main objective here is to create simple invariants: 

 1 - that the signals metadatachanged, readyRead and finished will come in this order.
 2 - that signals metadatachanged and finished will come for sure.

Having these invariants further simplifications will be possible and will come in future patches.
Comment 1 Luiz Agostini 2011-03-24 13:46:48 PDT
Created attachment 86823 [details]
patch
Comment 2 Kenneth Rohde Christiansen 2011-03-24 13:56:29 PDT
Kling, Jocelyn can you have a look at this?
Comment 3 Benjamin Poulain 2011-03-25 02:42:19 PDT
Could you give a bit of context? Which bugs is this fixing?

About the new enforced invariants:
 1 - that the signals metadatachanged, readyRead and finished will come in this order.
 2 - that signals metadatachanged and finished will come for sure.

In which case are they not met with the current code?
Comment 4 Luiz Agostini 2011-03-25 02:49:07 PDT
(In reply to comment #3)
> Could you give a bit of context? Which bugs is this fixing?
> 
> About the new enforced invariants:
>  1 - that the signals metadatachanged, readyRead and finished will come in this order.
>  2 - that signals metadatachanged and finished will come for sure.
> 
> In which case are they not met with the current code?

The current code expects the signals to come in any sequence.

Slots forwardData() and finish() call sendResponseIfNeeded() and a flag named m_responseSent is kept to indicate if sendResponseIfNeeded() is been called for the second time.

All those slots (forwardData, finish and sendResponseIfNeeded) are connected to a QNetworkReply object.
Comment 5 Luiz Agostini 2011-03-25 03:05:55 PDT
This is a refactoring that will make further changes. I tried to provide patches that are easy to understand each one alone. But the whole refactoring is much larger.

Basically the strategy is to:

 1 - create a wrapper that will enforce the invariants that I need and will be the place to add further logic as mime sniffing. (bug 57049)
 2 - separate the 'deferred' logic from the actual content processing logic. (bug 57075)
 3 - separate the logic for redirection from the logic for receive meta data. (bug 57083)
 4 - cleanup. (bug 57092)
 5 - create a separated class to be used in synchronous requests.
Comment 6 Jocelyn Turcotte 2011-03-28 07:37:17 PDT
Concerns:
- I'm not sure why you need to disconnect and reconnect the reply at each signal received. This could have performance impacts, especially for readyRead.
- In QNetworkReplyWrapper::receiveMetaData, each time you will receive readyRead from the reply, you will do the mime type dance and emit metadataChanged. Doing it once the first time should be enough.
- The QNetworkReplyWrapper class name doesn't define much it's responsibility, though I can't find a better name myself so...

This whole refactoring is awesome but it moves more tiny networking bug fixes than it may look. I think it would be better not to get this in QtWebKit 2.2 unless of course there is a clear gain and we put additional efforts to test this code.
Comment 7 Luiz Agostini 2011-03-28 12:26:14 PDT
(In reply to comment #6)
> Concerns:
> - I'm not sure why you need to disconnect and reconnect the reply at each signal received. This could have performance impacts, especially for readyRead.

At construction time all signals from QNetworkReply are connected to receiveMetaData and they are disconnected as soon as the first one come. The slot receiveMetaData is not used form this point on. If needed, the signals from QNetworkReply will be connected to other slots. Specifically, readyRead signal form QNetworkReply will only trigger QNetworkReplyWrapper's own readyRead signal.

 214    connect(m_reply, SIGNAL(readyRead()), this, SIGNAL(readyRead()));
 215    connect(m_reply, SIGNAL(finished()), this, SLOT(receiveFinished()));

> - In QNetworkReplyWrapper::receiveMetaData, each time you will receive readyRead from the reply, you will do the mime type dance and emit metadataChanged. Doing it once the first time should be enough.

The slot receiveMetaData is only be used to receive the first signal from QNetwrokReply. Signal metadataChanged is emitted only once. The mime type dance will only happen exactly once.

> - The QNetworkReplyWrapper class name doesn't define much it's responsibility, though I can't find a better name myself so...
> 
> This whole refactoring is awesome but it moves more tiny networking bug fixes than it may look. I think it would be better not to get this in QtWebKit 2.2 unless of course there is a clear gain and we put additional efforts to test this code.

Ok, the whole refactoring may be too much for this time but this first patch was designed to be clearly sane and to prepare the way to mime sniffing integration. Please then consider integrating this patch alone for this first time.
Comment 8 Jocelyn Turcotte 2011-03-29 05:31:42 PDT
(In reply to comment #7)
> At construction time all signals from QNetworkReply are connected to receiveMetaData and they are disconnected as soon as the first one come. The slot receiveMetaData is not used form this point on. If needed, the signals from QNetworkReply will be connected to other slots. Specifically, readyRead signal form QNetworkReply will only trigger QNetworkReplyWrapper's own readyRead signal.
> 
>  214    connect(m_reply, SIGNAL(readyRead()), this, SIGNAL(readyRead()));
>  215    connect(m_reply, SIGNAL(finished()), this, SLOT(receiveFinished()));
> 
> > - In QNetworkReplyWrapper::receiveMetaData, each time you will receive readyRead from the reply, you will do the mime type dance and emit metadataChanged. Doing it once the first time should be enough.
> 
> The slot receiveMetaData is only be used to receive the first signal from QNetwrokReply. Signal metadataChanged is emitted only once. The mime type dance will only happen exactly once.

Ahh, I missed that part, it makes more sense.
Please add a comment somewhere to highlight this.

> 
> Ok, the whole refactoring may be too much for this time but this first patch was designed to be clearly sane and to prepare the way to mime sniffing integration. Please then consider integrating this patch alone for this first time.

I have nothing against having it in trunk, as long as we are aware of the risk. In worst conditions we can revert it in the future branch.
Comment 9 Luiz Agostini 2011-03-29 11:54:07 PDT
Created attachment 87382 [details]
patch

adding the comments requested by Jocelyn.
Comment 10 Kenneth Rohde Christiansen 2011-03-29 14:29:23 PDT
Comment on attachment 87382 [details]
patch

View in context: https://bugs.webkit.org/attachment.cgi?id=87382&action=review

This is pretty readable and understandable

> Source/WebCore/ChangeLog:11
> +            2 - that signals metadatachanged and finished will will be called exactly once.

two will's there

> Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp:176
> +    disconnect(reply, 0, this, 0);

Isn't there a disconnectAll or so?

> Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp:189
> +    // this slot is only used to receive the first signal from the QNetworkReply object.

comments should start with capital - basically they should be real sentences

> Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp:207
> +        // if not finished, connect to the slots that will be used from this point on.

same here

> Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp:209
> +        connect(m_reply, SIGNAL(finished()), this, SLOT(receiveFinished()));

receive_d_Finished?

more webkit like, didReceiveFinished

> Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp:226
> +    // disconnecting will make sure that nothing will happen after emiting finished signal.

Disco...*

after emitting (two t's) THE finished signal

> Source/WebCore/platform/network/qt/QNetworkReplyHandler.h:48
> +    QUrl redirectUrl() const { return m_redirectUrl; }

I think redirectionUrl would be more correct. or redirectionTargetUrl()

> Source/WebCore/platform/network/qt/QNetworkReplyHandler.h:50
> +    QString officialMimeType() const { return m_officialMimeType; }

I don't like the official part of the name? maybe "advertisedMimeType"?
Comment 11 Kenneth Rohde Christiansen 2011-03-29 14:33:56 PDT
Have you tried measuring the performance impact of this change? I think it might be a good think to do, even though we think it won't affect it.
Comment 12 Luiz Agostini 2011-03-30 11:44:03 PDT
(In reply to comment #11)
> Have you tried measuring the performance impact of this change? I think it might be a good think to do, even though we think it won't affect it.

I have made some only simple tests with QtTestBrowser in robot mode using a master build as reference. I did not see any differences.
Comment 13 WebKit Review Bot 2011-03-30 12:26:15 PDT
http://trac.webkit.org/changeset/82478 might have broken Leopard Intel Release (Tests)
The following tests are not passing:
canvas/philip/tests/2d.text.draw.align.center.html
fast/blockflow/broken-ideographic-font.html
Comment 14 Luiz Agostini 2011-03-30 16:41:00 PDT
	M	Source/WebCore/ChangeLog
	M	Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp
	M	Source/WebCore/platform/network/qt/QNetworkReplyHandler.h
Committed r82478