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 3 // found in the LICENSE file. 4 5 #ifndef THIRD_PARTY_BLINK_RENDERER_MODULES_GEOLOCATION_GEOLOCATION_WATCHERS_H_ 6 #define THIRD_PARTY_BLINK_RENDERER_MODULES_GEOLOCATION_GEOLOCATION_WATCHERS_H_ 7 8 #include "third_party/blink/renderer/platform/bindings/name_client.h" 9 #include "third_party/blink/renderer/platform/heap/handle.h" 10 11 namespace blink { 12 13 class GeoNotifier; 14 15 class GeolocationWatchers final : public GarbageCollected<GeolocationWatchers>, 16 public NameClient { 17 public: 18 GeolocationWatchers() = default; 19 void Trace(Visitor*) const; NameInHeapSnapshot()20 const char* NameInHeapSnapshot() const override { 21 return "GeolocationWatchers"; 22 } 23 24 bool Add(int id, GeoNotifier*); 25 GeoNotifier* Find(int id) const; 26 void Remove(int id); 27 void Remove(GeoNotifier*); 28 bool Contains(GeoNotifier*) const; 29 void Clear(); 30 bool IsEmpty() const; 31 void Swap(GeolocationWatchers& other); 32 Notifiers()33 auto& Notifiers() { return id_to_notifier_map_.Values(); } 34 35 void CopyNotifiersToVector(HeapVector<Member<GeoNotifier>>&) const; 36 37 private: 38 typedef HeapHashMap<int, Member<GeoNotifier>> IdToNotifierMap; 39 typedef HeapHashMap<Member<GeoNotifier>, int> NotifierToIdMap; 40 41 IdToNotifierMap id_to_notifier_map_; 42 NotifierToIdMap notifier_to_id_map_; 43 }; 44 swap(GeolocationWatchers & a,GeolocationWatchers & b)45inline void swap(GeolocationWatchers& a, GeolocationWatchers& b) { 46 a.Swap(b); 47 } 48 49 } // namespace blink 50 51 #endif // THIRD_PARTY_BLINK_RENDERER_MODULES_GEOLOCATION_GEOLOCATION_WATCHERS_H_ 52