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

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

Issue 701953007: Expose mock geofencing service via testRunner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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/linked_ptr.h"
14 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
16 #include "content/browser/geofencing/geofencing_registration_delegate.h" 17 #include "content/browser/geofencing/geofencing_registration_delegate.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_status.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;
34 class MockGeofencingService;
33 class ServiceWorkerContextWrapper; 35 class ServiceWorkerContextWrapper;
34 class ServiceWorkerRegistration; 36 class ServiceWorkerRegistration;
35 37
36 // 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
37 // this class per storage partition. 39 // this class per storage partition.
38 // 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
39 // registered by websites/workers, persisting this list of registrations and 41 // registered by websites/workers, persisting this list of registrations and
40 // registering them with the global |GeofencingService|. 42 // registering them with the global |GeofencingService|.
41 // 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
42 // called from the IO thread. 44 // called from the IO thread.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 // Returns all currently registered regions. In case of failure (no geofencing 84 // Returns all currently registered regions. In case of failure (no geofencing
83 // provider available for example) return an error status, while leaving 85 // provider available for example) return an error status, while leaving
84 // |regions| untouched. 86 // |regions| untouched.
85 // This only returns regions for which the callback passed to RegisterRegion 87 // This only returns regions for which the callback passed to RegisterRegion
86 // has been called already (so it doesn't include still in progress 88 // has been called already (so it doesn't include still in progress
87 // registrations). 89 // registrations).
88 GeofencingStatus GetRegisteredRegions( 90 GeofencingStatus GetRegisteredRegions(
89 int64 service_worker_registration_id, 91 int64 service_worker_registration_id,
90 std::map<std::string, blink::WebCircularGeofencingRegion>* result); 92 std::map<std::string, blink::WebCircularGeofencingRegion>* result);
91 93
94 void SetMockProvider(int64 service_worker_registration_id,
95 GeofencingMockState mock_state);
96 void SetMockPosition(int64 service_worker_registration_id,
97 double latitude,
98 double longitude);
99
92 void SetServiceForTesting(GeofencingService* service) { 100 void SetServiceForTesting(GeofencingService* service) {
93 service_ = service; 101 service_ = service;
94 } 102 }
95 103
96 protected: 104 protected:
97 friend class base::RefCountedThreadSafe<GeofencingManager>; 105 friend class base::RefCountedThreadSafe<GeofencingManager>;
98 ~GeofencingManager() override; 106 ~GeofencingManager() override;
99 107
100 private: 108 private:
101 // Internal bookkeeping associated with each registered geofence. 109 // Internal bookkeeping associated with each registered geofence.
102 struct Registration; 110 struct Registration;
103 111
104 void InitOnIO(); 112 void InitOnIO();
105 void ShutdownOnIO(); 113 void ShutdownOnIO();
106 114
107 // GeofencingRegistrationDelegate implementation. 115 // GeofencingRegistrationDelegate implementation.
108 void RegistrationFinished(int64 geofencing_registration_id, 116 void RegistrationFinished(int64 geofencing_registration_id,
109 GeofencingStatus status) override; 117 GeofencingStatus status) override;
110 void RegionEntered(int64 geofencing_registration_id) override; 118 void RegionEntered(int64 geofencing_registration_id) override;
111 void RegionExited(int64 geofencing_registration_id) override; 119 void RegionExited(int64 geofencing_registration_id) override;
112 120
121 GeofencingService* ServiceForServiceWorker(
122 int64 service_worker_registration_id);
123
113 // Looks up a particular geofence registration. Returns nullptr if no 124 // Looks up a particular geofence registration. Returns nullptr if no
114 // registration with the given IDs exists. 125 // registration with the given IDs exists.
115 Registration* FindRegistration(int64 service_worker_registration_id, 126 Registration* FindRegistration(int64 service_worker_registration_id,
116 const std::string& region_id); 127 const std::string& region_id);
117 128
118 // Looks up a particular geofence registration. Returns nullptr if no 129 // Looks up a particular geofence registration. Returns nullptr if no
119 // registration with the given ID exists. 130 // registration with the given ID exists.
120 Registration* FindRegistrationById(int64 geofencing_registration_id); 131 Registration* FindRegistrationById(int64 geofencing_registration_id);
121 132
122 // Registers a new registration, returning a reference to the newly inserted 133 // Registers a new registration, returning a reference to the newly inserted
123 // object. Assumes no registration with the same IDs currently exists. 134 // object. Assumes no registration with the same IDs currently exists.
124 Registration& AddRegistration( 135 Registration& AddRegistration(
125 int64 service_worker_registration_id, 136 int64 service_worker_registration_id,
126 const GURL& service_worker_origin, 137 const GURL& service_worker_origin,
127 const std::string& region_id, 138 const std::string& region_id,
128 const blink::WebCircularGeofencingRegion& region, 139 const blink::WebCircularGeofencingRegion& region,
129 const StatusCallback& callback, 140 const StatusCallback& callback,
130 int64 geofencing_registration_id); 141 int64 geofencing_registration_id);
131 142
132 // Clears a registration. 143 // Clears a registration.
133 void ClearRegistration(Registration* registration); 144 void ClearRegistration(Registration* registration);
134 145
146 // Unregisters and clears all registrations associated with a specific
147 // service worker. Used when a service worker is unregistered or when enabling
148 // or disabling mocking for this service worker.
149 void CleanUpForServiceWorker(int64 service_worker_registration_id);
150
135 // Starts dispatching a particular geofencing |event_type| for the geofence 151 // Starts dispatching a particular geofencing |event_type| for the geofence
136 // registration with the given ID. This first looks up the Service Worker 152 // registration with the given ID. This first looks up the Service Worker
137 // Registration the geofence is associated with, and then attempts to deliver 153 // Registration the geofence is associated with, and then attempts to deliver
138 // the event to that service worker. 154 // the event to that service worker.
139 void DispatchGeofencingEvent(blink::WebGeofencingEventType event_type, 155 void DispatchGeofencingEvent(blink::WebGeofencingEventType event_type,
140 int64 geofencing_registration_id); 156 int64 geofencing_registration_id);
141 157
142 // Delivers an event to the specified service worker for the given geofence. 158 // 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 159 // If the geofence registration id is no longer valid, this method does
144 // nothing. This assumes the |service_worker_registration| is the service 160 // nothing. This assumes the |service_worker_registration| is the service
(...skipping 17 matching lines...) Expand all
162 typedef std::map<int64, RegionIdRegistrationMap> 178 typedef std::map<int64, RegionIdRegistrationMap>
163 ServiceWorkerRegistrationsMap; 179 ServiceWorkerRegistrationsMap;
164 ServiceWorkerRegistrationsMap registrations_; 180 ServiceWorkerRegistrationsMap registrations_;
165 181
166 // Map of all registered regions by geofencing_registration_id. 182 // Map of all registered regions by geofencing_registration_id.
167 typedef std::map<int64, RegionIdRegistrationMap::iterator> 183 typedef std::map<int64, RegionIdRegistrationMap::iterator>
168 RegistrationIdRegistrationMap; 184 RegistrationIdRegistrationMap;
169 RegistrationIdRegistrationMap registrations_by_id_; 185 RegistrationIdRegistrationMap registrations_by_id_;
170 186
171 GeofencingService* service_; 187 GeofencingService* service_;
188 std::map<int64, linked_ptr<MockGeofencingService>> mock_services_;
scheib 2014/12/03 17:54:31 Why not have the mock simply replace service_? Why
172 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_; 189 scoped_refptr<ServiceWorkerContextWrapper> service_worker_context_;
173 190
174 DISALLOW_COPY_AND_ASSIGN(GeofencingManager); 191 DISALLOW_COPY_AND_ASSIGN(GeofencingManager);
175 }; 192 };
176 193
177 } // namespace content 194 } // namespace content
178 195
179 #endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_MANAGER_H_ 196 #endif // CONTENT_BROWSER_GEOFENCING_GEOFENCING_MANAGER_H_
OLDNEW
« no previous file with comments | « content/browser/geofencing/geofencing_dispatcher_host.cc ('k') | content/browser/geofencing/geofencing_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698