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, std::move(request)); |
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_.EmplaceService(std::move(request), 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 |
| 63 void GeolocationServiceContext::DestroyService( |
| 64 GeolocationServiceImpl* service) { |
| 65 services_.DestroyService(service); |
| 66 } |
| 67 |
48 void GeolocationServiceContext::SetOverride( | 68 void GeolocationServiceContext::SetOverride( |
49 scoped_ptr<Geoposition> geoposition) { | 69 scoped_ptr<Geoposition> geoposition) { |
50 geoposition_override_.swap(geoposition); | 70 geoposition_override_.swap(geoposition); |
51 for (auto* service : services_) { | 71 for (auto* service : services_) { |
52 service->SetOverride(*geoposition_override_.get()); | 72 service->OnOverrideSet(); |
53 } | 73 } |
54 } | 74 } |
55 | 75 |
56 void GeolocationServiceContext::ClearOverride() { | 76 void GeolocationServiceContext::ClearOverride() { |
57 for (auto* service : services_) { | 77 for (auto* service : services_) { |
58 service->ClearOverride(); | 78 service->ClearOverride(); |
59 } | 79 } |
| 80 geoposition_override_.reset(); |
60 } | 81 } |
61 | 82 |
62 } // namespace content | 83 } // namespace content |
OLD | NEW |