| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_PROVIDER_H_ | 5 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_H_ |
| 6 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_H_ | 6 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <map> | 9 #include <map> |
| 10 | 10 |
| 11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "content/browser/geolocation/geolocation_observer.h" | 12 #include "content/browser/geolocation/geolocation_observer.h" |
| 13 #include "content/common/content_export.h" | 13 #include "content/common/content_export.h" |
| 14 #include "content/common/geoposition.h" | 14 #include "content/common/geoposition.h" |
| 15 #include "googleurl/src/gurl.h" | |
| 16 | 15 |
| 17 class GeolocationArbitrator; | 16 class GeolocationArbitrator; |
| 18 | 17 |
| 19 template<typename Type> | 18 template<typename Type> |
| 20 struct DefaultSingletonTraits; | 19 struct DefaultSingletonTraits; |
| 21 | 20 |
| 22 // This is the main API to the geolocation subsystem. The application | 21 // This is the main API to the geolocation subsystem. The application |
| 23 // will hold a single instance of this class, and can register multiple | 22 // will hold a single instance of this class, and can register multiple |
| 24 // observers which will be notified of location updates. Underlying location | 23 // observers which will be notified of location updates. Underlying location |
| 25 // arbitrator will only be enabled whilst there is at least one observer | 24 // arbitrator will only be enabled whilst there is at least one observer |
| (...skipping 10 matching lines...) Expand all Loading... |
| 36 // provider whilst it is registered. | 35 // provider whilst it is registered. |
| 37 // If an existing observer is added a second time it's options are updated | 36 // If an existing observer is added a second time it's options are updated |
| 38 // but only a single call to RemoveObserver() is required to remove it. | 37 // but only a single call to RemoveObserver() is required to remove it. |
| 39 void AddObserver(GeolocationObserver* delegate, | 38 void AddObserver(GeolocationObserver* delegate, |
| 40 const GeolocationObserverOptions& update_options); | 39 const GeolocationObserverOptions& update_options); |
| 41 | 40 |
| 42 // Remove a previously registered observer. No-op if not previously registered | 41 // Remove a previously registered observer. No-op if not previously registered |
| 43 // via AddObserver(). Returns true if the observer was removed. | 42 // via AddObserver(). Returns true if the observer was removed. |
| 44 bool RemoveObserver(GeolocationObserver* delegate); | 43 bool RemoveObserver(GeolocationObserver* delegate); |
| 45 | 44 |
| 46 void OnPermissionGranted(const GURL& requesting_frame); | 45 void OnPermissionGranted(); |
| 47 bool HasPermissionBeenGranted() const; | 46 bool HasPermissionBeenGranted() const; |
| 48 | 47 |
| 49 // GeolocationObserver | 48 // GeolocationObserver |
| 50 virtual void OnLocationUpdate(const Geoposition& position) OVERRIDE; | 49 virtual void OnLocationUpdate(const Geoposition& position) OVERRIDE; |
| 51 | 50 |
| 52 // Gets a pointer to the singleton instance of the location relayer, which | 51 // Gets a pointer to the singleton instance of the location relayer, which |
| 53 // is in turn bound to the browser's global context objects. Ownership is NOT | 52 // is in turn bound to the browser's global context objects. Ownership is NOT |
| 54 // returned. | 53 // returned. |
| 55 static GeolocationProvider* GetInstance(); | 54 static GeolocationProvider* GetInstance(); |
| 56 | 55 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 70 | 69 |
| 71 // Stop the providers when there are no more observers. Note that once our | 70 // Stop the providers when there are no more observers. Note that once our |
| 72 // thread is started, we'll keep it alive (but with no pending messages). | 71 // thread is started, we'll keep it alive (but with no pending messages). |
| 73 void StopProviders(); | 72 void StopProviders(); |
| 74 | 73 |
| 75 // Starts or updates the observers' geolocation options | 74 // Starts or updates the observers' geolocation options |
| 76 // (delegates to arbitrator). | 75 // (delegates to arbitrator). |
| 77 void StartProviders(const GeolocationObserverOptions& options); | 76 void StartProviders(const GeolocationObserverOptions& options); |
| 78 | 77 |
| 79 // Update the providers on the geolocation thread, which must be running. | 78 // Update the providers on the geolocation thread, which must be running. |
| 80 void InformProvidersPermissionGranted(const GURL& requesting_frame); | 79 void InformProvidersPermissionGranted(); |
| 81 | 80 |
| 82 // Notifies observers when a new position fix is available. | 81 // Notifies observers when a new position fix is available. |
| 83 void NotifyObservers(const Geoposition& position); | 82 void NotifyObservers(const Geoposition& position); |
| 84 | 83 |
| 85 // Thread | 84 // Thread |
| 86 virtual void Init() OVERRIDE; | 85 virtual void Init() OVERRIDE; |
| 87 virtual void CleanUp() OVERRIDE; | 86 virtual void CleanUp() OVERRIDE; |
| 88 | 87 |
| 89 scoped_refptr<base::MessageLoopProxy> client_loop_; | 88 scoped_refptr<base::MessageLoopProxy> client_loop_; |
| 90 | 89 |
| 91 // Only used on client thread | 90 // Only used on client thread |
| 92 ObserverMap observers_; | 91 ObserverMap observers_; |
| 93 GURL most_recent_authorized_frame_; | 92 bool is_permission_granted_; |
| 94 Geoposition position_; | 93 Geoposition position_; |
| 95 | 94 |
| 96 // Only to be used on the geolocation thread. | 95 // Only to be used on the geolocation thread. |
| 97 GeolocationArbitrator* arbitrator_; | 96 GeolocationArbitrator* arbitrator_; |
| 98 | 97 |
| 99 DISALLOW_COPY_AND_ASSIGN(GeolocationProvider); | 98 DISALLOW_COPY_AND_ASSIGN(GeolocationProvider); |
| 100 }; | 99 }; |
| 101 | 100 |
| 102 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_H_ | 101 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_H_ |
| OLD | NEW |