Chromium Code Reviews| Index: content/browser/geofencing/geofencing_service.h |
| diff --git a/content/browser/geofencing/geofencing_service.h b/content/browser/geofencing/geofencing_service.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..91056f4412cd682947a812b10dc426ec9fa44962 |
| --- /dev/null |
| +++ b/content/browser/geofencing/geofencing_service.h |
| @@ -0,0 +1,103 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_GEOFENCING_GEOFENCING_SERVICE_H_ |
| +#define CONTENT_BROWSER_GEOFENCING_GEOFENCING_SERVICE_H_ |
| + |
| +#include <map> |
| + |
| +#include "base/basictypes.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "content/common/content_export.h" |
| +#include "content/common/geofencing_status.h" |
| + |
| +template <typename T> |
| +struct DefaultSingletonTraits; |
| + |
| +namespace blink { |
| +struct WebCircularGeofencingRegion; |
| +}; |
| + |
| +namespace content { |
| + |
| +class GeofencingProvider; |
| +class GeofencingRegistrationDelegate; |
| + |
| +// This interface exists primarily to facilitate testing of classes that depend |
| +// on GeofencingService. It defines teh interface exposed by |
|
Michael van Ouwerkerk
2014/10/21 11:46:41
Nit: the
Marijn Kruisselbrink
2014/10/21 23:50:07
Done.
|
| +// |GeofencingService|. |
| +class GeofencingServiceInterface { |
|
Michael van Ouwerkerk
2014/10/21 11:46:41
I'd prefer renaming GeofencingService to Geofencin
Marijn Kruisselbrink
2014/10/21 23:50:07
Done.
|
| + public: |
| + virtual ~GeofencingServiceInterface() {} |
| + |
| + // Returns if a geofencing service is available. |
| + virtual bool IsServiceAvailable() = 0; |
| + |
| + // Register a region. This returns a unique registration ID, and |
| + // asynchronously calls the |delegate|s RegistrationFinished method to |
| + // inform the delegate of the result of the attempt to register the region. |
| + virtual int64 RegisterRegion(const blink::WebCircularGeofencingRegion& region, |
| + GeofencingRegistrationDelegate* delegate) = 0; |
| + |
| + // Unregister a region. This is assumed to always succeed. It is safe to call |
| + // this even if a registration is still in progress. |
| + virtual void UnregisterRegion(int64 geofencing_registration_id) = 0; |
| +}; |
| + |
| +// This class combines all the geofence registrations from the various per |
| +// storage partition |GeofencingManager| instances, and registers a subset |
| +// of those fences with an underlying platform specific |GeofencingProvider|. |
| +// TODO(mek): Limit the number of geofences that are registered with the |
| +// underlying GeofencingProvider. |
| +class CONTENT_EXPORT GeofencingService |
| + : NON_EXPORTED_BASE(public GeofencingServiceInterface) { |
| + public: |
| + // Gets a pointer to the singleton instance of the geofencing service. This |
| + // must only be called on the IO thread so that the GeofencingService is |
| + // always instantiated on the same thread. Ownership is NOT returned. |
| + static GeofencingService* GetInstance(); |
| + |
| + // GeofencingServiceInterface implementation. |
| + virtual bool IsServiceAvailable() override; |
| + virtual int64 RegisterRegion( |
| + const blink::WebCircularGeofencingRegion& region, |
| + GeofencingRegistrationDelegate* delegate) override; |
| + virtual void UnregisterRegion(int64 geofencing_registration_id) override; |
| + |
| + protected: |
| + friend class GeofencingServiceTest; |
| + friend struct DefaultSingletonTraits<GeofencingService>; |
| + GeofencingService(); |
| + virtual ~GeofencingService(); |
| + |
| + void SetProviderForTests(scoped_ptr<GeofencingProvider> provider); |
|
Michael van Ouwerkerk
2014/10/21 11:46:41
nit: ForTesting - http://www.chromium.org/develope
Marijn Kruisselbrink
2014/10/21 23:50:07
The presubmit check seems to check or more tan jus
|
| + int RegistrationCountForTests(); |
|
Michael van Ouwerkerk
2014/10/21 11:46:41
And here.
Marijn Kruisselbrink
2014/10/21 23:50:07
Done.
|
| + |
| + private: |
| + struct Registration; |
| + typedef std::map<int64, Registration> RegistrationsMap; |
| + |
| + // This method checks if a |GeofencingProvider| exists, creates a new one if |
| + // not, and finally returns false if it can't create a provider for the |
| + // current platform. |
| + bool EnsureProvider(); |
| + |
| + // Returns a new unique ID to use for the next geofence registration. |
| + int64 GetNextId(); |
| + |
| + // Notifies the correct delegate that registration has completed for a |
| + // specific geofence registration. |
| + void NotifyRegistrationFinished(int64 geofencing_registration_id, |
| + GeofencingStatus status); |
| + |
| + int64 next_registration_id_; |
| + RegistrationsMap registrations_; |
| + scoped_ptr<GeofencingProvider> provider_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(GeofencingService); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_SERVICE_H_ |