| 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/browser/service_worker/service_worker_storage.h" |
| 18 #include "content/common/content_export.h" | 18 #include "content/common/content_export.h" |
| 19 #include "content/common/geofencing_status.h" | 19 #include "content/common/geofencing_types.h" |
| 20 #include "content/common/service_worker/service_worker_status_code.h" | 20 #include "content/common/service_worker/service_worker_status_code.h" |
| 21 | 21 |
| 22 template <typename T> | 22 template <typename T> |
| 23 struct DefaultSingletonTraits; | 23 struct DefaultSingletonTraits; |
| 24 class GURL; | 24 class GURL; |
| 25 | 25 |
| 26 namespace blink { | 26 namespace blink { |
| 27 struct WebCircularGeofencingRegion; | 27 struct WebCircularGeofencingRegion; |
| 28 }; | 28 }; |
| 29 | 29 |
| 30 namespace content { | 30 namespace content { |
| 31 | 31 |
| 32 class GeofencingService; | 32 class GeofencingService; |
| 33 class MockGeofencingService; |
| 33 class ServiceWorkerContextWrapper; | 34 class ServiceWorkerContextWrapper; |
| 34 class ServiceWorkerRegistration; | 35 class ServiceWorkerRegistration; |
| 35 | 36 |
| 36 // This is the main API to the geofencing subsystem. There is one instance of | 37 // This is the main API to the geofencing subsystem. There is one instance of |
| 37 // this class per storage partition. | 38 // this class per storage partition. |
| 38 // This class is responsible for keeping track of which geofences are currently | 39 // This class is responsible for keeping track of which geofences are currently |
| 39 // registered by websites/workers, persisting this list of registrations and | 40 // registered by websites/workers, persisting this list of registrations and |
| 40 // registering them with the global |GeofencingService|. | 41 // registering them with the global |GeofencingService|. |
| 41 // This class is created on the UI thread, but all its methods should only be | 42 // This class is created on the UI thread, but all its methods should only be |
| 42 // called from the IO thread. | 43 // called from the IO thread. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 // Returns all currently registered regions. In case of failure (no geofencing | 83 // Returns all currently registered regions. In case of failure (no geofencing |
| 83 // provider available for example) return an error status, while leaving | 84 // provider available for example) return an error status, while leaving |
| 84 // |regions| untouched. | 85 // |regions| untouched. |
| 85 // This only returns regions for which the callback passed to RegisterRegion | 86 // This only returns regions for which the callback passed to RegisterRegion |
| 86 // has been called already (so it doesn't include still in progress | 87 // has been called already (so it doesn't include still in progress |
| 87 // registrations). | 88 // registrations). |
| 88 GeofencingStatus GetRegisteredRegions( | 89 GeofencingStatus GetRegisteredRegions( |
| 89 int64 service_worker_registration_id, | 90 int64 service_worker_registration_id, |
| 90 std::map<std::string, blink::WebCircularGeofencingRegion>* result); | 91 std::map<std::string, blink::WebCircularGeofencingRegion>* result); |
| 91 | 92 |
| 93 // Enables or disables mock geofencing service. |
| 94 void SetMockProvider(GeofencingMockState mock_state); |
| 95 // Set the mock geofencing position. |
| 96 void SetMockPosition(double latitude, double longitude); |
| 97 |
| 92 void SetServiceForTesting(GeofencingService* service) { | 98 void SetServiceForTesting(GeofencingService* service) { |
| 93 service_ = service; | 99 service_ = service; |
| 94 } | 100 } |
| 95 | 101 |
| 96 protected: | 102 protected: |
| 97 friend class base::RefCountedThreadSafe<GeofencingManager>; | 103 friend class base::RefCountedThreadSafe<GeofencingManager>; |
| 98 ~GeofencingManager() override; | 104 ~GeofencingManager() override; |
| 99 | 105 |
| 100 private: | 106 private: |
| 101 // Internal bookkeeping associated with each registered geofence. | 107 // Internal bookkeeping associated with each registered geofence. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 typedef std::map<int64, RegionIdRegistrationMap> | 168 typedef std::map<int64, RegionIdRegistrationMap> |
| 163 ServiceWorkerRegistrationsMap; | 169 ServiceWorkerRegistrationsMap; |
| 164 ServiceWorkerRegistrationsMap registrations_; | 170 ServiceWorkerRegistrationsMap registrations_; |
| 165 | 171 |
| 166 // Map of all registered regions by geofencing_registration_id. | 172 // Map of all registered regions by geofencing_registration_id. |
| 167 typedef std::map<int64, RegionIdRegistrationMap::iterator> | 173 typedef std::map<int64, RegionIdRegistrationMap::iterator> |
| 168 RegistrationIdRegistrationMap; | 174 RegistrationIdRegistrationMap; |
| 169 RegistrationIdRegistrationMap registrations_by_id_; | 175 RegistrationIdRegistrationMap registrations_by_id_; |
| 170 | 176 |
| 171 GeofencingService* service_; | 177 GeofencingService* service_; |
| 178 scoped_ptr<MockGeofencingService> mock_service_; |
| 172 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; | 179 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; |
| 173 | 180 |
| 174 DISALLOW_COPY_AND_ASSIGN(GeofencingManager); | 181 DISALLOW_COPY_AND_ASSIGN(GeofencingManager); |
| 175 }; | 182 }; |
| 176 | 183 |
| 177 } // namespace content | 184 } // namespace content |
| 178 | 185 |
| 179 #endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_MANAGER_H_ | 186 #endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_MANAGER_H_ |
| OLD | NEW |