| OLD | NEW |
| 1 // Copyright (c) 2012 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/public/common/geoposition.h" |
| 15 | 15 |
| 16 class GeolocationArbitrator; | 16 class GeolocationArbitrator; |
| 17 | 17 |
| 18 template<typename Type> | 18 template<typename Type> |
| 19 struct DefaultSingletonTraits; | 19 struct DefaultSingletonTraits; |
| 20 | 20 |
| 21 // This is the main API to the geolocation subsystem. The application | 21 // This is the main API to the geolocation subsystem. The application |
| 22 // 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 |
| 23 // observers which will be notified of location updates. Underlying location | 23 // observers which will be notified of location updates. Underlying location |
| 24 // 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 14 matching lines...) Expand all Loading... |
| 39 const GeolocationObserverOptions& update_options); | 39 const GeolocationObserverOptions& update_options); |
| 40 | 40 |
| 41 // Remove a previously registered observer. No-op if not previously registered | 41 // Remove a previously registered observer. No-op if not previously registered |
| 42 // via AddObserver(). Returns true if the observer was removed. | 42 // via AddObserver(). Returns true if the observer was removed. |
| 43 bool RemoveObserver(GeolocationObserver* delegate); | 43 bool RemoveObserver(GeolocationObserver* delegate); |
| 44 | 44 |
| 45 void OnPermissionGranted(); | 45 void OnPermissionGranted(); |
| 46 bool HasPermissionBeenGranted() const; | 46 bool HasPermissionBeenGranted() const; |
| 47 | 47 |
| 48 // GeolocationObserver | 48 // GeolocationObserver |
| 49 virtual void OnLocationUpdate(const Geoposition& position) OVERRIDE; | 49 virtual void OnLocationUpdate(const content::Geoposition& position) OVERRIDE; |
| 50 | 50 |
| 51 // Overrides the location for automation/testing. Updates any current | 51 // Overrides the location for automation/testing. Updates any current |
| 52 // observers with the overriden position. Any further updates from location | 52 // observers with the overriden position. Any further updates from location |
| 53 // providers will be ignored. | 53 // providers will be ignored. |
| 54 void OverrideLocationForTesting(const Geoposition& override_position); | 54 void OverrideLocationForTesting( |
| 55 const content::Geoposition& override_position); |
| 55 | 56 |
| 56 // Gets a pointer to the singleton instance of the location relayer, which | 57 // Gets a pointer to the singleton instance of the location relayer, which |
| 57 // is in turn bound to the browser's global context objects. Ownership is NOT | 58 // is in turn bound to the browser's global context objects. Ownership is NOT |
| 58 // returned. | 59 // returned. |
| 59 static GeolocationProvider* GetInstance(); | 60 static GeolocationProvider* GetInstance(); |
| 60 | 61 |
| 61 typedef std::map<GeolocationObserver*, GeolocationObserverOptions> | 62 typedef std::map<GeolocationObserver*, GeolocationObserverOptions> |
| 62 ObserverMap; | 63 ObserverMap; |
| 63 | 64 |
| 64 private: | 65 private: |
| (...skipping 12 matching lines...) Expand all Loading... |
| 77 void StopProviders(); | 78 void StopProviders(); |
| 78 | 79 |
| 79 // Starts or updates the observers' geolocation options | 80 // Starts or updates the observers' geolocation options |
| 80 // (delegates to arbitrator). | 81 // (delegates to arbitrator). |
| 81 void StartProviders(const GeolocationObserverOptions& options); | 82 void StartProviders(const GeolocationObserverOptions& options); |
| 82 | 83 |
| 83 // Update the providers on the geolocation thread, which must be running. | 84 // Update the providers on the geolocation thread, which must be running. |
| 84 void InformProvidersPermissionGranted(); | 85 void InformProvidersPermissionGranted(); |
| 85 | 86 |
| 86 // Notifies observers when a new position fix is available. | 87 // Notifies observers when a new position fix is available. |
| 87 void NotifyObservers(const Geoposition& position); | 88 void NotifyObservers(const content::Geoposition& position); |
| 88 | 89 |
| 89 // Thread | 90 // Thread |
| 90 virtual void Init() OVERRIDE; | 91 virtual void Init() OVERRIDE; |
| 91 virtual void CleanUp() OVERRIDE; | 92 virtual void CleanUp() OVERRIDE; |
| 92 | 93 |
| 93 scoped_refptr<base::MessageLoopProxy> client_loop_; | 94 scoped_refptr<base::MessageLoopProxy> client_loop_; |
| 94 | 95 |
| 95 // Only used on client thread | 96 // Only used on client thread |
| 96 ObserverMap observers_; | 97 ObserverMap observers_; |
| 97 bool is_permission_granted_; | 98 bool is_permission_granted_; |
| 98 Geoposition position_; | 99 content::Geoposition position_; |
| 99 // True only in testing, where we want to use a custom position. | 100 // True only in testing, where we want to use a custom position. |
| 100 bool ignore_location_updates_; | 101 bool ignore_location_updates_; |
| 101 | 102 |
| 102 // Only to be used on the geolocation thread. | 103 // Only to be used on the geolocation thread. |
| 103 GeolocationArbitrator* arbitrator_; | 104 GeolocationArbitrator* arbitrator_; |
| 104 | 105 |
| 105 DISALLOW_COPY_AND_ASSIGN(GeolocationProvider); | 106 DISALLOW_COPY_AND_ASSIGN(GeolocationProvider); |
| 106 }; | 107 }; |
| 107 | 108 |
| 108 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_H_ | 109 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_H_ |
| OLD | NEW |