| 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_MANAGER_H_ | 5 #ifndef CONTENT_BROWSER_GEOFENCING_GEOFENCING_MANAGER_H_ |
| 6 #define CONTENT_BROWSER_GEOFENCING_GEOFENCING_MANAGER_H_ | 6 #define CONTENT_BROWSER_GEOFENCING_GEOFENCING_MANAGER_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/callback_forward.h" | 12 #include "base/callback_forward.h" |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "content/browser/service_worker/service_worker_storage.h" |
| 15 #include "content/common/content_export.h" | 17 #include "content/common/content_export.h" |
| 16 #include "content/common/geofencing_status.h" | 18 #include "content/common/geofencing_status.h" |
| 19 #include "content/common/service_worker/service_worker_status_code.h" |
| 17 | 20 |
| 18 template <typename T> | 21 template <typename T> |
| 19 struct DefaultSingletonTraits; | 22 struct DefaultSingletonTraits; |
| 20 class GURL; | 23 class GURL; |
| 21 | 24 |
| 22 namespace blink { | 25 namespace blink { |
| 23 struct WebCircularGeofencingRegion; | 26 struct WebCircularGeofencingRegion; |
| 24 }; | 27 }; |
| 25 | 28 |
| 26 namespace content { | 29 namespace content { |
| 27 | 30 |
| 28 class BrowserContext; | 31 class BrowserContext; |
| 29 class GeofencingProvider; | 32 class GeofencingProvider; |
| 33 class ServiceWorkerContextWrapper; |
| 34 class ServiceWorkerRegistration; |
| 30 | 35 |
| 31 // This is the main API to the geofencing subsystem. The application will hold | 36 // This is the main API to the geofencing subsystem. The application will hold |
| 32 // a single instance of this class. | 37 // a single instance of this class. |
| 33 // This class is responsible for keeping track of which geofences are currently | 38 // This class is responsible for keeping track of which geofences are currently |
| 34 // registered by websites/workers, persisting this list of registrations and | 39 // registered by websites/workers, persisting this list of registrations and |
| 35 // registering a subset of these active registrations with the underlying | 40 // registering a subset of these active registrations with the underlying |
| 36 // platform specific |GeofencingProvider| instance. | 41 // platform specific |GeofencingProvider| instance. |
| 37 // This class lives on the IO thread, and all public methods of it should only | 42 // This class lives on the IO thread, and all public methods of it should only |
| 38 // ever be called from that same thread. | 43 // ever be called from that same thread. |
| 39 // FIXME: Does it make more sense for this to live on the UI thread instead of | 44 // FIXME: Does it make more sense for this to live on the UI thread instead of |
| 40 // the IO thread? | 45 // the IO thread? |
| 41 // TODO(mek): Implement some kind of persistence of registrations. | 46 // TODO(mek): Implement some kind of persistence of registrations. |
| 42 // TODO(mek): Limit the number of geofences that are registered with the | 47 // TODO(mek): Limit the number of geofences that are registered with the |
| 43 // underlying GeofencingProvider. | 48 // underlying GeofencingProvider. |
| 49 // TODO(mek): Unregister a geofence when the ServiceWorkerRegistration it |
| 50 // belongs to goes away. |
| 51 // TODO(mek): If not included in the above, make sure a BrowserContext going |
| 52 // away is also dealt with appropriately. |
| 44 class CONTENT_EXPORT GeofencingManager { | 53 class CONTENT_EXPORT GeofencingManager { |
| 45 public: | 54 public: |
| 46 typedef base::Callback<void(GeofencingStatus)> StatusCallback; | 55 typedef base::Callback<void(GeofencingStatus)> StatusCallback; |
| 47 typedef base::Callback<void( | 56 typedef base::Callback<void( |
| 48 GeofencingStatus, | 57 GeofencingStatus, |
| 49 const std::map<std::string, blink::WebCircularGeofencingRegion>&)> | 58 const std::map<std::string, blink::WebCircularGeofencingRegion>&)> |
| 50 RegistrationsCallback; | 59 RegistrationsCallback; |
| 51 | 60 |
| 52 // Gets a pointer to the singleton instance of the geofencing manager. This | 61 // Gets a pointer to the singleton instance of the geofencing manager. This |
| 53 // must only be called on the IO thread so that the GeofencingManager is | 62 // must only be called on the IO thread so that the GeofencingManager is |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // |regions| untouched. | 94 // |regions| untouched. |
| 86 // This only returns regions for which the callback passed to RegisterRegion | 95 // This only returns regions for which the callback passed to RegisterRegion |
| 87 // has been called already (so it doesn't include still in progress | 96 // has been called already (so it doesn't include still in progress |
| 88 // registrations). | 97 // registrations). |
| 89 GeofencingStatus GetRegisteredRegions( | 98 GeofencingStatus GetRegisteredRegions( |
| 90 BrowserContext* browser_context, | 99 BrowserContext* browser_context, |
| 91 int64 service_worker_registration_id, | 100 int64 service_worker_registration_id, |
| 92 const GURL& service_worker_origin, | 101 const GURL& service_worker_origin, |
| 93 std::map<std::string, blink::WebCircularGeofencingRegion>* regions); | 102 std::map<std::string, blink::WebCircularGeofencingRegion>* regions); |
| 94 | 103 |
| 104 // To be called by GeofencingProvider |
| 105 void RegionEntered(int provider_id); |
| 106 void RegionExited(int provider_id); |
| 107 |
| 95 void SetProviderForTests(scoped_ptr<GeofencingProvider> provider); | 108 void SetProviderForTests(scoped_ptr<GeofencingProvider> provider); |
| 96 | 109 |
| 97 protected: | 110 protected: |
| 98 friend struct DefaultSingletonTraits<GeofencingManager>; | 111 friend struct DefaultSingletonTraits<GeofencingManager>; |
| 99 friend class GeofencingManagerTest; | 112 friend class GeofencingManagerTest; |
| 100 GeofencingManager(); | 113 GeofencingManager(); |
| 101 virtual ~GeofencingManager(); | 114 virtual ~GeofencingManager(); |
| 102 | 115 |
| 103 private: | 116 private: |
| 104 // Internal bookkeeping associated with each registered geofence. | 117 // Internal bookkeeping associated with each registered geofence. |
| (...skipping 14 matching lines...) Expand all Loading... |
| 119 | 132 |
| 120 // Registers a new registration, returning a reference to the newly inserted | 133 // Registers a new registration, returning a reference to the newly inserted |
| 121 // object. Assumes no registration with the same IDs currently exists. | 134 // object. Assumes no registration with the same IDs currently exists. |
| 122 Registration& AddRegistration( | 135 Registration& AddRegistration( |
| 123 const RegistrationKey& key, | 136 const RegistrationKey& key, |
| 124 const blink::WebCircularGeofencingRegion& region); | 137 const blink::WebCircularGeofencingRegion& region); |
| 125 | 138 |
| 126 // Clears a registration. | 139 // Clears a registration. |
| 127 void ClearRegistration(const RegistrationKey& key); | 140 void ClearRegistration(const RegistrationKey& key); |
| 128 | 141 |
| 142 // Finds a registration given the ID it is registered with by the provider. |
| 143 Registration* FindRegistrationByProviderId(int provider_id); |
| 144 |
| 145 void DispatchGeofencingEvent(blink::WebGeofencingEventType event_type, |
| 146 int provider_id); |
| 147 |
| 129 // List of all currently registered geofences. | 148 // List of all currently registered geofences. |
| 130 // TODO(mek): Better way of storing these that allows more efficient lookup | 149 // TODO(mek): Better way of storing these that allows more efficient lookup |
| 131 // and deletion. | 150 // and deletion. |
| 132 std::vector<Registration> registrations_; | 151 std::vector<Registration> registrations_; |
| 133 | 152 |
| 134 scoped_ptr<GeofencingProvider> provider_; | 153 scoped_ptr<GeofencingProvider> provider_; |
| 135 | 154 |
| 136 DISALLOW_COPY_AND_ASSIGN(GeofencingManager); | 155 DISALLOW_COPY_AND_ASSIGN(GeofencingManager); |
| 137 }; | 156 }; |
| 138 | 157 |
| 139 } // namespace content | 158 } // namespace content |
| 140 | 159 |
| 141 #endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_MANAGER_H_ | 160 #endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_MANAGER_H_ |
| OLD | NEW |