Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(72)

Side by Side Diff: content/browser/geofencing/geofencing_manager.h

Issue 629393002: Chromium side of geofencing event dispatching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@geofencing_serviceworker
Patch Set: address comments Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Starts dispatching a particular geofencing |event_type| for the geofence
136 // registration with the given ID. This first looks up the Service Worker
137 // Registration the geofence is associated with, and then attempts to deliver
138 // the event to that service worker.
139 void DispatchGeofencingEvent(blink::WebGeofencingEventType event_type,
140 int64 geofencing_registration_id);
141
142 // Delivers an event to the specified service worker for the given geofence.
143 // If the geofence registration id is no longer valid, this method does
144 // nothing. This assumes the |service_worker_registration| is the service
145 // worker the geofence registration is associated with.
146 void DeliverGeofencingEvent(blink::WebGeofencingEventType event_type,
147 int64 geofencing_registration_id,
148 ServiceWorkerStatusCode service_worker_status,
149 const scoped_refptr<ServiceWorkerRegistration>&
150 service_worker_registration);
151
152 // Called when delivering of a geofence event to a service worker has finished
palmer 2014/10/27 22:27:36 Nit: "...when delivery of..."
Marijn Kruisselbrink 2014/10/29 17:31:28 Done.
153 // (or failed to finish).
154 void DeliverGeofencingEventEnd(const scoped_refptr<ServiceWorkerRegistration>&
155 service_worker_registration,
156 ServiceWorkerStatusCode service_worker_status);
157
128 // Map of all registered regions for a particular service worker registration. 158 // Map of all registered regions for a particular service worker registration.
129 typedef std::map<std::string, Registration> RegionIdRegistrationMap; 159 typedef std::map<std::string, Registration> RegionIdRegistrationMap;
130 // Map of service worker registration id to the regions registered by that 160 // Map of service worker registration id to the regions registered by that
131 // service worker. 161 // service worker.
132 typedef std::map<int64, RegionIdRegistrationMap> 162 typedef std::map<int64, RegionIdRegistrationMap>
133 ServiceWorkerRegistrationsMap; 163 ServiceWorkerRegistrationsMap;
134 ServiceWorkerRegistrationsMap registrations_; 164 ServiceWorkerRegistrationsMap registrations_;
135 165
136 // Map of all registered regions by geofencing_registration_id. 166 // Map of all registered regions by geofencing_registration_id.
137 typedef std::map<int64, RegionIdRegistrationMap::iterator> 167 typedef std::map<int64, RegionIdRegistrationMap::iterator>
138 RegistrationIdRegistrationMap; 168 RegistrationIdRegistrationMap;
139 RegistrationIdRegistrationMap registrations_by_id_; 169 RegistrationIdRegistrationMap registrations_by_id_;
140 170
141 GeofencingService* service_; 171 GeofencingService* service_;
142 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; 172 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
143 173
144 DISALLOW_COPY_AND_ASSIGN(GeofencingManager); 174 DISALLOW_COPY_AND_ASSIGN(GeofencingManager);
145 }; 175 };
146 176
147 } // namespace content 177 } // namespace content
148 178
149 #endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_MANAGER_H_ 179 #endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698