diff options
author | Steve Block <steveblock@google.com> | 2009-08-18 15:56:54 +0100 |
---|---|---|
committer | Steve Block <steveblock@google.com> | 2009-08-19 22:43:23 +0100 |
commit | 666ce90734aced48a6dbbce4b87ae20b6f32d065 (patch) | |
tree | af343df649628f3d76e5e9257d155926fefcc32e /WebCore | |
parent | d2b4b46e864b9002fee625c0a6c65955e4f4d92c (diff) | |
download | external_webkit-666ce90734aced48a6dbbce4b87ae20b6f32d065.zip external_webkit-666ce90734aced48a6dbbce4b87ae20b6f32d065.tar.gz external_webkit-666ce90734aced48a6dbbce4b87ae20b6f32d065.tar.bz2 |
Update MockGeolocationService to avoid the use of static initializers with constructors, as required by WebKit.
Diffstat (limited to 'WebCore')
-rwxr-xr-x | WebCore/platform/MockGeolocationService.cpp | 53 | ||||
-rwxr-xr-x | WebCore/platform/MockGeolocationService.h | 13 |
2 files changed, 46 insertions, 20 deletions
diff --git a/WebCore/platform/MockGeolocationService.cpp b/WebCore/platform/MockGeolocationService.cpp index 481d588..c6d807c 100755 --- a/WebCore/platform/MockGeolocationService.cpp +++ b/WebCore/platform/MockGeolocationService.cpp @@ -32,12 +32,13 @@ namespace WebCore { -MockGeolocationService::MockGeolocationServiceSet MockGeolocationService::s_instances; -RefPtr<Geoposition> MockGeolocationService::s_lastPosition = 0; -RefPtr<PositionError> MockGeolocationService::s_lastError = 0; +MockGeolocationService::MockGeolocationServiceSet* MockGeolocationService::s_instances = 0; +RefPtr<Geoposition>* MockGeolocationService::s_lastPosition; +RefPtr<PositionError>* MockGeolocationService::s_lastError; GeolocationService* MockGeolocationService::create(GeolocationServiceClient* client) { + initStatics(); return new MockGeolocationService(client); } @@ -45,27 +46,30 @@ MockGeolocationService::MockGeolocationService(GeolocationServiceClient* client) : GeolocationService(client) , m_timer(this, &MockGeolocationService::timerFired) { - s_instances.add(this); + s_instances->add(this); } MockGeolocationService::~MockGeolocationService() { - MockGeolocationServiceSet::iterator iter = s_instances.find(this); - ASSERT(iter != s_instances.end()); - s_instances.remove(iter); + MockGeolocationServiceSet::iterator iter = s_instances->find(this); + ASSERT(iter != s_instances->end()); + s_instances->remove(iter); + cleanUpStatics(); } void MockGeolocationService::setPosition(PassRefPtr<Geoposition> position) { - s_lastPosition = position; - s_lastError = 0; + initStatics(); + *s_lastPosition = position; + *s_lastError = 0; makeGeolocationCallbackFromAllInstances(); } void MockGeolocationService::setError(PassRefPtr<PositionError> error) { - s_lastError = error; - s_lastPosition = 0; + initStatics(); + *s_lastError = error; + *s_lastPosition = 0; makeGeolocationCallbackFromAllInstances(); } @@ -83,8 +87,8 @@ void MockGeolocationService::timerFired(Timer<MockGeolocationService>* timer) void MockGeolocationService::makeGeolocationCallbackFromAllInstances() { - MockGeolocationServiceSet::const_iterator end = s_instances.end(); - for (MockGeolocationServiceSet::const_iterator iter = s_instances.begin(); + MockGeolocationServiceSet::const_iterator end = s_instances->end(); + for (MockGeolocationServiceSet::const_iterator iter = s_instances->begin(); iter != end; ++iter) { (*iter)->makeGeolocationCallback(); @@ -93,11 +97,30 @@ void MockGeolocationService::makeGeolocationCallbackFromAllInstances() void MockGeolocationService::makeGeolocationCallback() { - if (s_lastPosition) { + if (*s_lastPosition) { positionChanged(); - } else if (s_lastError) { + } else if (*s_lastError) { errorOccurred(); } } +void MockGeolocationService::initStatics() +{ + if (s_instances == 0) { + s_instances = new MockGeolocationServiceSet; + s_lastPosition = new RefPtr<Geoposition>; + s_lastError = new RefPtr<PositionError>; + } +} + +void MockGeolocationService::cleanUpStatics() +{ + if (s_instances->size() == 0) { + delete s_instances; + s_instances = 0; + delete s_lastPosition; + delete s_lastError; + } +} + } // namespace WebCore diff --git a/WebCore/platform/MockGeolocationService.h b/WebCore/platform/MockGeolocationService.h index 0a1ef11..6f05168 100755 --- a/WebCore/platform/MockGeolocationService.h +++ b/WebCore/platform/MockGeolocationService.h @@ -51,8 +51,8 @@ class MockGeolocationService : public GeolocationService { static void setPosition(PassRefPtr<Geoposition> position); static void setError(PassRefPtr<PositionError> position); - virtual Geoposition* lastPosition() const { return s_lastPosition.get(); } - virtual PositionError* lastError() const { return s_lastError.get(); } + virtual Geoposition* lastPosition() const { return s_lastPosition->get(); } + virtual PositionError* lastError() const { return s_lastError->get(); } private: static void makeGeolocationCallbackFromAllInstances(); @@ -60,11 +60,14 @@ class MockGeolocationService : public GeolocationService { void timerFired(Timer<MockGeolocationService>*); - static RefPtr<Geoposition> s_lastPosition; - static RefPtr<PositionError> s_lastError; + static void initStatics(); + static void cleanUpStatics(); + + static RefPtr<Geoposition>* s_lastPosition; + static RefPtr<PositionError>* s_lastError; typedef HashSet<MockGeolocationService*> MockGeolocationServiceSet; - static MockGeolocationServiceSet s_instances; + static MockGeolocationServiceSet* s_instances; Timer<MockGeolocationService> m_timer; }; |