Index: content/browser/geolocation/geolocation_service_context.cc |
diff --git a/content/browser/geolocation/geolocation_service_context.cc b/content/browser/geolocation/geolocation_service_context.cc |
index 7a250237d872385bda09de3ac0a2f5221e011d65..91c2c5c6d9d78a2744a22bcd3101a700e197cdaa 100644 |
--- a/content/browser/geolocation/geolocation_service_context.cc |
+++ b/content/browser/geolocation/geolocation_service_context.cc |
@@ -4,33 +4,48 @@ |
#include "content/browser/geolocation/geolocation_service_context.h" |
+#include "content/public/common/geoposition.h" |
+ |
namespace content { |
-GeolocationServiceContext::GeolocationServiceContext() : paused_(false) { |
-} |
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(GeolocationServiceContext); |
+ |
+GeolocationServiceContext::GeolocationServiceContext(WebContents* web_contents) |
+ : paused_(false) {} |
-GeolocationServiceContext::~GeolocationServiceContext() { |
+GeolocationServiceContext::~GeolocationServiceContext() {} |
+ |
+// static |
+GeolocationServiceContext* GeolocationServiceContext::GetOrCreateForWebContents( |
+ WebContents* web_contents) { |
+ CreateForWebContents(web_contents); |
+ return FromWebContents(web_contents); |
} |
+// static |
void GeolocationServiceContext::CreateService( |
- const base::Closure& update_callback, |
+ RenderFrameHost* render_frame_host, |
+ mojo::InterfaceRequest<GeolocationService> request) { |
+ WebContents* web_contents = |
+ WebContents::FromRenderFrameHost(render_frame_host); |
+ if (!web_contents) |
+ return; |
+ |
+ GeolocationServiceContext::GetOrCreateForWebContents(web_contents) |
+ ->CreateServiceImpl(render_frame_host, request.Pass()); |
+} |
+ |
+void GeolocationServiceContext::CreateServiceImpl( |
+ RenderFrameHost* render_frame_host, |
mojo::InterfaceRequest<GeolocationService> request) { |
GeolocationServiceImpl* service = |
- new GeolocationServiceImpl(request.Pass(), this, update_callback); |
- services_.push_back(service); |
+ services_.AddService(request.Pass(), this, render_frame_host); |
if (geoposition_override_) |
- service->SetOverride(*geoposition_override_.get()); |
+ service->OnOverrideSet(); |
else |
service->StartListeningForUpdates(); |
} |
-void GeolocationServiceContext::ServiceHadConnectionError( |
- GeolocationServiceImpl* service) { |
- auto it = std::find(services_.begin(), services_.end(), service); |
- DCHECK(it != services_.end()); |
- services_.erase(it); |
-} |
- |
void GeolocationServiceContext::PauseUpdates() { |
paused_ = true; |
for (auto* service : services_) { |
@@ -49,7 +64,7 @@ void GeolocationServiceContext::SetOverride( |
scoped_ptr<Geoposition> geoposition) { |
geoposition_override_.swap(geoposition); |
for (auto* service : services_) { |
- service->SetOverride(*geoposition_override_.get()); |
+ service->OnOverrideSet(); |
Anand Mistry (off Chromium)
2015/11/10 04:53:39
Why have you moved the position override into this
Sam McNally
2015/11/11 07:04:02
Each GeolocationServiceImpl doesn't really need it
|
} |
} |
@@ -57,6 +72,7 @@ void GeolocationServiceContext::ClearOverride() { |
for (auto* service : services_) { |
service->ClearOverride(); |
} |
+ geoposition_override_.reset(); |
} |
} // namespace content |