1 // Copyright 2014 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 CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_LOCATION_MONITOR_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_LOCATION_MONITOR_H_
8 #include "base/macros.h"
9 #include "base/memory/singleton.h"
10 #include "base/memory/weak_ptr.h"
11 #include "base/time/time.h"
12 #include "base/timer/timer.h"
13 #include "content/public/browser/geolocation_provider.h"
17 // This class does one-time Geoposition resolve for OOBE.
18 // It stops after first valid position received or when timeout occurs.
19 // Valid position is sent to WizardController to resolve timezone.
20 class LoginLocationMonitor {
22 ~LoginLocationMonitor();
24 // Called on UI thread.
25 static void InstallLocationCallback(const base::TimeDelta timeout);
26 static void RemoveLocationCallback();
29 friend struct DefaultSingletonTraits<LoginLocationMonitor>;
30 friend class Singleton<chromeos::LoginLocationMonitor>;
32 LoginLocationMonitor();
34 // Called on UI thread.
35 static LoginLocationMonitor* GetInstance();
37 // Called on IO thread.
38 static void DoInstallLocationCallback(
39 content::GeolocationProvider::LocationUpdateCallback callback);
40 static void DoRemoveLocationCallback(
41 content::GeolocationProvider::LocationUpdateCallback callback);
43 // OnLocationUpdated comes on IO thread and should be passed to UI thread.
44 static void OnLocationUpdatedIO(const content::Geoposition& position);
45 static void OnLocationUpdatedUI(const content::Geoposition& position);
47 base::WeakPtrFactory<LoginLocationMonitor> weak_factory_;
48 content::GeolocationProvider::LocationUpdateCallback on_location_update_;
49 base::OneShotTimer<LoginLocationMonitor> request_timeout_;
53 DISALLOW_COPY_AND_ASSIGN(LoginLocationMonitor);
56 } // namespace chromeos
58 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_LOCATION_MONITOR_H_