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

Unified Diff: chrome/browser/chromeos/system/timezone_resolver_manager.cc

Issue 1843523002: ChromeOS: Add SystemTimezoneAutomaticDetection policy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@596690--Implement-better-timezone-detection--refactoring-before-policy
Patch Set: Rebased. Created 4 years, 8 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/system/timezone_resolver_manager.cc
diff --git a/chrome/browser/chromeos/system/timezone_resolver_manager.cc b/chrome/browser/chromeos/system/timezone_resolver_manager.cc
index d4e1715efbb2dc7b262ae191334cf38ba373867f..3ff7ff541fa2f355df157bfe463d4cbc36689a7b 100644
--- a/chrome/browser/chromeos/system/timezone_resolver_manager.cc
+++ b/chrome/browser/chromeos/system/timezone_resolver_manager.cc
@@ -7,6 +7,7 @@
#include "base/command_line.h"
#include "base/logging.h"
#include "chrome/browser/browser_process.h"
+#include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
#include "chrome/browser/chromeos/preferences.h"
#include "chrome/browser/chromeos/system/timezone_util.h"
#include "chrome/common/pref_names.h"
@@ -26,6 +27,39 @@ enum ServiceConfiguration {
SHOULD_STOP = 2, // This source requires service Stop.
};
+// Starts or stops TimezoneResolver if required by
+// SystemTimezoneAutomaticDetectionPolicy.
+// Returns SHOULD_* if timezone resolver status is controlled by this policy.
+ServiceConfiguration GetServiceConfigurationFromAutomaticDetectionPolicy() {
+ if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
+ chromeos::switches::kEnableSystemTimezoneAutomaticDetectionPolicy)) {
+ return UNSPECIFIED;
+ }
+
+ PrefService* local_state = g_browser_process->local_state();
+ const bool is_managed = local_state->IsManagedPreference(
+ prefs::kSystemTimezoneAutomaticDetectionPolicy);
+ if (!is_managed)
+ return UNSPECIFIED;
+
+ int policy_value =
+ local_state->GetInteger(prefs::kSystemTimezoneAutomaticDetectionPolicy);
+
+ switch (policy_value) {
+ case enterprise_management::SystemTimezoneProto::USERS_DECIDE:
+ return UNSPECIFIED;
+ case enterprise_management::SystemTimezoneProto::DISABLED:
+ return SHOULD_STOP;
+ case enterprise_management::SystemTimezoneProto::IP_ONLY:
+ return SHOULD_START;
+ case enterprise_management::SystemTimezoneProto::SEND_WIFI_ACCESS_POINTS:
+ return SHOULD_START;
+ }
+ // Default for unknown policy value.
+ NOTREACHED() << "Unrecognized policy value: " << policy_value;
+ return SHOULD_STOP;
+}
+
// Stops TimezoneResolver if SystemTimezonePolicy is applied.
// Returns SHOULD_* if timezone resolver status is controlled by this policy.
ServiceConfiguration GetServiceConfigurationFromSystemTimezonePolicy() {
@@ -44,6 +78,7 @@ ServiceConfiguration GetServiceConfigurationFromPolicy() {
if (result != UNSPECIFIED)
return result;
+ result = GetServiceConfigurationFromAutomaticDetectionPolicy();
return result;
}
@@ -78,6 +113,12 @@ ServiceConfiguration GetServiceConfigurationForSigninScreen() {
TimeZoneResolverManager::TimeZoneResolverManager()
: primary_user_prefs_(nullptr) {
+ local_state_pref_change_registrar_.Init(g_browser_process->local_state());
+ local_state_pref_change_registrar_.Add(
+ prefs::kSystemTimezoneAutomaticDetectionPolicy,
+ base::Bind(
+ &::chromeos::system::TimeZoneResolverManager::UpdateTimezoneResolver,
+ base::Unretained(this)));
}
TimeZoneResolverManager::~TimeZoneResolverManager() {}
@@ -87,7 +128,20 @@ void TimeZoneResolverManager::SetPrimaryUserPrefs(PrefService* pref_service) {
}
bool TimeZoneResolverManager::ShouldSendWiFiGeolocationData() {
- return false;
+ PrefService* local_state = g_browser_process->local_state();
+ const bool is_managed = local_state->IsManagedPreference(
+ prefs::kSystemTimezoneAutomaticDetectionPolicy);
+ if (!is_managed)
+ return false;
+
+ int policy_value =
+ local_state->GetInteger(prefs::kSystemTimezoneAutomaticDetectionPolicy);
+
+ DCHECK(policy_value <= enterprise_management::SystemTimezoneProto::
+ AutomaticTimezoneDetectionType_MAX);
+
+ return policy_value ==
+ enterprise_management::SystemTimezoneProto::SEND_WIFI_ACCESS_POINTS;
}
void TimeZoneResolverManager::UpdateTimezoneResolver() {
@@ -101,6 +155,10 @@ bool TimeZoneResolverManager::ShouldApplyResolvedTimezone() {
return TimeZoneResolverShouldBeRunning();
}
+bool TimeZoneResolverManager::TimeZoneResolverShouldBeRunningForTests() {
+ return TimeZoneResolverShouldBeRunning();
+}
+
bool TimeZoneResolverManager::TimeZoneResolverShouldBeRunning() {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
chromeos::switches::kDisableTimeZoneTrackingOption)) {

Powered by Google App Engine
This is Rietveld 408576698