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

Side by Side Diff: Source/modules/geolocation/Geolocation.h

Issue 402563002: Separate GeolocationWatchers from Geolocation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Patch for landing Created 6 years, 5 months 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
« no previous file with comments | « Source/modules/geolocation/GeoNotifier.cpp ('k') | Source/modules/geolocation/Geolocation.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008, 2009, 2010, 2011 Apple Inc. All Rights Reserved.
3 * Copyright 2010, The Android Open Source Project 3 * Copyright 2010, The Android Open Source Project
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 13 matching lines...) Expand all
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 #ifndef Geolocation_h 27 #ifndef Geolocation_h
28 #define Geolocation_h 28 #define Geolocation_h
29 29
30 #include "bindings/core/v8/ScriptPromise.h" 30 #include "bindings/core/v8/ScriptPromise.h"
31 #include "bindings/core/v8/ScriptWrappable.h" 31 #include "bindings/core/v8/ScriptWrappable.h"
32 #include "core/dom/ActiveDOMObject.h" 32 #include "core/dom/ActiveDOMObject.h"
33 #include "modules/geolocation/GeoNotifier.h" 33 #include "modules/geolocation/GeoNotifier.h"
34 #include "modules/geolocation/GeolocationWatchers.h"
34 #include "modules/geolocation/Geoposition.h" 35 #include "modules/geolocation/Geoposition.h"
35 #include "modules/geolocation/PositionCallback.h" 36 #include "modules/geolocation/PositionCallback.h"
36 #include "modules/geolocation/PositionError.h" 37 #include "modules/geolocation/PositionError.h"
37 #include "modules/geolocation/PositionErrorCallback.h" 38 #include "modules/geolocation/PositionErrorCallback.h"
38 #include "modules/geolocation/PositionOptions.h" 39 #include "modules/geolocation/PositionOptions.h"
39 #include "platform/Timer.h" 40 #include "platform/Timer.h"
40 #include "platform/heap/Handle.h" 41 #include "platform/heap/Handle.h"
41 42
42 namespace blink { 43 namespace blink {
43 44
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 // Returns the last known position, if any. May return null. 105 // Returns the last known position, if any. May return null.
105 Geoposition* lastPosition(); 106 Geoposition* lastPosition();
106 107
107 bool isDenied() const { return m_geolocationPermission == PermissionDenied; } 108 bool isDenied() const { return m_geolocationPermission == PermissionDenied; }
108 109
109 explicit Geolocation(ExecutionContext*); 110 explicit Geolocation(ExecutionContext*);
110 111
111 typedef HeapVector<Member<GeoNotifier> > GeoNotifierVector; 112 typedef HeapVector<Member<GeoNotifier> > GeoNotifierVector;
112 typedef HeapHashSet<Member<GeoNotifier> > GeoNotifierSet; 113 typedef HeapHashSet<Member<GeoNotifier> > GeoNotifierSet;
113 114
114 class Watchers {
115 DISALLOW_ALLOCATION();
116 public:
117 void trace(Visitor*);
118 bool add(int id, GeoNotifier*);
119 GeoNotifier* find(int id);
120 void remove(int id);
121 void remove(GeoNotifier*);
122 bool contains(GeoNotifier*) const;
123 void clear();
124 bool isEmpty() const;
125 void getNotifiersVector(GeoNotifierVector&) const;
126 private:
127 typedef HeapHashMap<int, Member<GeoNotifier> > IdToNotifierMap;
128 typedef HeapHashMap<Member<GeoNotifier>, int> NotifierToIdMap;
129 IdToNotifierMap m_idToNotifierMap;
130 NotifierToIdMap m_notifierToIdMap;
131 };
132
133 bool hasListeners() const { return !m_oneShots.isEmpty() || !m_watchers.isEm pty(); } 115 bool hasListeners() const { return !m_oneShots.isEmpty() || !m_watchers.isEm pty(); }
134 116
135 void sendError(GeoNotifierVector&, PositionError*); 117 void sendError(GeoNotifierVector&, PositionError*);
136 void sendPosition(GeoNotifierVector&, Geoposition*); 118 void sendPosition(GeoNotifierVector&, Geoposition*);
137 119
138 // Removes notifiers that use a cached position from |notifiers| and 120 // Removes notifiers that use a cached position from |notifiers| and
139 // if |cached| is not null they are added to it. 121 // if |cached| is not null they are added to it.
140 static void extractNotifiersWithCachedPosition(GeoNotifierVector& notifiers, GeoNotifierVector* cached); 122 static void extractNotifiersWithCachedPosition(GeoNotifierVector& notifiers, GeoNotifierVector* cached);
141 123
142 // Copies notifiers from |src| vector to |dest| set. 124 // Copies notifiers from |src| vector to |dest| set.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // fatal error if permission is denied or no position can be obtained. 163 // fatal error if permission is denied or no position can be obtained.
182 void startRequest(GeoNotifier*); 164 void startRequest(GeoNotifier*);
183 165
184 bool haveSuitableCachedPosition(PositionOptions*); 166 bool haveSuitableCachedPosition(PositionOptions*);
185 167
186 // Runs the success callbacks for the set of notifiers awaiting a cached 168 // Runs the success callbacks for the set of notifiers awaiting a cached
187 // position, the set is then cleared. The oneshots are removed everywhere. 169 // position, the set is then cleared. The oneshots are removed everywhere.
188 void makeCachedPositionCallbacks(); 170 void makeCachedPositionCallbacks();
189 171
190 GeoNotifierSet m_oneShots; 172 GeoNotifierSet m_oneShots;
191 Watchers m_watchers; 173 GeolocationWatchers m_watchers;
192 GeoNotifierSet m_pendingForPermissionNotifiers; 174 GeoNotifierSet m_pendingForPermissionNotifiers;
193 Member<Geoposition> m_lastPosition; 175 Member<Geoposition> m_lastPosition;
194 176
195 // States of Geolocation permission as granted by the embedder. Unknown 177 // States of Geolocation permission as granted by the embedder. Unknown
196 // means that the embedder still has to be asked for the current permission 178 // means that the embedder still has to be asked for the current permission
197 // level; Requested means that the user has yet to make a decision. 179 // level; Requested means that the user has yet to make a decision.
198 enum Permission { 180 enum Permission {
199 PermissionUnknown, 181 PermissionUnknown,
200 PermissionRequested, 182 PermissionRequested,
201 PermissionAllowed, 183 PermissionAllowed,
202 PermissionDenied 184 PermissionDenied
203 }; 185 };
204 186
205 Permission m_geolocationPermission; 187 Permission m_geolocationPermission;
206 188
207 GeoNotifierSet m_requestsAwaitingCachedPosition; 189 GeoNotifierSet m_requestsAwaitingCachedPosition;
208 }; 190 };
209 191
210 } // namespace blink 192 } // namespace blink
211 193
212 #endif // Geolocation_h 194 #endif // Geolocation_h
OLDNEW
« no previous file with comments | « Source/modules/geolocation/GeoNotifier.cpp ('k') | Source/modules/geolocation/Geolocation.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698