Add ICU message format support
[chromium-blink-merge.git] / content / browser / geolocation / geolocation_provider_impl.h
blobb3c128649bbfcfd9f9570891e9270fd6c50568ed
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_
6 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_
8 #include <list>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/callback_forward.h"
13 #include "base/compiler_specific.h"
14 #include "base/threading/thread.h"
15 #include "content/common/content_export.h"
16 #include "content/public/browser/geolocation_provider.h"
17 #include "content/public/common/geoposition.h"
19 template<typename Type> struct DefaultSingletonTraits;
21 namespace content {
22 class LocationArbitrator;
24 class CONTENT_EXPORT GeolocationProviderImpl
25 : public NON_EXPORTED_BASE(GeolocationProvider),
26 public base::Thread {
27 public:
28 // GeolocationProvider implementation:
29 scoped_ptr<GeolocationProvider::Subscription> AddLocationUpdateCallback(
30 const LocationUpdateCallback& callback,
31 bool use_high_accuracy) override;
32 void UserDidOptIntoLocationServices() override;
33 void OverrideLocationForTesting(const Geoposition& position) override;
35 // Callback from the LocationArbitrator. Public for testing.
36 void OnLocationUpdate(const Geoposition& position);
38 // Gets a pointer to the singleton instance of the location relayer, which
39 // is in turn bound to the browser's global context objects. This must only be
40 // called on the UI thread so that the GeolocationProviderImpl is always
41 // instantiated on the same thread. Ownership is NOT returned.
42 static GeolocationProviderImpl* GetInstance();
44 bool user_did_opt_into_location_services_for_testing() {
45 return user_did_opt_into_location_services_;
48 protected:
49 friend struct DefaultSingletonTraits<GeolocationProviderImpl>;
50 GeolocationProviderImpl();
51 ~GeolocationProviderImpl() override;
53 // Useful for injecting mock geolocation arbitrator in tests.
54 virtual LocationArbitrator* CreateArbitrator();
56 private:
57 bool OnGeolocationThread() const;
59 // Start and stop providers as needed when clients are added or removed.
60 void OnClientsChanged();
62 // Stops the providers when there are no more registered clients. Note that
63 // once the Geolocation thread is started, it will stay alive (but sitting
64 // idle without any pending messages).
65 void StopProviders();
67 // Starts the geolocation providers or updates their options (delegates to
68 // arbitrator).
69 void StartProviders(bool use_high_accuracy);
71 // Updates the providers on the geolocation thread, which must be running.
72 void InformProvidersPermissionGranted();
74 // Notifies all registered clients that a position update is available.
75 void NotifyClients(const Geoposition& position);
77 // Thread
78 void Init() override;
79 void CleanUp() override;
81 base::CallbackList<void(const Geoposition&)> high_accuracy_callbacks_;
82 base::CallbackList<void(const Geoposition&)> low_accuracy_callbacks_;
84 bool user_did_opt_into_location_services_;
85 Geoposition position_;
87 // True only in testing, where we want to use a custom position.
88 bool ignore_location_updates_;
90 // Only to be used on the geolocation thread.
91 LocationArbitrator* arbitrator_;
93 DISALLOW_COPY_AND_ASSIGN(GeolocationProviderImpl);
96 } // namespace content
98 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_