Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #include "content/browser/geolocation/geolocation_service_context.h" | 5 #include "content/browser/geolocation/geolocation_service_context.h" |
| 6 | 6 |
| 7 #include "content/public/common/geoposition.h" | |
| 8 | |
| 7 namespace content { | 9 namespace content { |
| 8 | 10 |
| 9 GeolocationServiceContext::GeolocationServiceContext() : paused_(false) { | 11 DEFINE_WEB_CONTENTS_USER_DATA_KEY(GeolocationServiceContext); |
| 12 | |
| 13 GeolocationServiceContext::GeolocationServiceContext(WebContents* web_contents) | |
| 14 : paused_(false) {} | |
| 15 | |
| 16 GeolocationServiceContext::~GeolocationServiceContext() {} | |
| 17 | |
| 18 // static | |
| 19 GeolocationServiceContext* GeolocationServiceContext::GetOrCreateForWebContents( | |
| 20 WebContents* web_contents) { | |
| 21 CreateForWebContents(web_contents); | |
| 22 return FromWebContents(web_contents); | |
| 10 } | 23 } |
| 11 | 24 |
| 12 GeolocationServiceContext::~GeolocationServiceContext() { | 25 // static |
| 26 void GeolocationServiceContext::CreateService( | |
| 27 RenderFrameHost* render_frame_host, | |
| 28 mojo::InterfaceRequest<GeolocationService> request) { | |
| 29 WebContents* web_contents = | |
| 30 WebContents::FromRenderFrameHost(render_frame_host); | |
| 31 if (!web_contents) | |
| 32 return; | |
| 33 | |
| 34 GeolocationServiceContext::GetOrCreateForWebContents(web_contents) | |
| 35 ->CreateServiceImpl(render_frame_host, request.Pass()); | |
| 13 } | 36 } |
| 14 | 37 |
| 15 void GeolocationServiceContext::CreateService( | 38 void GeolocationServiceContext::CreateServiceImpl( |
| 16 const base::Closure& update_callback, | 39 RenderFrameHost* render_frame_host, |
| 17 mojo::InterfaceRequest<GeolocationService> request) { | 40 mojo::InterfaceRequest<GeolocationService> request) { |
| 18 GeolocationServiceImpl* service = | 41 GeolocationServiceImpl* service = |
| 19 new GeolocationServiceImpl(request.Pass(), this, update_callback); | 42 services_.AddService(request.Pass(), this, render_frame_host); |
| 20 services_.push_back(service); | |
| 21 if (geoposition_override_) | 43 if (geoposition_override_) |
| 22 service->SetOverride(*geoposition_override_.get()); | 44 service->OnOverrideSet(); |
| 23 else | 45 else |
| 24 service->StartListeningForUpdates(); | 46 service->StartListeningForUpdates(); |
| 25 } | 47 } |
| 26 | 48 |
| 27 void GeolocationServiceContext::ServiceHadConnectionError( | |
| 28 GeolocationServiceImpl* service) { | |
| 29 auto it = std::find(services_.begin(), services_.end(), service); | |
| 30 DCHECK(it != services_.end()); | |
| 31 services_.erase(it); | |
| 32 } | |
| 33 | |
| 34 void GeolocationServiceContext::PauseUpdates() { | 49 void GeolocationServiceContext::PauseUpdates() { |
| 35 paused_ = true; | 50 paused_ = true; |
| 36 for (auto* service : services_) { | 51 for (auto* service : services_) { |
| 37 service->PauseUpdates(); | 52 service->PauseUpdates(); |
| 38 } | 53 } |
| 39 } | 54 } |
| 40 | 55 |
| 41 void GeolocationServiceContext::ResumeUpdates() { | 56 void GeolocationServiceContext::ResumeUpdates() { |
| 42 paused_ = false; | 57 paused_ = false; |
| 43 for (auto* service : services_) { | 58 for (auto* service : services_) { |
| 44 service->ResumeUpdates(); | 59 service->ResumeUpdates(); |
| 45 } | 60 } |
| 46 } | 61 } |
| 47 | 62 |
| 48 void GeolocationServiceContext::SetOverride( | 63 void GeolocationServiceContext::SetOverride( |
| 49 scoped_ptr<Geoposition> geoposition) { | 64 scoped_ptr<Geoposition> geoposition) { |
| 50 geoposition_override_.swap(geoposition); | 65 geoposition_override_.swap(geoposition); |
| 51 for (auto* service : services_) { | 66 for (auto* service : services_) { |
| 52 service->SetOverride(*geoposition_override_.get()); | 67 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
| |
| 53 } | 68 } |
| 54 } | 69 } |
| 55 | 70 |
| 56 void GeolocationServiceContext::ClearOverride() { | 71 void GeolocationServiceContext::ClearOverride() { |
| 57 for (auto* service : services_) { | 72 for (auto* service : services_) { |
| 58 service->ClearOverride(); | 73 service->ClearOverride(); |
| 59 } | 74 } |
| 75 geoposition_override_.reset(); | |
| 60 } | 76 } |
| 61 | 77 |
| 62 } // namespace content | 78 } // namespace content |
| OLD | NEW |