Bug 59070 - [Qt] Fix QNetworkReplyWrapper to not depend on QNetworkReply::isFinished() method
Summary: [Qt] Fix QNetworkReplyWrapper to not depend on QNetworkReply::isFinished() me...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: Other OS X 10.5
: P2 Normal
Assignee: Caio Marcelo de Oliveira Filho
URL:
Keywords:
Depends on:
Blocks: 58848
  Show dependency treegraph
 
Reported: 2011-04-20 20:49 PDT by Caio Marcelo de Oliveira Filho
Modified: 2011-05-04 09:35 PDT (History)
2 users (show)

See Also:


Attachments
Patch (9.29 KB, patch)
2011-04-20 21:03 PDT, Caio Marcelo de Oliveira Filho
no flags Details | Formatted Diff | Diff
patch v2, rebased (11.19 KB, patch)
2011-04-20 21:55 PDT, Caio Marcelo de Oliveira Filho
kling: review+
Details | Formatted Diff | Diff
patch v3, using dynamic property (10.83 KB, patch)
2011-04-28 17:30 PDT, Caio Marcelo de Oliveira Filho
luiz: review-
Details | Formatted Diff | Diff
patch v4, use fact that synchronous loads are always finished (9.93 KB, patch)
2011-05-02 14:54 PDT, Caio Marcelo de Oliveira Filho
no flags Details | Formatted Diff | Diff
patch v4 (second take), use the fact that synchronous loads are always finished (9.93 KB, patch)
2011-05-02 15:00 PDT, Caio Marcelo de Oliveira Filho
kling: review+
Details | Formatted Diff | Diff
patch v5, better comment (9.94 KB, patch)
2011-05-02 17:15 PDT, Caio Marcelo de Oliveira Filho
kling: review+
eric: commit-queue-
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Caio Marcelo de Oliveira Filho 2011-04-20 20:49:06 PDT
[Qt] Fix QNetworkReplyWrapper to not depend on QNetworkReply::isFinished() method
Comment 1 Caio Marcelo de Oliveira Filho 2011-04-20 21:03:25 PDT
Created attachment 90483 [details]
Patch
Comment 2 Caio Marcelo de Oliveira Filho 2011-04-20 21:07:00 PDT
Luiz, could you take a look at this?

I've decided to make receiveMetaDataWhenFinished() to avoid depending on the order of the connections.
Comment 3 Caio Marcelo de Oliveira Filho 2011-04-20 21:55:05 PDT
Created attachment 90491 [details]
patch v2, rebased
Comment 4 Andreas Kling 2011-04-26 16:52:33 PDT
Comment on attachment 90491 [details]
patch v2, rebased

r=me. Sucky, but unavoidable.
Comment 5 Luiz Agostini 2011-04-27 21:07:46 PDT
I don't like it that much. It is too complex.

A crazy idea: why don't we take advantage of the fact that QNetworkReply is a QObject and store a dynamic property on it to keep the flag that we need?
I think that if we just create a slot in QNRW that sets that dynamic property on QNR and connect it in QNRW constructor it is done (take care to never disconnect it). The flag will be in the QNR object only (as it should) and we can avoid all other connections, parameters, flags that are replicated in two classes, ...

I don't think that it is a problem to trust on the signal emission sequence because it is a well known feature of Qt that is well documented.

Anyway, I think that with the proposed patch we might have problems with synchronous requests. Are layout tests ok?
Comment 6 Caio Marcelo de Oliveira Filho 2011-04-28 05:30:59 PDT
Luiz, thanks for looking into this :-)

(In reply to comment #5)
> I don't like it that much. It is too complex.
> 
> A crazy idea: why don't we take advantage of the fact that QNetworkReply is a QObject and store a dynamic property on it to keep the flag that we need?
> I think that if we just create a slot in QNRW that sets that dynamic property on QNR and connect it in QNRW constructor it is done (take care to never disconnect it). The flag will be in the QNR object only (as it should) and we can avoid all other connections, parameters, flags that are replicated in two classes, ...

I see your point. I will try to implement this idea today and we can see how it goes. :-)   


> I don't think that it is a problem to trust on the signal emission sequence because it is a well known feature of Qt that is well documented.

OK. I do trust the sequence, I was avoiding depend on the connect lines having to respect a strict order, but I guess a comment would be enough.


> Anyway, I think that with the proposed patch we might have problems with synchronous requests. Are layout tests ok?

What kind of problems? Both wrapper and sniffer are per-reply, so one reply will not affect others. In practice, this shouldn't change anything for non-fake replies -- which is the case for layout tests.

How can I test the synchronous requests? Do we have autotests for that or only in layout tests?
Comment 7 Caio Marcelo de Oliveira Filho 2011-04-28 16:10:37 PDT
The dynamic approach indeed looks better and avoids complicating the logic.

> > Anyway, I think that with the proposed patch we might have problems with synchronous requests. Are layout tests ok?
> 
> What kind of problems? Both wrapper and sniffer are per-reply, so one reply will not affect others. In practice, this shouldn't change anything for non-fake replies -- which is the case for layout tests.

Ok. I've found the problems, manually tracking the finished works only if we can catch the signal. That's where the fake replies heuristic of emitting finished() after a 0-timer come from, they need to give time for the  :-)

What I plan to do is to make our isFinished check both the dynamic property AND the m_reply property. This way we catch asynchronous and synchronous loads for Qt network replies, and also asynchronous loads for fake network replies.

If I understand correct, until Qt 4.8 (where we can set finished) we can't really have autotests for synchronous load with custom replies. Makes sense?

 
> How can I test the synchronous requests? Do we have autotests for that or only in layout tests?

I've found LayoutTests/http. Are there others?
Comment 8 Caio Marcelo de Oliveira Filho 2011-04-28 16:25:03 PDT
(In reply to comment #7)

> Ok. I've found the problems, manually tracking the finished works only if we can catch the signal. That's where the fake replies heuristic of emitting finished() after a 0-timer come from, they need to give time for the  :-)

...give time for the signal connections. :-)
Comment 9 Caio Marcelo de Oliveira Filho 2011-04-28 17:30:32 PDT
Created attachment 91603 [details]
patch v3, using dynamic property
Comment 10 Luiz Agostini 2011-04-29 16:03:32 PDT
Comment on attachment 91603 [details]
patch v3, using dynamic property

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

> Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp:663
> -    if (m_loadType == SynchronousLoad && m_replyWrapper->reply()->isFinished()) {
> +    if (m_loadType == SynchronousLoad && m_replyWrapper->isFinished()) {
>          m_replyWrapper->synchronousLoad();
>          // If supported, a synchronous request will be finished at this point, no need to hook up the signals.
>          return;

For synchronous requests we should call m_replyWrapper->synchronousLoad() and return anyway.
My suggestion now is that we do not check for isFinished at this point and that we call QNetworkReplyWrapper::setFinished() from QNetworkReplyWrapper::synchronousLoad().
Then we may avoid using QNetworkReply::isFinished() completely.

> Source/WebCore/platform/network/qt/QNetworkReplyHandler.h:84
> +    bool isFinished() const { return m_reply->isFinished() || m_reply->property("_q_isFinished").toBool(); }

How can we trust on QNetworkReply::isFinished()? We should have a solution that does not rely on it.

> Source/WebCore/platform/network/qt/QtMIMETypeSniffer.h:44
> +    bool isReplyFinished() const { return m_reply->isFinished() || m_reply->property("_q_isFinished").toBool(); }

The same here.
Comment 11 Caio Marcelo de Oliveira Filho 2011-05-02 14:54:33 PDT
Created attachment 91986 [details]
patch v4, use fact that synchronous loads are always finished
Comment 12 WebKit Review Bot 2011-05-02 14:56:36 PDT
Attachment 91986 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebCore/ChangeLog', u'Source/WebCor..." exit_code: 1

Source/WebCore/platform/network/qt/QNetworkReplyHandler.h:26:  Alphabetical sorting problem.  [build/include_order] [4]
Total errors found: 1 in 4 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 13 Caio Marcelo de Oliveira Filho 2011-05-02 15:00:27 PDT
Created attachment 91988 [details]
patch v4 (second take), use the fact that synchronous loads are always finished
Comment 14 Luiz Agostini 2011-05-02 15:34:54 PDT
Comment on attachment 91988 [details]
patch v4 (second take), use the fact that synchronous loads are always finished

LGTM
Comment 15 Andreas Kling 2011-05-02 16:09:14 PDT
Comment on attachment 91988 [details]
patch v4 (second take), use the fact that synchronous loads are always finished

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

> Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp:311
> +    // QNetworkReply, the QNetworkReply::isFinished() is never true, so we need to keep track

s/the//

> Source/WebCore/platform/network/qt/QNetworkReplyHandler.cpp:312
> +    // ourselves. This limitation is fixed in 4.8, but we'll still have applications that doesn't

s/doesn't/don't/
Comment 16 Caio Marcelo de Oliveira Filho 2011-05-02 17:15:29 PDT
Created attachment 92013 [details]
patch v5, better comment
Comment 17 Eric Seidel (no email) 2011-05-04 05:09:51 PDT
Comment on attachment 92013 [details]
patch v5, better comment

Rejecting attachment 92013 [details] from commit-queue.

cmarcelo@webkit.org does not have committer permissions according to http://trac.webkit.org/browser/trunk/Tools/Scripts/webkitpy/common/config/committers.py.

- If you do not have committer rights please read http://webkit.org/coding/contributing.html for instructions on how to use bugzilla flags.

- If you have committer rights please correct the error in Tools/Scripts/webkitpy/common/config/committers.py by adding yourself to the file (no review needed).  The commit-queue restarts itself every 2 hours.  After restart the commit-queue will correctly respect your committer rights.
Comment 18 Caio Marcelo de Oliveira Filho 2011-05-04 05:34:02 PDT
Commited: http://trac.webkit.org/changeset/85734