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

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

Issue 788073007: Cleanup geofence registrations when a service worker is unregistered. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: slightly improve mock usage in test Created 6 years 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_context_observer.h"
17 #include "content/browser/service_worker/service_worker_storage.h" 18 #include "content/browser/service_worker/service_worker_storage.h"
18 #include "content/common/content_export.h" 19 #include "content/common/content_export.h"
19 #include "content/common/geofencing_types.h" 20 #include "content/common/geofencing_types.h"
20 #include "content/common/service_worker/service_worker_status_code.h" 21 #include "content/common/service_worker/service_worker_status_code.h"
21 22
22 template <typename T> 23 template <typename T>
23 struct DefaultSingletonTraits; 24 struct DefaultSingletonTraits;
24 class GURL; 25 class GURL;
25 26
26 namespace blink { 27 namespace blink {
27 struct WebCircularGeofencingRegion; 28 struct WebCircularGeofencingRegion;
28 }; 29 };
29 30
30 namespace content { 31 namespace content {
31 32
32 class GeofencingService; 33 class GeofencingService;
33 class MockGeofencingService; 34 class MockGeofencingService;
34 class ServiceWorkerContextWrapper; 35 class ServiceWorkerContextWrapper;
35 class ServiceWorkerRegistration; 36 class ServiceWorkerRegistration;
36 37
37 // This is the main API to the geofencing subsystem. There is one instance of 38 // This is the main API to the geofencing subsystem. There is one instance of
38 // this class per storage partition. 39 // this class per storage partition.
39 // This class is responsible for keeping track of which geofences are currently 40 // This class is responsible for keeping track of which geofences are currently
40 // registered by websites/workers, persisting this list of registrations and 41 // registered by websites/workers, persisting this list of registrations and
41 // registering them with the global |GeofencingService|. 42 // registering them with the global |GeofencingService|.
42 // This class is created on the UI thread, but all its methods should only be 43 // This class is created on the UI thread, but all its methods should only be
43 // called from the IO thread. 44 // called from the IO thread.
44 // TODO(mek): Implement some kind of persistence of registrations. 45 // TODO(mek): Implement some kind of persistence of registrations.
45 // TODO(mek): Unregister a geofence when the ServiceWorkerRegistration it
46 // belongs to goes away.
47 class CONTENT_EXPORT GeofencingManager 46 class CONTENT_EXPORT GeofencingManager
48 : NON_EXPORTED_BASE(public GeofencingRegistrationDelegate), 47 : NON_EXPORTED_BASE(public GeofencingRegistrationDelegate),
48 NON_EXPORTED_BASE(public ServiceWorkerContextObserver),
49 public base::RefCountedThreadSafe<GeofencingManager> { 49 public base::RefCountedThreadSafe<GeofencingManager> {
50 public: 50 public:
51 typedef base::Callback<void(GeofencingStatus)> StatusCallback; 51 typedef base::Callback<void(GeofencingStatus)> StatusCallback;
52 52
53 explicit GeofencingManager( 53 explicit GeofencingManager(
54 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context); 54 const scoped_refptr<ServiceWorkerContextWrapper>& service_worker_context);
55 55
56 // Init and Shutdown are for use on the UI thread when the storagepartition is 56 // Init and Shutdown are for use on the UI thread when the storagepartition is
57 // being setup and torn down. 57 // being setup and torn down.
58 void Init(); 58 void Init();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 friend class base::RefCountedThreadSafe<GeofencingManager>; 106 friend class base::RefCountedThreadSafe<GeofencingManager>;
107 ~GeofencingManager() override; 107 ~GeofencingManager() override;
108 108
109 private: 109 private:
110 // Internal bookkeeping associated with each registered geofence. 110 // Internal bookkeeping associated with each registered geofence.
111 struct Registration; 111 struct Registration;
112 112
113 void InitOnIO(); 113 void InitOnIO();
114 void ShutdownOnIO(); 114 void ShutdownOnIO();
115 115
116 // ServiceWorkerContextObserver implementation.
117 void OnRegistrationDeleted(int64 service_worker_registration_id,
118 const GURL& pattern) override;
119
116 // GeofencingRegistrationDelegate implementation. 120 // GeofencingRegistrationDelegate implementation.
117 void RegistrationFinished(int64 geofencing_registration_id, 121 void RegistrationFinished(int64 geofencing_registration_id,
118 GeofencingStatus status) override; 122 GeofencingStatus status) override;
119 void RegionEntered(int64 geofencing_registration_id) override; 123 void RegionEntered(int64 geofencing_registration_id) override;
120 void RegionExited(int64 geofencing_registration_id) override; 124 void RegionExited(int64 geofencing_registration_id) override;
121 125
122 // Looks up a particular geofence registration. Returns nullptr if no 126 // Looks up a particular geofence registration. Returns nullptr if no
123 // registration with the given IDs exists. 127 // registration with the given IDs exists.
124 Registration* FindRegistration(int64 service_worker_registration_id, 128 Registration* FindRegistration(int64 service_worker_registration_id,
125 const std::string& region_id); 129 const std::string& region_id);
126 130
127 // Looks up a particular geofence registration. Returns nullptr if no 131 // Looks up a particular geofence registration. Returns nullptr if no
128 // registration with the given ID exists. 132 // registration with the given ID exists.
129 Registration* FindRegistrationById(int64 geofencing_registration_id); 133 Registration* FindRegistrationById(int64 geofencing_registration_id);
130 134
131 // Registers a new registration, returning a reference to the newly inserted 135 // Registers a new registration, returning a reference to the newly inserted
132 // object. Assumes no registration with the same IDs currently exists. 136 // object. Assumes no registration with the same IDs currently exists.
133 Registration& AddRegistration( 137 Registration& AddRegistration(
134 int64 service_worker_registration_id, 138 int64 service_worker_registration_id,
135 const GURL& service_worker_origin, 139 const GURL& service_worker_origin,
136 const std::string& region_id, 140 const std::string& region_id,
137 const blink::WebCircularGeofencingRegion& region, 141 const blink::WebCircularGeofencingRegion& region,
138 const StatusCallback& callback, 142 const StatusCallback& callback,
139 int64 geofencing_registration_id); 143 int64 geofencing_registration_id);
140 144
141 // Clears a registration. 145 // Clears a registration.
142 void ClearRegistration(Registration* registration); 146 void ClearRegistration(Registration* registration);
143 147
148 // Unregisters and clears all registrations associated with a specific
149 // service worker.
150 void CleanUpForServiceWorker(int64 service_worker_registration_id);
151
144 // Starts dispatching a particular geofencing |event_type| for the geofence 152 // Starts dispatching a particular geofencing |event_type| for the geofence
145 // registration with the given ID. This first looks up the Service Worker 153 // registration with the given ID. This first looks up the Service Worker
146 // Registration the geofence is associated with, and then attempts to deliver 154 // Registration the geofence is associated with, and then attempts to deliver
147 // the event to that service worker. 155 // the event to that service worker.
148 void DispatchGeofencingEvent(blink::WebGeofencingEventType event_type, 156 void DispatchGeofencingEvent(blink::WebGeofencingEventType event_type,
149 int64 geofencing_registration_id); 157 int64 geofencing_registration_id);
150 158
151 // Delivers an event to the specified service worker for the given geofence. 159 // Delivers an event to the specified service worker for the given geofence.
152 // If the geofence registration id is no longer valid, this method does 160 // If the geofence registration id is no longer valid, this method does
153 // nothing. This assumes the |service_worker_registration| is the service 161 // nothing. This assumes the |service_worker_registration| is the service
(...skipping 26 matching lines...) Expand all
180 GeofencingService* service_; 188 GeofencingService* service_;
181 scoped_ptr<MockGeofencingService> mock_service_; 189 scoped_ptr<MockGeofencingService> mock_service_;
182 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; 190 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
183 191
184 DISALLOW_COPY_AND_ASSIGN(GeofencingManager); 192 DISALLOW_COPY_AND_ASSIGN(GeofencingManager);
185 }; 193 };
186 194
187 } // namespace content 195 } // namespace content
188 196
189 #endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_MANAGER_H_ 197 #endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_MANAGER_H_
OLDNEW
« no previous file with comments | « no previous file | content/browser/geofencing/geofencing_manager.cc » ('j') | content/browser/geofencing/geofencing_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698