Bug 48416 - IDBFactoryBackend's reference to IDBDatabaseBackend should be weak
Summary: IDBFactoryBackend's reference to IDBDatabaseBackend should be weak
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: New Bugs (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC OS X 10.5
: P2 Normal
Assignee: Jeremy Orlow
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-27 04:53 PDT by Jeremy Orlow
Modified: 2010-11-05 07:12 PDT (History)
3 users (show)

See Also:


Attachments
patch (8.11 KB, patch)
2010-10-27 04:56 PDT, Jeremy Orlow
steveblock: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jeremy Orlow 2010-10-27 04:53:28 PDT
.
Comment 1 Jeremy Orlow 2010-10-27 04:56:52 PDT
Created attachment 72011 [details]
patch
Comment 2 Andrei Popescu 2010-10-27 05:54:55 PDT
LGTM
Comment 3 Steve Block 2010-11-01 10:58:18 PDT
Comment on attachment 72011 [details]
patch

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

> WebCore/storage/IDBDatabaseBackendImpl.h:93
> +    RefPtr<IDBFactoryBackendImpl> m_factory;

You mention that the factory has the lifetime of the application. If so, why do we need to take a ref to it?
Comment 4 Jeremy Orlow 2010-11-02 04:19:26 PDT
(In reply to comment #3)
> (From update of attachment 72011 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=72011&action=review
> 
> > WebCore/storage/IDBDatabaseBackendImpl.h:93
> > +    RefPtr<IDBFactoryBackendImpl> m_factory;
> 
> You mention that the factory has the lifetime of the application. If so, why do we need to take a ref to it?

The other objects are ref counted and held by javascript.  Are we guaranteed that a GC will happen and the GC will catch _all_ references before the page group goes away?

Is there any reason to do this either?  Given that the factory is a pretty light weight object (since it only has weak references) there seems like no advantage and big disadvantages (possible security bugs) for changing this behavior.
Comment 5 Steve Block 2010-11-02 06:11:30 PDT
> The other objects are ref counted and held by javascript.  Are we guaranteed that a GC will happen and
> the GC will catch _all_ references before the page group goes away?
So you mean the factory has page lifetime? If so, that makes sense. Perhaps you could update the comment to make that clear.
Comment 6 Jeremy Orlow 2010-11-02 11:05:15 PDT
(In reply to comment #5)
> > The other objects are ref counted and held by javascript.  Are we guaranteed that a GC will happen and
> > the GC will catch _all_ references before the page group goes away?
> So you mean the factory has page lifetime? If so, that makes sense. Perhaps you could update the comment to make that clear.

No, it's page group lifetime which is a superset of the pages' lifetime.  But pages will own IDBDatabase objects.  And once the last one goes away, the IDBDatabaseBackendImpl will go to 0 which will cause the IDBFactory to clear its pointer.

Basically the case where IDBFactory could possibly go away first is on shutdown where it's not clear whether all the pages' resources (especially those owned by JavaScript) will be killed before the page group goes away.
Comment 7 Jeremy Orlow 2010-11-05 04:58:13 PDT
I can has r+?
Comment 8 Steve Block 2010-11-05 06:38:05 PDT
Comment on attachment 72011 [details]
patch

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

r=me

>>> WebCore/storage/IDBDatabaseBackendImpl.h:93
>>> +    RefPtr<IDBFactoryBackendImpl> m_factory;
>> 
>> You mention that the factory has the lifetime of the application. If so, why do we need to take a ref to it?
> 
> The other objects are ref counted and held by javascript.  Are we guaranteed that a GC will happen and the GC will catch _all_ references before the page group goes away?
> 
> Is there any reason to do this either?  Given that the factory is a pretty light weight object (since it only has weak references) there seems like no advantage and big disadvantages (possible security bugs) for changing this behavior.

OK, makes sense. I still think the comment could be more clear.
Comment 9 Jeremy Orlow 2010-11-05 06:57:45 PDT
Committed r71411: <http://trac.webkit.org/changeset/71411>
Comment 10 Jeremy Orlow 2010-11-05 07:12:19 PDT
(In reply to comment #8)
> (From update of attachment 72011 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=72011&action=review
> 
> r=me
> 
> >>> WebCore/storage/IDBDatabaseBackendImpl.h:93
> >>> +    RefPtr<IDBFactoryBackendImpl> m_factory;
> >> 
> >> You mention that the factory has the lifetime of the application. If so, why do we need to take a ref to it?
> > 
> > The other objects are ref counted and held by javascript.  Are we guaranteed that a GC will happen and the GC will catch _all_ references before the page group goes away?
> > 
> > Is there any reason to do this either?  Given that the factory is a pretty light weight object (since it only has weak references) there seems like no advantage and big disadvantages (possible security bugs) for changing this behavior.
> 
> OK, makes sense. I still think the comment could be more clear.

I added a comment.