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

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

Issue 402563002: Separate GeolocationWatchers from Geolocation (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 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
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 (C) 2009 Torch Mobile, Inc. 3 * Copyright (C) 2009 Torch Mobile, Inc.
4 * Copyright 2010, The Android Open Source Project 4 * Copyright 2010, The Android Open Source Project
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 18 matching lines...) Expand all
29 #include "modules/geolocation/Geolocation.h" 29 #include "modules/geolocation/Geolocation.h"
30 30
31 #include "core/dom/DOMException.h" 31 #include "core/dom/DOMException.h"
32 #include "core/dom/Document.h" 32 #include "core/dom/Document.h"
33 #include "core/dom/ExceptionCode.h" 33 #include "core/dom/ExceptionCode.h"
34 #include "modules/geolocation/Coordinates.h" 34 #include "modules/geolocation/Coordinates.h"
35 #include "modules/geolocation/GeofencingRegion.h" 35 #include "modules/geolocation/GeofencingRegion.h"
36 #include "modules/geolocation/GeolocationController.h" 36 #include "modules/geolocation/GeolocationController.h"
37 #include "modules/geolocation/GeolocationError.h" 37 #include "modules/geolocation/GeolocationError.h"
38 #include "modules/geolocation/GeolocationPosition.h" 38 #include "modules/geolocation/GeolocationPosition.h"
39 #include "modules/geolocation/GeolocationWatchers.h"
kihong 2014/07/18 15:36:58 This is duplicated include. I will remove this bef
39 #include "wtf/CurrentTime.h" 40 #include "wtf/CurrentTime.h"
40 41
41 namespace WebCore { 42 namespace WebCore {
42 43
43 static const char permissionDeniedErrorMessage[] = "User denied Geolocation"; 44 static const char permissionDeniedErrorMessage[] = "User denied Geolocation";
44 static const char failedToStartServiceErrorMessage[] = "Failed to start Geolocat ion service"; 45 static const char failedToStartServiceErrorMessage[] = "Failed to start Geolocat ion service";
45 static const char framelessDocumentErrorMessage[] = "Geolocation cannot be used in frameless documents"; 46 static const char framelessDocumentErrorMessage[] = "Geolocation cannot be used in frameless documents";
46 47
47 static Geoposition* createGeoposition(GeolocationPosition* position) 48 static Geoposition* createGeoposition(GeolocationPosition* position)
48 { 49 {
(...skipping 23 matching lines...) Expand all
72 code = PositionError::PERMISSION_DENIED; 73 code = PositionError::PERMISSION_DENIED;
73 break; 74 break;
74 case GeolocationError::PositionUnavailable: 75 case GeolocationError::PositionUnavailable:
75 code = PositionError::POSITION_UNAVAILABLE; 76 code = PositionError::POSITION_UNAVAILABLE;
76 break; 77 break;
77 } 78 }
78 79
79 return PositionError::create(code, error->message()); 80 return PositionError::create(code, error->message());
80 } 81 }
81 82
82 void Geolocation::Watchers::trace(Visitor* visitor)
83 {
84 visitor->trace(m_idToNotifierMap);
85 visitor->trace(m_notifierToIdMap);
86 }
87
88 bool Geolocation::Watchers::add(int id, GeoNotifier* notifier)
89 {
90 ASSERT(id > 0);
91 if (!m_idToNotifierMap.add(id, notifier).isNewEntry)
92 return false;
93 m_notifierToIdMap.set(notifier, id);
94 return true;
95 }
96
97 GeoNotifier* Geolocation::Watchers::find(int id)
98 {
99 ASSERT(id > 0);
100 IdToNotifierMap::iterator iter = m_idToNotifierMap.find(id);
101 if (iter == m_idToNotifierMap.end())
102 return 0;
103 return iter->value.get();
104 }
105
106 void Geolocation::Watchers::remove(int id)
107 {
108 ASSERT(id > 0);
109 IdToNotifierMap::iterator iter = m_idToNotifierMap.find(id);
110 if (iter == m_idToNotifierMap.end())
111 return;
112 m_notifierToIdMap.remove(iter->value);
113 m_idToNotifierMap.remove(iter);
114 }
115
116 void Geolocation::Watchers::remove(GeoNotifier* notifier)
117 {
118 NotifierToIdMap::iterator iter = m_notifierToIdMap.find(notifier);
119 if (iter == m_notifierToIdMap.end())
120 return;
121 m_idToNotifierMap.remove(iter->value);
122 m_notifierToIdMap.remove(iter);
123 }
124
125 bool Geolocation::Watchers::contains(GeoNotifier* notifier) const
126 {
127 return m_notifierToIdMap.contains(notifier);
128 }
129
130 void Geolocation::Watchers::clear()
131 {
132 m_idToNotifierMap.clear();
133 m_notifierToIdMap.clear();
134 }
135
136 bool Geolocation::Watchers::isEmpty() const
137 {
138 return m_idToNotifierMap.isEmpty();
139 }
140
141 void Geolocation::Watchers::getNotifiersVector(GeoNotifierVector& copy) const
142 {
143 copyValuesToVector(m_idToNotifierMap, copy);
144 }
145
146 Geolocation* Geolocation::create(ExecutionContext* context) 83 Geolocation* Geolocation::create(ExecutionContext* context)
147 { 84 {
148 Geolocation* geolocation = new Geolocation(context); 85 Geolocation* geolocation = new Geolocation(context);
149 geolocation->suspendIfNeeded(); 86 geolocation->suspendIfNeeded();
150 return geolocation; 87 return geolocation;
151 } 88 }
152 89
153 Geolocation::Geolocation(ExecutionContext* context) 90 Geolocation::Geolocation(ExecutionContext* context)
154 : ActiveDOMObject(context) 91 : ActiveDOMObject(context)
155 , m_geolocationPermission(PermissionUnknown) 92 , m_geolocationPermission(PermissionUnknown)
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 { 536 {
600 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError)); 537 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError));
601 } 538 }
602 539
603 ScriptPromise Geolocation::getRegisteredRegions(ScriptState* scriptState) const 540 ScriptPromise Geolocation::getRegisteredRegions(ScriptState* scriptState) const
604 { 541 {
605 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError)); 542 return ScriptPromise::rejectWithDOMException(scriptState, DOMException::crea te(NotSupportedError));
606 } 543 }
607 544
608 } // namespace WebCore 545 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698