Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: content/browser/geolocation/geolocation_provider_impl.h

Issue 2192683002: Reland 2:Geolocation: move from content/browser to device/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Ignore size_t_to_int truncation warning Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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.
4
5 #ifndef CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_
6 #define CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_
7
8 #include <list>
9 #include <memory>
10 #include <vector>
11
12 #include "base/callback_forward.h"
13 #include "base/compiler_specific.h"
14 #include "base/macros.h"
15 #include "base/threading/thread.h"
16 #include "content/common/content_export.h"
17 #include "content/public/browser/geolocation_provider.h"
18 #include "content/public/common/geoposition.h"
19
20 namespace base {
21 template<typename Type> struct DefaultSingletonTraits;
22 }
23
24 namespace content {
25 class LocationArbitrator;
26
27 class CONTENT_EXPORT GeolocationProviderImpl
28 : public NON_EXPORTED_BASE(GeolocationProvider),
29 public base::Thread {
30 public:
31 // GeolocationProvider implementation:
32 std::unique_ptr<GeolocationProvider::Subscription> AddLocationUpdateCallback(
33 const LocationUpdateCallback& callback,
34 bool enable_high_accuracy) override;
35 void UserDidOptIntoLocationServices() override;
36 void OverrideLocationForTesting(const Geoposition& position) override;
37
38 // Callback from the LocationArbitrator. Public for testing.
39 void OnLocationUpdate(const Geoposition& position);
40
41 // Gets a pointer to the singleton instance of the location relayer, which
42 // is in turn bound to the browser's global context objects. This must only be
43 // called on the UI thread so that the GeolocationProviderImpl is always
44 // instantiated on the same thread. Ownership is NOT returned.
45 static GeolocationProviderImpl* GetInstance();
46
47 bool user_did_opt_into_location_services_for_testing() {
48 return user_did_opt_into_location_services_;
49 }
50
51 protected:
52 friend struct base::DefaultSingletonTraits<GeolocationProviderImpl>;
53 GeolocationProviderImpl();
54 ~GeolocationProviderImpl() override;
55
56 // Useful for injecting mock geolocation arbitrator in tests.
57 // TODO(mvanouwerkerk): Use something like SetArbitratorForTesting instead.
58 virtual std::unique_ptr<LocationArbitrator> CreateArbitrator();
59
60 private:
61 bool OnGeolocationThread() const;
62
63 // Start and stop providers as needed when clients are added or removed.
64 void OnClientsChanged();
65
66 // Stops the providers when there are no more registered clients. Note that
67 // once the Geolocation thread is started, it will stay alive (but sitting
68 // idle without any pending messages).
69 void StopProviders();
70
71 // Starts the geolocation providers or updates their options (delegates to
72 // arbitrator).
73 void StartProviders(bool enable_high_accuracy);
74
75 // Updates the providers on the geolocation thread, which must be running.
76 void InformProvidersPermissionGranted();
77
78 // Notifies all registered clients that a position update is available.
79 void NotifyClients(const Geoposition& position);
80
81 // Thread
82 void Init() override;
83 void CleanUp() override;
84
85 base::CallbackList<void(const Geoposition&)> high_accuracy_callbacks_;
86 base::CallbackList<void(const Geoposition&)> low_accuracy_callbacks_;
87
88 bool user_did_opt_into_location_services_;
89 Geoposition position_;
90
91 // True only in testing, where we want to use a custom position.
92 bool ignore_location_updates_;
93
94 // Only to be used on the geolocation thread.
95 std::unique_ptr<LocationArbitrator> arbitrator_;
96
97 DISALLOW_COPY_AND_ASSIGN(GeolocationProviderImpl);
98 };
99
100 } // namespace content
101
102 #endif // CONTENT_BROWSER_GEOLOCATION_GEOLOCATION_PROVIDER_IMPL_H_
OLDNEW
« no previous file with comments | « content/browser/geolocation/fake_access_token_store.cc ('k') | content/browser/geolocation/geolocation_provider_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698