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 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_CONTEXT_H_ | 5 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_CONTEXT_H_ |
6 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_CONTEXT_H_ | 6 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_CONTEXT_H_ |
7 | 7 |
8 #include "base/memory/scoped_vector.h" | |
9 #include "content/browser/geolocation/geolocation_service_impl.h" | 8 #include "content/browser/geolocation/geolocation_service_impl.h" |
| 9 #include "content/common/geolocation_service.mojom.h" |
| 10 #include "content/public/browser/web_contents_user_data.h" |
| 11 #include "mojo/common/strong_binding_set.h" |
10 | 12 |
11 namespace content { | 13 namespace content { |
| 14 struct Geoposition; |
12 | 15 |
13 // Provides information to a set of GeolocationServiceImpl instances that are | 16 // Provides information to a set of GeolocationServiceImpl instances that are |
14 // associated with a given context. Notably, allows pausing and resuming | 17 // associated with a given context. Notably, allows pausing and resuming |
15 // geolocation on these instances. | 18 // geolocation on these instances. |
16 class GeolocationServiceContext { | 19 class GeolocationServiceContext |
| 20 : public WebContentsUserData<GeolocationServiceContext> { |
17 public: | 21 public: |
18 GeolocationServiceContext(); | 22 static GeolocationServiceContext* GetOrCreateForWebContents( |
19 virtual ~GeolocationServiceContext(); | 23 WebContents* web_contents); |
20 | 24 |
21 // Creates a GeolocationServiceImpl that is weakly bound to |request|. | 25 // Creates a GeolocationServiceImpl that is bound to |request|. |
22 // |update_callback| will be called when services send | 26 static void CreateService(RenderFrameHost* render_frame_host, |
23 // location updates to their clients. | 27 mojo::InterfaceRequest<GeolocationService> request); |
24 void CreateService(const base::Closure& update_callback, | |
25 mojo::InterfaceRequest<GeolocationService> request); | |
26 | |
27 // Called when a service has a connection error. After this call, it is no | |
28 // longer safe to access |service|. | |
29 void ServiceHadConnectionError(GeolocationServiceImpl* service); | |
30 | 28 |
31 // Pauses and resumes geolocation. Resuming when nothing is paused is a | 29 // Pauses and resumes geolocation. Resuming when nothing is paused is a |
32 // no-op. If a service is added while geolocation is paused, that service | 30 // no-op. If a service is added while geolocation is paused, that service |
33 // will not get geolocation updates until geolocation is resumed. | 31 // will not get geolocation updates until geolocation is resumed. |
34 void PauseUpdates(); | 32 void PauseUpdates(); |
35 void ResumeUpdates(); | 33 void ResumeUpdates(); |
36 | 34 |
37 // Returns whether geolocation updates are currently paused. | 35 // Returns whether geolocation updates are currently paused. |
38 bool paused() { return paused_; } | 36 bool paused() const { return paused_; } |
| 37 |
| 38 // Returns the current position override, or nullptr if there isn't one. |
| 39 const Geoposition* position_override() const { |
| 40 return geoposition_override_.get(); |
| 41 } |
| 42 |
| 43 void DestroyService(GeolocationServiceImpl* service); |
39 | 44 |
40 // Enables geolocation override. This method can be used to trigger possible | 45 // Enables geolocation override. This method can be used to trigger possible |
41 // location-specific behavior in a particular context. | 46 // location-specific behavior in a particular context. |
42 void SetOverride(scoped_ptr<Geoposition> geoposition); | 47 void SetOverride(scoped_ptr<Geoposition> geoposition); |
43 | 48 |
44 // Disables geolocation override. | 49 // Disables geolocation override. |
45 void ClearOverride(); | 50 void ClearOverride(); |
46 | 51 |
47 private: | 52 private: |
48 ScopedVector<GeolocationServiceImpl> services_; | 53 friend class WebContentsUserData<GeolocationServiceContext>; |
| 54 |
| 55 explicit GeolocationServiceContext(WebContents* web_contents); |
| 56 ~GeolocationServiceContext() override; |
| 57 |
| 58 void CreateServiceImpl(RenderFrameHost* render_frame_host, |
| 59 mojo::InterfaceRequest<GeolocationService> request); |
| 60 |
| 61 mojo::StrongBindingSet<GeolocationServiceImpl> services_; |
49 bool paused_; | 62 bool paused_; |
50 | 63 |
51 scoped_ptr<Geoposition> geoposition_override_; | 64 scoped_ptr<Geoposition> geoposition_override_; |
52 | 65 |
53 DISALLOW_COPY_AND_ASSIGN(GeolocationServiceContext); | 66 DISALLOW_COPY_AND_ASSIGN(GeolocationServiceContext); |
54 }; | 67 }; |
55 | 68 |
56 } // namespace content | 69 } // namespace content |
57 | 70 |
58 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_CONTEXT_H_ | 71 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_SERVICE_CONTEXT_H_ |
OLD | NEW |