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

Unified Diff: chrome/browser/chromeos/night_light/night_light_client.h

Issue 2966873002: [Night Light] CL12: String changes and fix frequent requests. (Closed)
Patch Set: Steven's suggestions Created 3 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/night_light/night_light_client.h
diff --git a/chrome/browser/chromeos/night_light/night_light_client.h b/chrome/browser/chromeos/night_light/night_light_client.h
index 0f8580dfacd3c9e8766fd7e91f84d96ada9a8697..0594840f9ba90aaa93861ccb6bb740367a14c341 100644
--- a/chrome/browser/chromeos/night_light/night_light_client.h
+++ b/chrome/browser/chromeos/night_light/night_light_client.h
@@ -5,6 +5,8 @@
#ifndef CHROME_BROWSER_CHROMEOS_NIGHT_LIGHT_NIGHT_LIGHT_CLIENT_H_
#define CHROME_BROWSER_CHROMEOS_NIGHT_LIGHT_NIGHT_LIGHT_CLIENT_H_
+#include <memory>
+
#include "ash/public/interfaces/night_light_controller.mojom.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
@@ -12,6 +14,10 @@
#include "chromeos/geolocation/simple_geolocation_provider.h"
#include "mojo/public/cpp/bindings/binding.h"
+namespace base {
+class Clock;
+} // namespace base
+
namespace net {
class URLRequestContextGetter;
}
@@ -21,7 +27,7 @@ class URLRequestContextGetter;
class NightLightClient
: public NON_EXPORTED_BASE(ash::mojom::NightLightClient) {
public:
- explicit NightLightClient(net::URLRequestContextGetter* url_context_getter);
+ NightLightClient(net::URLRequestContextGetter* url_context_getter);
~NightLightClient() override;
// Starts watching changes in the Night Light schedule type in order to begin
@@ -33,19 +39,36 @@ class NightLightClient
void OnScheduleTypeChanged(
ash::mojom::NightLightController::ScheduleType new_type) override;
+ const base::OneShotTimer& timer() const { return *timer_; }
+
+ base::Time last_successful_geo_request_time() const {
+ return last_successful_geo_request_time_;
+ }
+
bool using_geoposition() const { return using_geoposition_; }
+ static base::TimeDelta GetNextRequestDelayAfterSuccessForTesting();
+
void SetNightLightControllerPtrForTesting(
ash::mojom::NightLightControllerPtr controller);
void FlushNightLightControllerForTesting();
+ void SetTimerForTesting(std::unique_ptr<base::OneShotTimer> timer);
+
+ void SetClockForTesting(base::Clock* clock);
+
protected:
void OnGeoposition(const chromeos::Geoposition& position,
bool server_error,
const base::TimeDelta elapsed);
private:
+ base::Time GetNow() const;
+
+ // Sends the most recent valid geoposition to NightLightController in ash.
+ void SendCurrentGeoposition();
+
void ScheduleNextRequest(base::TimeDelta delay);
// Virtual so that it can be overriden by a fake implementation in unit tests
@@ -61,7 +84,15 @@ class NightLightClient
// Delay after which a new request is retried after a failed one.
base::TimeDelta backoff_delay_;
- base::OneShotTimer timer_;
+ std::unique_ptr<base::OneShotTimer> timer_;
+
+ // Optional Used in tests to override the time of "Now".
+ base::Clock* clock_ = nullptr; // Not owned.
+
+ // Last successful geoposition coordinates and its timestamp.
+ base::Time last_successful_geo_request_time_;
+ double latitude_ = 0.0;
+ double longitude_ = 0.0;
// True as long as the schedule type is set to "sunset to sunrise", which
// means this client will be retrieving the IP-based geoposition once per day.
« no previous file with comments | « chrome/browser/chromeos/night_light/OWNERS ('k') | chrome/browser/chromeos/night_light/night_light_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698