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