Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / login_location_monitor.h
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.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_LOCATION_MONITOR_H_
6 #define CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_LOCATION_MONITOR_H_
7
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"
14
15 namespace chromeos {
16
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 {
21  public:
22   ~LoginLocationMonitor();
23
24   // Called on UI thread.
25   static void InstallLocationCallback(const base::TimeDelta timeout);
26   static void RemoveLocationCallback();
27
28  private:
29   friend struct DefaultSingletonTraits<LoginLocationMonitor>;
30   friend class Singleton<chromeos::LoginLocationMonitor>;
31
32   LoginLocationMonitor();
33
34   // Called on UI thread.
35   static LoginLocationMonitor* GetInstance();
36
37   // Called on IO thread.
38   static void DoInstallLocationCallback(
39       content::GeolocationProvider::LocationUpdateCallback callback);
40   static void DoRemoveLocationCallback(
41       content::GeolocationProvider::LocationUpdateCallback callback);
42
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);
46
47   base::WeakPtrFactory<LoginLocationMonitor> weak_factory_;
48   content::GeolocationProvider::LocationUpdateCallback on_location_update_;
49   base::OneShotTimer<LoginLocationMonitor> request_timeout_;
50
51   base::Time started_;
52
53   DISALLOW_COPY_AND_ASSIGN(LoginLocationMonitor);
54 };
55
56 }  // namespace chromeos
57
58 #endif  // CHROME_BROWSER_CHROMEOS_LOGIN_LOGIN_LOCATION_MONITOR_H_