[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-10851-g50815da

steveblock at google.com steveblock at google.com
Wed Dec 22 18:44:40 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit da6fa36e006cc929da4b72913ccfa578fad3064d
Author: steveblock at google.com <steveblock at google.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Fri Dec 17 02:47:06 2010 +0000

    2010-12-16  Steve Block  <steveblock at google.com>
    
            Reviewed by Steve Block.
    
            GeolocationPositionCache needs refactoring
            https://bugs.webkit.org/show_bug.cgi?id=50826
    
            No new tests, refactoring only.
    
            * page/Geolocation.cpp:
            (WebCore::Geolocation::Geolocation):
            (WebCore::Geolocation::makeCachedPositionCallbacks):
            (WebCore::Geolocation::haveSuitableCachedPosition):
            (WebCore::Geolocation::positionChangedInternal):
            * page/Geolocation.h:
            * page/GeolocationPositionCache.cpp:
            (WebCore::GeolocationPositionCache::instance):
            (WebCore::GeolocationPositionCache::GeolocationPositionCache):
            (WebCore::GeolocationPositionCache::addUser):
            (WebCore::GeolocationPositionCache::removeUser):
            (WebCore::GeolocationPositionCache::setDatabasePath):
            (WebCore::GeolocationPositionCache::setCachedPosition):
            (WebCore::GeolocationPositionCache::cachedPosition):
            (WebCore::GeolocationPositionCache::readFromDatabase):
            (WebCore::GeolocationPositionCache::writeToDatabase):
            * page/GeolocationPositionCache.h:
            (WebCore::GeolocationPositionCacheWrapper::GeolocationPositionCacheWrapper):
            (WebCore::GeolocationPositionCacheWrapper::~GeolocationPositionCacheWrapper):
            (WebCore::GeolocationPositionCacheWrapper::setCachedPosition):
            (WebCore::GeolocationPositionCacheWrapper::cachedPosition):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@74226 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 11e66f0..79493c3 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,34 @@
+2010-12-16  Steve Block  <steveblock at google.com>
+
+        Reviewed by Steve Block.
+
+        GeolocationPositionCache needs refactoring
+        https://bugs.webkit.org/show_bug.cgi?id=50826
+
+        No new tests, refactoring only.
+
+        * page/Geolocation.cpp:
+        (WebCore::Geolocation::Geolocation):
+        (WebCore::Geolocation::makeCachedPositionCallbacks):
+        (WebCore::Geolocation::haveSuitableCachedPosition):
+        (WebCore::Geolocation::positionChangedInternal):
+        * page/Geolocation.h:
+        * page/GeolocationPositionCache.cpp:
+        (WebCore::GeolocationPositionCache::instance):
+        (WebCore::GeolocationPositionCache::GeolocationPositionCache):
+        (WebCore::GeolocationPositionCache::addUser):
+        (WebCore::GeolocationPositionCache::removeUser):
+        (WebCore::GeolocationPositionCache::setDatabasePath):
+        (WebCore::GeolocationPositionCache::setCachedPosition):
+        (WebCore::GeolocationPositionCache::cachedPosition):
+        (WebCore::GeolocationPositionCache::readFromDatabase):
+        (WebCore::GeolocationPositionCache::writeToDatabase):
+        * page/GeolocationPositionCache.h:
+        (WebCore::GeolocationPositionCacheWrapper::GeolocationPositionCacheWrapper):
+        (WebCore::GeolocationPositionCacheWrapper::~GeolocationPositionCacheWrapper):
+        (WebCore::GeolocationPositionCacheWrapper::setCachedPosition):
+        (WebCore::GeolocationPositionCacheWrapper::cachedPosition):
+
 2010-12-16  Ariya Hidayat  <ariya at sencha.com>
 
         Reviewed by Andreas Kling.
diff --git a/WebCore/page/Geolocation.cpp b/WebCore/page/Geolocation.cpp
index 9c6f6d1..40f53a1 100644
--- a/WebCore/page/Geolocation.cpp
+++ b/WebCore/page/Geolocation.cpp
@@ -219,7 +219,6 @@ Geolocation::Geolocation(Frame* frame)
     , m_service(GeolocationService::create(this))
 #endif
     , m_allowGeolocation(Unknown)
-    , m_positionCache(new GeolocationPositionCache)
 {
     if (!m_frame)
         return;
@@ -358,7 +357,7 @@ void Geolocation::makeCachedPositionCallbacks()
     GeoNotifierSet::const_iterator end = m_requestsAwaitingCachedPosition.end();
     for (GeoNotifierSet::const_iterator iter = m_requestsAwaitingCachedPosition.begin(); iter != end; ++iter) {
         GeoNotifier* notifier = iter->get();
-        notifier->runSuccessCallback(m_positionCache->cachedPosition());
+        notifier->runSuccessCallback(m_positionCache.cachedPosition());
 
         // If this is a one-shot request, stop it. Otherwise, if the watch still
         // exists, start the service to get updates.
@@ -389,14 +388,14 @@ void Geolocation::requestTimedOut(GeoNotifier* notifier)
 
 bool Geolocation::haveSuitableCachedPosition(PositionOptions* options)
 {
-    if (!m_positionCache->cachedPosition())
+    if (!m_positionCache.cachedPosition())
         return false;
     if (!options->hasMaximumAge())
         return true;
     if (!options->maximumAge())
         return false;
     DOMTimeStamp currentTimeMillis = convertSecondsToDOMTimeStamp(currentTime());
-    return m_positionCache->cachedPosition()->timestamp() > currentTimeMillis - options->maximumAge();
+    return m_positionCache.cachedPosition()->timestamp() > currentTimeMillis - options->maximumAge();
 }
 
 void Geolocation::clearWatch(int watchId)
@@ -611,7 +610,7 @@ void Geolocation::requestPermission()
 
 void Geolocation::positionChangedInternal()
 {
-    m_positionCache->setCachedPosition(lastPosition());
+    m_positionCache.setCachedPosition(lastPosition());
 
     // Stop all currently running timers.
     stopTimers();
diff --git a/WebCore/page/Geolocation.h b/WebCore/page/Geolocation.h
index 306214b..2930752 100644
--- a/WebCore/page/Geolocation.h
+++ b/WebCore/page/Geolocation.h
@@ -128,6 +128,23 @@ private:
         NotifierToIdMap m_notifierToIdMap;
     };
 
+    class PositionCacheWrapper {
+    public:
+        PositionCacheWrapper()
+            : m_cache(GeolocationPositionCache::instance())
+        {
+            m_cache->addUser();
+        }
+        ~PositionCacheWrapper()
+        {
+            m_cache->removeUser();
+        }
+        void setCachedPosition(Geoposition* cachedPosition) { m_cache->setCachedPosition(cachedPosition); }
+        Geoposition* cachedPosition() { return m_cache->cachedPosition(); }
+    private:
+        GeolocationPositionCache* m_cache;
+    };
+
     bool hasListeners() const { return !m_oneShots.isEmpty() || !m_watchers.isEmpty(); }
 
     void sendError(GeoNotifierVector&, PositionError*);
@@ -189,9 +206,7 @@ private:
         No
     } m_allowGeolocation;
 
-#if ENABLE(GEOLOCATION)
-    OwnPtr<GeolocationPositionCache> m_positionCache;
-#endif
+    PositionCacheWrapper m_positionCache;
     GeoNotifierSet m_requestsAwaitingCachedPosition;
 };
     
diff --git a/WebCore/page/GeolocationPositionCache.cpp b/WebCore/page/GeolocationPositionCache.cpp
index 06159f4..9b93b03 100644
--- a/WebCore/page/GeolocationPositionCache.cpp
+++ b/WebCore/page/GeolocationPositionCache.cpp
@@ -37,55 +37,66 @@
 
 namespace WebCore {
 
-static const char* databaseName = "CachedGeoposition.db";
+static int numUsers = 0;
 
-int GeolocationPositionCache::s_instances = 0;
-RefPtr<Geoposition>* GeolocationPositionCache::s_cachedPosition;
-String* GeolocationPositionCache::s_databaseFile = 0;
+GeolocationPositionCache* GeolocationPositionCache::instance()
+{
+    DEFINE_STATIC_LOCAL(GeolocationPositionCache*, instance, (0));
+    if (!instance)
+        instance = new GeolocationPositionCache();
+    return instance;
+}
 
 GeolocationPositionCache::GeolocationPositionCache()
+    : m_haveReadFromDatabase(false)
 {
-    if (!(s_instances++)) {
-        s_cachedPosition = new RefPtr<Geoposition>;
-        *s_cachedPosition = readFromDB();
-    }
 }
 
-GeolocationPositionCache::~GeolocationPositionCache()
+void GeolocationPositionCache::addUser()
+{
+    ASSERT(numUsers >= 0);
+    ++numUsers;
+}
+
+void GeolocationPositionCache::removeUser()
+{
+    if (!(--numUsers) && m_cachedPosition)
+        writeToDatabase();
+    ASSERT(numUsers >= 0);
+}
+
+void GeolocationPositionCache::setDatabasePath(const String& path)
 {
-    if (!(--s_instances)) {
-        if (*s_cachedPosition)
-            writeToDB(s_cachedPosition->get());
-        delete s_cachedPosition;
+    static const char* databaseName = "CachedGeoposition.db";
+    String newFile = SQLiteFileSystem::appendDatabaseFileNameToPath(path, databaseName);
+    if (m_databaseFile != newFile) {
+        m_databaseFile = newFile;
+        m_haveReadFromDatabase = false;
     }
 }
 
 void GeolocationPositionCache::setCachedPosition(Geoposition* cachedPosition)
 {
-    *s_cachedPosition = cachedPosition;
+    m_cachedPosition = cachedPosition;
 }
 
 Geoposition* GeolocationPositionCache::cachedPosition()
 {
-    return s_cachedPosition->get();
+    if (!m_haveReadFromDatabase && !m_cachedPosition)
+        readFromDatabase();
+    return m_cachedPosition.get();
 }
 
-void GeolocationPositionCache::setDatabasePath(const String& databasePath)
+void GeolocationPositionCache::readFromDatabase()
 {
-    if (!s_databaseFile)
-        s_databaseFile = new String;
-    *s_databaseFile = SQLiteFileSystem::appendDatabaseFileNameToPath(databasePath, databaseName);
-    // If we don't have have a cached position, attempt to read one from the
-    // DB at the new path.
-    if (s_instances && !(*s_cachedPosition))
-        *s_cachedPosition = readFromDB();
-}
+    ASSERT(!m_haveReadFromDatabase);
+    ASSERT(!m_cachedPosition);
+
+    m_haveReadFromDatabase = true;
 
-PassRefPtr<Geoposition> GeolocationPositionCache::readFromDB()
-{
     SQLiteDatabase database;
-    if (!s_databaseFile || !database.open(*s_databaseFile))
-        return 0;
+    if (!database.open(m_databaseFile))
+        return;
 
     // Create the table here, such that even if we've just created the
     // DB, the commands below should succeed.
@@ -98,14 +109,14 @@ PassRefPtr<Geoposition> GeolocationPositionCache::readFromDB()
             "heading REAL, "
             "speed REAL, "
             "timestamp INTEGER NOT NULL)"))
-        return 0;
+        return;
 
     SQLiteStatement statement(database, "SELECT * FROM CachedPosition");
     if (statement.prepare() != SQLResultOk)
-        return 0;
+        return;
 
     if (statement.step() != SQLResultRow)
-        return 0;
+        return;
 
     bool providesAltitude = statement.getColumnValue(2).type() != SQLValue::NullValue;
     bool providesAltitudeAccuracy = statement.getColumnValue(4).type() != SQLValue::NullValue;
@@ -118,15 +129,15 @@ PassRefPtr<Geoposition> GeolocationPositionCache::readFromDB()
                                                           providesAltitudeAccuracy, statement.getColumnDouble(4), // altitudeAccuracy
                                                           providesHeading, statement.getColumnDouble(5), // heading
                                                           providesSpeed, statement.getColumnDouble(6)); // speed
-    return Geoposition::create(coordinates.release(), statement.getColumnInt64(7)); // timestamp
+    m_cachedPosition = Geoposition::create(coordinates.release(), statement.getColumnInt64(7)); // timestamp
 }
 
-void GeolocationPositionCache::writeToDB(const Geoposition* position)
+void GeolocationPositionCache::writeToDatabase()
 {
-    ASSERT(position);
+    ASSERT(m_cachedPosition);
 
     SQLiteDatabase database;
-    if (!s_databaseFile || !database.open(*s_databaseFile))
+    if (!database.open(m_databaseFile))
         return;
 
     SQLiteTransaction transaction(database);
@@ -147,26 +158,26 @@ void GeolocationPositionCache::writeToDB(const Geoposition* position)
     if (statement.prepare() != SQLResultOk)
         return;
 
-    statement.bindDouble(1, position->coords()->latitude());
-    statement.bindDouble(2, position->coords()->longitude());
-    if (position->coords()->canProvideAltitude())
-        statement.bindDouble(3, position->coords()->altitude());
+    statement.bindDouble(1, m_cachedPosition->coords()->latitude());
+    statement.bindDouble(2, m_cachedPosition->coords()->longitude());
+    if (m_cachedPosition->coords()->canProvideAltitude())
+        statement.bindDouble(3, m_cachedPosition->coords()->altitude());
     else
         statement.bindNull(3);
-    statement.bindDouble(4, position->coords()->accuracy());
-    if (position->coords()->canProvideAltitudeAccuracy())
-        statement.bindDouble(5, position->coords()->altitudeAccuracy());
+    statement.bindDouble(4, m_cachedPosition->coords()->accuracy());
+    if (m_cachedPosition->coords()->canProvideAltitudeAccuracy())
+        statement.bindDouble(5, m_cachedPosition->coords()->altitudeAccuracy());
     else
         statement.bindNull(5);
-    if (position->coords()->canProvideHeading())
-        statement.bindDouble(6, position->coords()->heading());
+    if (m_cachedPosition->coords()->canProvideHeading())
+        statement.bindDouble(6, m_cachedPosition->coords()->heading());
     else
         statement.bindNull(6);
-    if (position->coords()->canProvideSpeed())
-        statement.bindDouble(7, position->coords()->speed());
+    if (m_cachedPosition->coords()->canProvideSpeed())
+        statement.bindDouble(7, m_cachedPosition->coords()->speed());
     else
         statement.bindNull(7);
-    statement.bindInt64(8, position->timestamp());
+    statement.bindInt64(8, m_cachedPosition->timestamp());
     if (!statement.executeCommand())
         return;
 
diff --git a/WebCore/page/GeolocationPositionCache.h b/WebCore/page/GeolocationPositionCache.h
index dd57180..5053848 100644
--- a/WebCore/page/GeolocationPositionCache.h
+++ b/WebCore/page/GeolocationPositionCache.h
@@ -26,31 +26,35 @@
 #ifndef GeolocationPositionCache_h
 #define GeolocationPositionCache_h
 
+#include "PlatformString.h"
 #include <wtf/Forward.h>
 #include <wtf/PassRefPtr.h>
 #include <wtf/RefPtr.h>
 
-
 namespace WebCore {
 
 class Geoposition;
 
 class GeolocationPositionCache {
-  public:
-    GeolocationPositionCache();
-    ~GeolocationPositionCache();
+public:
+    static GeolocationPositionCache* instance();
+
+    void addUser();
+    void removeUser();
 
+    void setDatabasePath(const String&);
     void setCachedPosition(Geoposition*);
     Geoposition* cachedPosition();
-    static void setDatabasePath(const String&);
 
-  private:
-    static PassRefPtr<Geoposition> readFromDB();
-    static void writeToDB(const Geoposition*);
+private:
+    GeolocationPositionCache();
+
+    void readFromDatabase();
+    void writeToDatabase();
 
-    static int s_instances;
-    static RefPtr<Geoposition>* s_cachedPosition;
-    static String* s_databaseFile;
+    RefPtr<Geoposition> m_cachedPosition;
+    String m_databaseFile;
+    bool m_haveReadFromDatabase;
 };
 
 } // namespace WebCore

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list