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)
8cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "base/callback_list.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)
14cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// This is the main API to the geolocation subsystem. The application will hold
15cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// a single instance of this class and can register multiple clients to be
16cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// notified of location changes:
17cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// * Callbacks are registered by AddLocationUpdateCallback() and will keep
18cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)//   receiving updates until the returned subscription object is destructed.
19cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// The application must instantiate the GeolocationProvider on the UI thread and
20cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// must communicate with it on the same thread.
21cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// The underlying location arbitrator will only be enabled whilst there is at
22cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// least one registered observer or pending callback (and only after
23cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// UserDidOptIntoLocationServices). The arbitrator and the location providers it
24cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)// uses run on a separate Geolocation thread.
25cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)class GeolocationProvider {
26b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) public:
27cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  CONTENT_EXPORT static GeolocationProvider* GetInstance();
28b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
29b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  typedef base::Callback<void(const Geoposition&)> LocationUpdateCallback;
30cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  typedef base::CallbackList<void(const Geoposition&)>::Subscription
31cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      Subscription;
32b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
33b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // |use_high_accuracy| is used as a 'hint' for the provider preferences for
34b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // this particular observer, however the observer could receive updates for
35b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // best available locations from any active provider whilst it is registered.
36cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual scoped_ptr<Subscription> AddLocationUpdateCallback(
37cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      const LocationUpdateCallback& callback, bool use_high_accuracy) = 0;
38b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
39b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // Calling this method indicates the user has opted into using location
40b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // services, including sending network requests to [Google servers to] resolve
41b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // the user's location. Use this method carefully, in line with the rules in
42b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // go/chrome-privacy-doc.
43b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  virtual void UserDidOptIntoLocationServices() = 0;
44b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
45cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Overrides the current location for testing.
46b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  //
47cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Overrides the location for automation/testing. Suppresses any further
48cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // updates from the actual providers and sends an update with the overridden
49cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // position to all registered clients.
50b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  //
51b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // Do not use this function in unit tests. The function instantiates the
52b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // singleton geolocation stack in the background and manipulates it to report
53b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // a fake location. Neither step can be undone, breaking unit test isolation
54b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  // (crbug.com/125931).
55cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  virtual void OverrideLocationForTesting(const Geoposition& position) = 0;
56b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
57b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles) protected:
58b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)  virtual~GeolocationProvider() {}
59b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)};
60b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
61b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)}  // namespace content
62b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)
63b2df76ea8fec9e32f6f3718986dba0d95315b29cTorne (Richard Coles)#endif  // CONTENT_PUBLIC_BROWSER_GEOLOCATION_PROVIDER_H_
64