Bug 50826 - GeolocationPositionCache needs refactoring
Summary: GeolocationPositionCache needs refactoring
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks: 50825 65289
  Show dependency treegraph
 
Reported: 2010-12-10 10:16 PST by Steve Block
Modified: 2011-07-28 07:59 PDT (History)
8 users (show)

See Also:


Attachments
Patch (12.55 KB, patch)
2010-12-10 10:48 PST, Steve Block
no flags Details | Formatted Diff | Diff
Patch (12.75 KB, patch)
2010-12-16 08:47 PST, Steve Block
no flags Details | Formatted Diff | Diff
Patch (12.75 KB, patch)
2010-12-16 13:01 PST, Steve Block
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Steve Block 2010-12-10 10:16:14 PST
Currently, Geolocation position cache uses numerous static members. Refactoring to use a single instance of the class will make the code cleaner and make it simpler to move database access to a background thread in Bug 50825.
Comment 1 Steve Block 2010-12-10 10:48:19 PST
Created attachment 76221 [details]
Patch
Comment 2 Andrei Popescu 2010-12-14 06:39:47 PST
LGTM
Comment 3 Jeremy Orlow 2010-12-16 07:12:50 PST
Comment on attachment 76221 [details]
Patch

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

overall, things are looking better

> WebCore/page/GeolocationPositionCache.cpp:44
> +    static GeolocationPositionCache* instance = 0;

I believe DEFINE_STATIC_LOCAL is preferred.

> WebCore/page/GeolocationPositionCache.cpp:46
> +        instance = new GeolocationPositionCache();

What's the webkit policy on leaking things like this?  I know we do it in some places, but I imagine it's kind of frowned upon.

I wonder if this class should instead be ref counted, be saved to some static member variable as a pointer, and then have it's destructor zero out the pointer in addition to writing to disk.  The downside is that if you then go back to a site that wants to use the cached value, it'll be a bit slower.  The upside is that it'd be cleaner in that it won't leak or require manual (and thus error prone) ref counting.

> WebCore/page/GeolocationPositionCache.cpp:87
> +    return m_cachedPosition.get();

The calling code handles null, right?

> WebCore/page/GeolocationPositionCache.cpp:90
> +void GeolocationPositionCache::readFromDatabase()

This will block the main thread, right?  That seems bad.  Can it be avoided?

> WebCore/page/GeolocationPositionCache.h:38
> +// Maintains a cached position for Geolocation.

Not sure this is necessary.

> WebCore/page/GeolocationPositionCache.h:61
> +class GeolocationPositionCacheWrapper {

This should be in its own file or a sub class

> WebCore/page/GeolocationPositionCache.h:66
> +        ASSERT(m_cache);

no need
Comment 4 Steve Block 2010-12-16 08:27:44 PST
Comment on attachment 76221 [details]
Patch

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

>> WebCore/page/GeolocationPositionCache.cpp:44
>> +    static GeolocationPositionCache* instance = 0;
> 
> I believe DEFINE_STATIC_LOCAL is preferred.

Will do

>> WebCore/page/GeolocationPositionCache.cpp:46
>> +        instance = new GeolocationPositionCache();
> 
> What's the webkit policy on leaking things like this?  I know we do it in some places, but I imagine it's kind of frowned upon.
> 
> I wonder if this class should instead be ref counted, be saved to some static member variable as a pointer, and then have it's destructor zero out the pointer in addition to writing to disk.  The downside is that if you then go back to a site that wants to use the cached value, it'll be a bit slower.  The upside is that it'd be cleaner in that it won't leak or require manual (and thus error prone) ref counting.

I think we leak plenty of small static objects like this. Personally I think that it's worth it to keep the cached position in memory.

>> WebCore/page/GeolocationPositionCache.cpp:87
>> +    return m_cachedPosition.get();
> 
> The calling code handles null, right?

Correct

>> WebCore/page/GeolocationPositionCache.cpp:90
>> +void GeolocationPositionCache::readFromDatabase()
> 
> This will block the main thread, right?  That seems bad.  Can it be avoided?

Yes, this will be done in Bug 50825, which is the motivation for this refactoring.

>> WebCore/page/GeolocationPositionCache.h:38
>> +// Maintains a cached position for Geolocation.
> 
> Not sure this is necessary.

Sure

>> WebCore/page/GeolocationPositionCache.h:61
>> +class GeolocationPositionCacheWrapper {
> 
> This should be in its own file or a sub class

Will do

>> WebCore/page/GeolocationPositionCache.h:66
>> +        ASSERT(m_cache);
> 
> no need

OK
Comment 5 Jeremy Orlow 2010-12-16 08:29:36 PST
k.  give me a new patch and i'll LGTM it
Comment 6 Steve Block 2010-12-16 08:47:38 PST
Created attachment 76773 [details]
Patch
Comment 7 Jeremy Orlow 2010-12-16 09:35:06 PST
Comment on attachment 76773 [details]
Patch

r=me
Comment 8 WebKit Commit Bot 2010-12-16 10:42:11 PST
Comment on attachment 76773 [details]
Patch

Rejecting attachment 76773 [details] from commit-queue.

Failed to run "['./WebKitTools/Scripts/webkit-patch', '--status-host=queues.webkit.org', '--bot-id=cr-jail-3', 'apply-attachment', '--non-interactive', 76773]" exit_code: 2
Last 500 characters of output:
ailed to merge in the changes.
Patch failed at 0001 2010-12-16  Yury Semikhatsky  <yurys@chromium.org>

When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To restore the original branch and stop rebasing run "git rebase --abort".

rebase refs/remotes/origin/master: command returned error: 1

Died at WebKitTools/Scripts/update-webkit line 132.

Failed to run "['WebKitTools/Scripts/update-webkit']" exit_code: 2

Full output: http://queues.webkit.org/results/7179078
Comment 9 Steve Block 2010-12-16 13:01:36 PST
Created attachment 76805 [details]
Patch
Comment 10 Steve Block 2010-12-16 17:22:07 PST
Comment on attachment 76805 [details]
Patch

rebased
Comment 11 WebKit Commit Bot 2010-12-16 18:47:25 PST
Comment on attachment 76805 [details]
Patch

Clearing flags on attachment: 76805

Committed r74226: <http://trac.webkit.org/changeset/74226>
Comment 12 WebKit Commit Bot 2010-12-16 18:47:32 PST
All reviewed patches have been landed.  Closing bug.
Comment 13 Ariya Hidayat 2010-12-16 18:51:15 PST
The name of the reviewer in the commit http://trac.webkit.org/changeset/74226 is wrong.
Comment 14 Antonio Gomes 2010-12-16 19:40:19 PST
All Qt bots (windows, minimal, arm) but linux 32bits do not seem to build after this patch:

(...)
/Qt-4.7.1/lib -L/usr/X11R6/lib -lQtNetwork -lQtCore -lpthread  
obj/release/Geolocation.o: In function `WebCore::Geolocation::~Geolocation()':
Geolocation.cpp:(.text._ZN7WebCore11GeolocationD1Ev+0x30): undefined reference to `WebCore::GeolocationPositionCache::removeUser()'
Geolocation.cpp:(.text._ZN7WebCore11GeolocationD1Ev+0x11c): undefined reference to `WebCore::GeolocationPositionCache::removeUser()'
collect2: ld returned 1 exit status
make[1]: *** [../lib/libQtWebKit.so.4.9.0] Error 1
make[1]: Leaving directory `/home/webkitbuildbot/slaves/release32bitMinimal/buildslave/qt-linux-release-minimal/build/WebKitBuild/Release/WebCore'
make: *** [sub-WebCore-make_default-ordered] Error 2
Comment 15 Jake 2010-12-16 22:38:00 PST
To get this to build locally on windows/Qt I added these #ifdefs in Geolocation.h:


    class PositionCacheWrapper {
    public:
        PositionCacheWrapper()
            : m_cache
#if ENABLE(GEOLOCATION)
			(GeolocationPositionCache::instance())
#else
			(0)
#endif
        {
#if ENABLE(GEOLOCATION)
            m_cache->addUser();
#endif
        }
        ~PositionCacheWrapper()
        {
#if ENABLE(GEOLOCATION)
			m_cache->removeUser();
#endif
        }
Comment 16 Carlos Garcia Campos 2010-12-17 00:49:40 PST
It fails to build gtk port without geolocation support too, one #ifdef was enough for me to fix it:

+#if ENABLE(GEOLOCATION)
     PositionCacheWrapper m_positionCache;
+#endif
Comment 17 Steve Block 2010-12-17 02:13:53 PST
> The name of the reviewer in the commit http://trac.webkit.org/changeset/74226
> is wrong.
Aargh. I knew I wouldn't be around to watch the build, so I wanted to commit via the commit-queue to make sure that I landed exactly the patch that had passed the try-bots. I hoped that the commit queue would be smart enough to set jorlow as reviewer. Would it have helped if I'd set him as reviewer in my patch, or would the commit-queue have overridden it anyway?

> All Qt bots (windows, minimal, arm) but linux 32bits do not seem to build after
> this patch:
Apologies. Should be fixed with http://trac.webkit.org/changeset/74240