Chromium Code Reviews| 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/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "content/browser/geofencing/geofencing_registration_delegate.h" | 16 #include "content/browser/geofencing/geofencing_registration_delegate.h" |
| 17 #include "content/browser/service_worker/service_worker_storage.h" | |
| 17 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 18 #include "content/common/geofencing_status.h" | 19 #include "content/common/geofencing_status.h" |
| 20 #include "content/common/service_worker/service_worker_status_code.h" | |
| 19 | 21 |
| 20 template <typename T> | 22 template <typename T> |
| 21 struct DefaultSingletonTraits; | 23 struct DefaultSingletonTraits; |
| 22 class GURL; | 24 class GURL; |
| 23 | 25 |
| 24 namespace blink { | 26 namespace blink { |
| 25 struct WebCircularGeofencingRegion; | 27 struct WebCircularGeofencingRegion; |
| 26 }; | 28 }; |
| 27 | 29 |
| 28 namespace content { | 30 namespace content { |
| 29 | 31 |
| 30 class GeofencingService; | 32 class GeofencingService; |
| 31 class ServiceWorkerContextWrapper; | 33 class ServiceWorkerContextWrapper; |
| 34 class ServiceWorkerRegistration; | |
| 32 | 35 |
| 33 // This is the main API to the geofencing subsystem. There is one instance of | 36 // This is the main API to the geofencing subsystem. There is one instance of |
| 34 // this class per storage partition. | 37 // this class per storage partition. |
| 35 // 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 |
| 36 // registered by websites/workers, persisting this list of registrations and | 39 // registered by websites/workers, persisting this list of registrations and |
| 37 // registering them with the global |GeofencingService|. | 40 // registering them with the global |GeofencingService|. |
| 38 // This class is created on the UI thread, but all its methods should only be | 41 // This class is created on the UI thread, but all its methods should only be |
| 39 // called from the IO thread. | 42 // called from the IO thread. |
| 40 // TODO(mek): Implement some kind of persistence of registrations. | 43 // TODO(mek): Implement some kind of persistence of registrations. |
| 44 // TODO(mek): Unregister a geofence when the ServiceWorkerRegistration it | |
| 45 // belongs to goes away. | |
| 41 class CONTENT_EXPORT GeofencingManager | 46 class CONTENT_EXPORT GeofencingManager |
| 42 : NON_EXPORTED_BASE(public GeofencingRegistrationDelegate), | 47 : NON_EXPORTED_BASE(public GeofencingRegistrationDelegate), |
| 43 public base::RefCountedThreadSafe<GeofencingManager> { | 48 public base::RefCountedThreadSafe<GeofencingManager> { |
| 44 public: | 49 public: |
| 45 typedef base::Callback<void(GeofencingStatus)> StatusCallback; | 50 typedef base::Callback<void(GeofencingStatus)> StatusCallback; |
| 46 | 51 |
| 47 explicit GeofencingManager( | 52 explicit GeofencingManager( |
| 48 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); | 53 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); |
| 49 | 54 |
| 50 // Init and Shutdown are for use on the UI thread when the storagepartition is | 55 // Init and Shutdown are for use on the UI thread when the storagepartition is |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 private: | 100 private: |
| 96 // Internal bookkeeping associated with each registered geofence. | 101 // Internal bookkeeping associated with each registered geofence. |
| 97 struct Registration; | 102 struct Registration; |
| 98 | 103 |
| 99 void InitOnIO(); | 104 void InitOnIO(); |
| 100 void ShutdownOnIO(); | 105 void ShutdownOnIO(); |
| 101 | 106 |
| 102 // GeofencingRegistrationDelegate implementation. | 107 // GeofencingRegistrationDelegate implementation. |
| 103 void RegistrationFinished(int64 geofencing_registration_id, | 108 void RegistrationFinished(int64 geofencing_registration_id, |
| 104 GeofencingStatus status) override; | 109 GeofencingStatus status) override; |
| 110 void RegionEntered(int64 geofencing_registration_id) override; | |
| 111 void RegionExited(int64 geofencing_registration_id) override; | |
| 105 | 112 |
| 106 // Looks up a particular geofence registration. Returns nullptr if no | 113 // Looks up a particular geofence registration. Returns nullptr if no |
| 107 // registration with the given IDs exists. | 114 // registration with the given IDs exists. |
| 108 Registration* FindRegistration(int64 service_worker_registration_id, | 115 Registration* FindRegistration(int64 service_worker_registration_id, |
| 109 const std::string& region_id); | 116 const std::string& region_id); |
| 110 | 117 |
| 111 // Looks up a particular geofence registration. Returns nullptr if no | 118 // Looks up a particular geofence registration. Returns nullptr if no |
| 112 // registration with the given ID exists. | 119 // registration with the given ID exists. |
| 113 Registration* FindRegistrationById(int64 geofencing_registration_id); | 120 Registration* FindRegistrationById(int64 geofencing_registration_id); |
| 114 | 121 |
| 115 // Registers a new registration, returning a reference to the newly inserted | 122 // Registers a new registration, returning a reference to the newly inserted |
| 116 // object. Assumes no registration with the same IDs currently exists. | 123 // object. Assumes no registration with the same IDs currently exists. |
| 117 Registration& AddRegistration( | 124 Registration& AddRegistration( |
| 118 int64 service_worker_registration_id, | 125 int64 service_worker_registration_id, |
| 119 const GURL& service_worker_origin, | 126 const GURL& service_worker_origin, |
| 120 const std::string& region_id, | 127 const std::string& region_id, |
| 121 const blink::WebCircularGeofencingRegion& region, | 128 const blink::WebCircularGeofencingRegion& region, |
| 122 const StatusCallback& callback, | 129 const StatusCallback& callback, |
| 123 int64 geofencing_registration_id); | 130 int64 geofencing_registration_id); |
| 124 | 131 |
| 125 // Clears a registration. | 132 // Clears a registration. |
| 126 void ClearRegistration(Registration* registration); | 133 void ClearRegistration(Registration* registration); |
| 127 | 134 |
| 135 void DispatchGeofencingEvent(blink::WebGeofencingEventType event_type, | |
|
Michael van Ouwerkerk
2014/10/27 15:57:40
Please document these methods. I can't tell from t
Marijn Kruisselbrink
2014/10/27 18:29:10
Done.
| |
| 136 int64 geofencing_registration_id); | |
| 137 void DeliverGeofencingEvent(blink::WebGeofencingEventType event_type, | |
| 138 int64 geofencing_registration_id, | |
| 139 ServiceWorkerStatusCode service_worker_status, | |
| 140 const scoped_refptr<ServiceWorkerRegistration>& | |
| 141 service_worker_registration); | |
| 142 void DeliverGeofencingEventEnd(const scoped_refptr<ServiceWorkerRegistration>& | |
| 143 service_worker_registration, | |
| 144 ServiceWorkerStatusCode service_worker_status); | |
| 145 | |
| 128 // Map of all registered regions for a particular service worker registration. | 146 // Map of all registered regions for a particular service worker registration. |
| 129 typedef std::map<std::string, Registration> RegionIdRegistrationMap; | 147 typedef std::map<std::string, Registration> RegionIdRegistrationMap; |
| 130 // Map of service worker registration id to the regions registered by that | 148 // Map of service worker registration id to the regions registered by that |
| 131 // service worker. | 149 // service worker. |
| 132 typedef std::map<int64, RegionIdRegistrationMap> | 150 typedef std::map<int64, RegionIdRegistrationMap> |
| 133 ServiceWorkerRegistrationsMap; | 151 ServiceWorkerRegistrationsMap; |
| 134 ServiceWorkerRegistrationsMap registrations_; | 152 ServiceWorkerRegistrationsMap registrations_; |
| 135 | 153 |
| 136 // Map of all registered regions by geofencing_registration_id. | 154 // Map of all registered regions by geofencing_registration_id. |
| 137 typedef std::map<int64, RegionIdRegistrationMap::iterator> | 155 typedef std::map<int64, RegionIdRegistrationMap::iterator> |
| 138 RegistrationIdRegistrationMap; | 156 RegistrationIdRegistrationMap; |
| 139 RegistrationIdRegistrationMap registrations_by_id_; | 157 RegistrationIdRegistrationMap registrations_by_id_; |
| 140 | 158 |
| 141 GeofencingService* service_; | 159 GeofencingService* service_; |
| 142 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | 160 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
| 143 | 161 |
| 144 DISALLOW_COPY_AND_ASSIGN(GeofencingManager); | 162 DISALLOW_COPY_AND_ASSIGN(GeofencingManager); |
| 145 }; | 163 }; |
| 146 | 164 |
| 147 } // namespace content | 165 } // namespace content |
| 148 | 166 |
| 149 #endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_MANAGER_H_ | 167 #endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_MANAGER_H_ |
| OLD | NEW |