geolocation_provider.h revision b2df76ea8fec9e32f6f3718986dba0d95315b29c
1b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 2b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)// found in the LICENSE file. 4b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 5b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#ifndef CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_ 6b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#define CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_ 7b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 8b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "base/callback_forward.h" 9b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#include "content/common/content_export.h" 10b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 11b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)namespace content { 12b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)struct Geoposition; 13b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 14b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)class CONTENT_EXPORT GeolocationProvider { 15b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) public: 16b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // This method, and all below, can only be called on the IO thread unless 17b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // otherwise specified. 18b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) static GeolocationProvider* GetInstance(); 19b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 20b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) typedef base::Callback<void(const Geoposition&)> LocationUpdateCallback; 21b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 22b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // |use_high_accuracy| is used as a 'hint' for the provider preferences for 23b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // this particular observer, however the observer could receive updates for 24b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // best available locations from any active provider whilst it is registered. 25b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // If an existing observer is added a second time, its options are updated 26b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // but only a single call to RemoveLocationUpdateCallback() is required to 27b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // remove it. 28b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) virtual void AddLocationUpdateCallback(const LocationUpdateCallback& callback, 29b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) bool use_high_accuracy) = 0; 30b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 31b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Remove a previously registered observer. No-op if not previously registered 32b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // via AddLocationUpdateCallback(). Returns true if the observer was removed. 33b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) virtual bool RemoveLocationUpdateCallback( 34b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const LocationUpdateCallback& callback) = 0; 35b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 36b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Calling this method indicates the user has opted into using location 37b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // services, including sending network requests to [Google servers to] resolve 38b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // the user's location. Use this method carefully, in line with the rules in 39b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // go/chrome-privacy-doc. 40b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) virtual void UserDidOptIntoLocationServices() = 0; 41b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 42b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Overrides the current location for testing. This function may be called on 43b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // any thread. The completion callback will be invoked asynchronously on the 44b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // calling thread when the override operation is completed. 45b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // 46b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // This function allows the current location to be faked without having to 47b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // manually instantiate a GeolocationProvider backed by a MockLocationProvider 48b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // that serves a fake location. 49b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // 50b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // Do not use this function in unit tests. The function instantiates the 51b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // singleton geolocation stack in the background and manipulates it to report 52b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // a fake location. Neither step can be undone, breaking unit test isolation 53b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) // (crbug.com/125931). 54b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) static void OverrideLocationForTesting( 55b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const Geoposition& position, 56b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) const base::Closure& completion_callback); 57b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 58b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) protected: 59b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) virtual~GeolocationProvider() {} 60b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}; 61b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 62b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)} // namespace content 63b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) 64b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#endif // CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_ 65