Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CONTENT_BROWSER_GEOFENCING_GEOFENCING_SERVICE_H_ | |
| 6 #define CONTENT_BROWSER_GEOFENCING_GEOFENCING_SERVICE_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "content/common/content_export.h" | |
| 13 #include "content/common/geofencing_status.h" | |
| 14 | |
| 15 template <typename T> | |
| 16 struct DefaultSingletonTraits; | |
| 17 | |
| 18 namespace blink { | |
| 19 struct WebCircularGeofencingRegion; | |
| 20 }; | |
| 21 | |
| 22 namespace content { | |
| 23 | |
| 24 class GeofencingProvider; | |
| 25 class GeofencingRegistrationDelegate; | |
| 26 | |
| 27 // This interface exists primarily to facilitate testing of classes that depend | |
| 28 // 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.
| |
| 29 // |GeofencingService|. | |
| 30 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.
| |
| 31 public: | |
| 32 virtual ~GeofencingServiceInterface() {} | |
| 33 | |
| 34 // Returns if a geofencing service is available. | |
| 35 virtual bool IsServiceAvailable() = 0; | |
| 36 | |
| 37 // Register a region. This returns a unique registration ID, and | |
| 38 // asynchronously calls the |delegate|s RegistrationFinished method to | |
| 39 // inform the delegate of the result of the attempt to register the region. | |
| 40 virtual int64 RegisterRegion(const blink::WebCircularGeofencingRegion& region, | |
| 41 GeofencingRegistrationDelegate* delegate) = 0; | |
| 42 | |
| 43 // Unregister a region. This is assumed to always succeed. It is safe to call | |
| 44 // this even if a registration is still in progress. | |
| 45 virtual void UnregisterRegion(int64 geofencing_registration_id) = 0; | |
| 46 }; | |
| 47 | |
| 48 // This class combines all the geofence registrations from the various per | |
| 49 // storage partition |GeofencingManager| instances, and registers a subset | |
| 50 // of those fences with an underlying platform specific |GeofencingProvider|. | |
| 51 // TODO(mek): Limit the number of geofences that are registered with the | |
| 52 // underlying GeofencingProvider. | |
| 53 class CONTENT_EXPORT GeofencingService | |
| 54 : NON_EXPORTED_BASE(public GeofencingServiceInterface) { | |
| 55 public: | |
| 56 // Gets a pointer to the singleton instance of the geofencing service. This | |
| 57 // must only be called on the IO thread so that the GeofencingService is | |
| 58 // always instantiated on the same thread. Ownership is NOT returned. | |
| 59 static GeofencingService* GetInstance(); | |
| 60 | |
| 61 // GeofencingServiceInterface implementation. | |
| 62 virtual bool IsServiceAvailable() override; | |
| 63 virtual int64 RegisterRegion( | |
| 64 const blink::WebCircularGeofencingRegion& region, | |
| 65 GeofencingRegistrationDelegate* delegate) override; | |
| 66 virtual void UnregisterRegion(int64 geofencing_registration_id) override; | |
| 67 | |
| 68 protected: | |
| 69 friend class GeofencingServiceTest; | |
| 70 friend struct DefaultSingletonTraits<GeofencingService>; | |
| 71 GeofencingService(); | |
| 72 virtual ~GeofencingService(); | |
| 73 | |
| 74 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
| |
| 75 int RegistrationCountForTests(); | |
|
Michael van Ouwerkerk
2014/10/21 11:46:41
And here.
Marijn Kruisselbrink
2014/10/21 23:50:07
Done.
| |
| 76 | |
| 77 private: | |
| 78 struct Registration; | |
| 79 typedef std::map<int64, Registration> RegistrationsMap; | |
| 80 | |
| 81 // This method checks if a |GeofencingProvider| exists, creates a new one if | |
| 82 // not, and finally returns false if it can't create a provider for the | |
| 83 // current platform. | |
| 84 bool EnsureProvider(); | |
| 85 | |
| 86 // Returns a new unique ID to use for the next geofence registration. | |
| 87 int64 GetNextId(); | |
| 88 | |
| 89 // Notifies the correct delegate that registration has completed for a | |
| 90 // specific geofence registration. | |
| 91 void NotifyRegistrationFinished(int64 geofencing_registration_id, | |
| 92 GeofencingStatus status); | |
| 93 | |
| 94 int64 next_registration_id_; | |
| 95 RegistrationsMap registrations_; | |
| 96 scoped_ptr<GeofencingProvider> provider_; | |
| 97 | |
| 98 DISALLOW_COPY_AND_ASSIGN(GeofencingService); | |
| 99 }; | |
| 100 | |
| 101 } // namespace content | |
| 102 | |
| 103 #endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_SERVICE_H_ | |
| OLD | NEW |