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

Side by Side Diff: chrome/browser/chromeos/night_light/night_light_client.h

Issue 2966873002: [Night Light] CL12: String changes and fix frequent requests. (Closed)
Patch Set: James comments Created 3 years, 5 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_NIGHT_LIGHT_NIGHT_LIGHT_CLIENT_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_NIGHT_LIGHT_NIGHT_LIGHT_CLIENT_H_
6 #define CHROME_BROWSER_CHROMEOS_NIGHT_LIGHT_NIGHT_LIGHT_CLIENT_H_ 6 #define CHROME_BROWSER_CHROMEOS_NIGHT_LIGHT_NIGHT_LIGHT_CLIENT_H_
7 7
8 #include "ash/public/interfaces/night_light_controller.mojom.h" 8 #include "ash/public/interfaces/night_light_controller.mojom.h"
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/memory/weak_ptr.h" 10 #include "base/memory/weak_ptr.h"
(...skipping 15 matching lines...) Expand all
26 26
27 // Starts watching changes in the Night Light schedule type in order to begin 27 // Starts watching changes in the Night Light schedule type in order to begin
28 // periodically pushing user's IP-based geoposition to NightLightController as 28 // periodically pushing user's IP-based geoposition to NightLightController as
29 // long as the type is set to "sunset to sunrise". 29 // long as the type is set to "sunset to sunrise".
30 void Start(); 30 void Start();
31 31
32 // ash::mojom::NightLightClient: 32 // ash::mojom::NightLightClient:
33 void OnScheduleTypeChanged( 33 void OnScheduleTypeChanged(
34 ash::mojom::NightLightController::ScheduleType new_type) override; 34 ash::mojom::NightLightController::ScheduleType new_type) override;
35 35
36 const base::OneShotTimer& timer() const { return timer_; }
37
38 base::Time last_successful_geo_request_time() const {
39 return last_successful_geo_request_time_;
40 }
41
36 bool using_geoposition() const { return using_geoposition_; } 42 bool using_geoposition() const { return using_geoposition_; }
37 43
44 static base::TimeDelta GetNextRequestDelayAfterSuccessForTesting();
45
38 void SetNightLightControllerPtrForTesting( 46 void SetNightLightControllerPtrForTesting(
39 ash::mojom::NightLightControllerPtr controller); 47 ash::mojom::NightLightControllerPtr controller);
40 48
41 void FlushNightLightControllerForTesting(); 49 void FlushNightLightControllerForTesting();
42 50
43 protected: 51 protected:
44 void OnGeoposition(const chromeos::Geoposition& position, 52 void OnGeoposition(const chromeos::Geoposition& position,
45 bool server_error, 53 bool server_error,
46 const base::TimeDelta elapsed); 54 const base::TimeDelta elapsed);
47 55
48 private: 56 private:
57 // Sends the most recent valid geoposition to NightLightController in ash.
58 void SendCurrentGeoposition();
59
49 void ScheduleNextRequest(base::TimeDelta delay); 60 void ScheduleNextRequest(base::TimeDelta delay);
50 61
51 // Virtual so that it can be overriden by a fake implementation in unit tests 62 // Virtual so that it can be overriden by a fake implementation in unit tests
52 // that doesn't request actual geopositions. 63 // that doesn't request actual geopositions.
53 virtual void RequestGeoposition(); 64 virtual void RequestGeoposition();
54 65
55 // The IP-based geolocation provider. 66 // The IP-based geolocation provider.
56 chromeos::SimpleGeolocationProvider provider_; 67 chromeos::SimpleGeolocationProvider provider_;
57 68
58 ash::mojom::NightLightControllerPtr night_light_controller_; 69 ash::mojom::NightLightControllerPtr night_light_controller_;
59 mojo::Binding<ash::mojom::NightLightClient> binding_; 70 mojo::Binding<ash::mojom::NightLightClient> binding_;
60 71
61 // Delay after which a new request is retried after a failed one. 72 // Delay after which a new request is retried after a failed one.
62 base::TimeDelta backoff_delay_; 73 base::TimeDelta backoff_delay_;
63 74
64 base::OneShotTimer timer_; 75 base::OneShotTimer timer_;
65 76
77 // Last successful geoposition coordinates and its timestamp.
78 base::Time last_successful_geo_request_time_;
79 double latitude_ = 0.0;
80 double longitude_ = 0.0;
81
66 // True as long as the schedule type is set to "sunset to sunrise", which 82 // True as long as the schedule type is set to "sunset to sunrise", which
67 // means this client will be retrieving the IP-based geoposition once per day. 83 // means this client will be retrieving the IP-based geoposition once per day.
68 bool using_geoposition_ = false; 84 bool using_geoposition_ = false;
69 85
70 DISALLOW_COPY_AND_ASSIGN(NightLightClient); 86 DISALLOW_COPY_AND_ASSIGN(NightLightClient);
71 }; 87 };
72 88
73 #endif // CHROME_BROWSER_CHROMEOS_NIGHT_LIGHT_NIGHT_LIGHT_CLIENT_H_ 89 #endif // CHROME_BROWSER_CHROMEOS_NIGHT_LIGHT_NIGHT_LIGHT_CLIENT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698