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 |
(...skipping 14 matching lines...) Expand all Loading... | |
54 // always instantiated on the same thread. Ownership is NOT returned. | 59 // always instantiated on the same thread. Ownership is NOT returned. |
55 static GeofencingManager* GetInstance(); | 60 static GeofencingManager* GetInstance(); |
56 | 61 |
57 // Initiates registration of a new geofence. StatusCallback is called when | 62 // Initiates registration of a new geofence. StatusCallback is called when |
58 // registration has completed or failed (which could possibly be before | 63 // registration has completed or failed (which could possibly be before |
59 // RegisterRegion returns. | 64 // RegisterRegion returns. |
60 // Attempting to register a region with the same ID as an already registered | 65 // Attempting to register a region with the same ID as an already registered |
61 // (or in progress of being registered) region will fail. | 66 // (or in progress of being registered) region will fail. |
62 // TODO(mek): Behavior when using an already used ID might need to be revised | 67 // TODO(mek): Behavior when using an already used ID might need to be revised |
63 // depending on what the actual spec ends up saying about this. | 68 // depending on what the actual spec ends up saying about this. |
64 void RegisterRegion(BrowserContext* browser_context, | 69 void RegisterRegion(BrowserContext* browser_context, |
michaeln
2014/10/13 00:22:32
What if this is an incognito profile?
| |
65 int64 service_worker_registration_id, | 70 int64 service_worker_registration_id, |
66 const GURL& service_worker_origin, | 71 const GURL& service_worker_origin, |
67 const std::string& region_id, | 72 const std::string& region_id, |
68 const blink::WebCircularGeofencingRegion& region, | 73 const blink::WebCircularGeofencingRegion& region, |
69 const StatusCallback& callback); | 74 const StatusCallback& callback); |
70 | 75 |
71 // Unregister a region that was previously registered by a call to | 76 // Unregister a region that was previously registered by a call to |
72 // RegisterRegion. Any attempt to unregister a region that has not been | 77 // RegisterRegion. Any attempt to unregister a region that has not been |
73 // registered, or for which the registration is still in progress | 78 // registered, or for which the registration is still in progress |
74 // (RegisterRegion hasn't called its callback yet) will fail. | 79 // (RegisterRegion hasn't called its callback yet) will fail. |
(...skipping 10 matching lines...) Expand all Loading... | |
85 // |regions| untouched. | 90 // |regions| untouched. |
86 // This only returns regions for which the callback passed to RegisterRegion | 91 // This only returns regions for which the callback passed to RegisterRegion |
87 // has been called already (so it doesn't include still in progress | 92 // has been called already (so it doesn't include still in progress |
88 // registrations). | 93 // registrations). |
89 GeofencingStatus GetRegisteredRegions( | 94 GeofencingStatus GetRegisteredRegions( |
90 BrowserContext* browser_context, | 95 BrowserContext* browser_context, |
91 int64 service_worker_registration_id, | 96 int64 service_worker_registration_id, |
92 const GURL& service_worker_origin, | 97 const GURL& service_worker_origin, |
93 std::map<std::string, blink::WebCircularGeofencingRegion>* regions); | 98 std::map<std::string, blink::WebCircularGeofencingRegion>* regions); |
94 | 99 |
100 // To be called by GeofencingProvider | |
101 void RegionEntered(int provider_id); | |
102 void RegionExited(int provider_id); | |
103 | |
95 void SetProviderForTests(scoped_ptr<GeofencingProvider> provider); | 104 void SetProviderForTests(scoped_ptr<GeofencingProvider> provider); |
96 | 105 |
97 protected: | 106 protected: |
98 friend struct DefaultSingletonTraits<GeofencingManager>; | 107 friend struct DefaultSingletonTraits<GeofencingManager>; |
99 friend class GeofencingManagerTest; | 108 friend class GeofencingManagerTest; |
100 GeofencingManager(); | 109 GeofencingManager(); |
101 virtual ~GeofencingManager(); | 110 virtual ~GeofencingManager(); |
102 | 111 |
103 private: | 112 private: |
104 // Internal bookkeeping associated with each registered geofence. | 113 // Internal bookkeeping associated with each registered geofence. |
(...skipping 14 matching lines...) Expand all Loading... | |
119 | 128 |
120 // Registers a new registration, returning a reference to the newly inserted | 129 // Registers a new registration, returning a reference to the newly inserted |
121 // object. Assumes no registration with the same IDs currently exists. | 130 // object. Assumes no registration with the same IDs currently exists. |
122 Registration& AddRegistration( | 131 Registration& AddRegistration( |
123 const RegistrationKey& key, | 132 const RegistrationKey& key, |
124 const blink::WebCircularGeofencingRegion& region); | 133 const blink::WebCircularGeofencingRegion& region); |
125 | 134 |
126 // Clears a registration. | 135 // Clears a registration. |
127 void ClearRegistration(const RegistrationKey& key); | 136 void ClearRegistration(const RegistrationKey& key); |
128 | 137 |
138 // Finds a registration given the ID it is registered with by the provider. | |
139 Registration* FindRegistrationByProviderId(int provider_id); | |
140 | |
141 void DispatchGeofencingEvent(blink::WebGeofencingEventType event_type, | |
142 int provider_id); | |
143 | |
129 // List of all currently registered geofences. | 144 // List of all currently registered geofences. |
130 // TODO(mek): Better way of storing these that allows more efficient lookup | 145 // TODO(mek): Better way of storing these that allows more efficient lookup |
131 // and deletion. | 146 // and deletion. |
132 std::vector<Registration> registrations_; | 147 std::vector<Registration> registrations_; |
133 | 148 |
134 scoped_ptr<GeofencingProvider> provider_; | 149 scoped_ptr<GeofencingProvider> provider_; |
135 | 150 |
136 DISALLOW_COPY_AND_ASSIGN(GeofencingManager); | 151 DISALLOW_COPY_AND_ASSIGN(GeofencingManager); |
137 }; | 152 }; |
138 | 153 |
139 } // namespace content | 154 } // namespace content |
140 | 155 |
141 #endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_MANAGER_H_ | 156 #endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_MANAGER_H_ |
OLD | NEW |