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

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

Issue 2849823003: ChromeOS: implement per-user time zone preferences. (Closed)
Patch Set: Try remove g_browser_process check Created 3 years, 7 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_util.cc
diff --git a/chrome/browser/chromeos/system/timezone_util.cc b/chrome/browser/chromeos/system/timezone_util.cc
index d01f60e03b9fa460b7d67a6f535f2d3393327db2..d131fe8d5db2c21a7fbda86352705080ac2bf139 100644
--- a/chrome/browser/chromeos/system/timezone_util.cc
+++ b/chrome/browser/chromeos/system/timezone_util.cc
@@ -21,13 +21,16 @@
#include "base/values.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
+#include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/chromeos/settings/cros_settings.h"
#include "chrome/browser/chromeos/system/timezone_resolver_manager.h"
+#include "chrome/common/pref_names.h"
#include "chrome/grit/generated_resources.h"
#include "chromeos/settings/timezone_settings.h"
#include "chromeos/timezone/timezone_request.h"
#include "components/prefs/pref_service.h"
+#include "components/user_manager/user.h"
#include "components/user_manager/user_manager.h"
#include "third_party/icu/source/common/unicode/ures.h"
#include "third_party/icu/source/common/unicode/utypes.h"
@@ -184,6 +187,43 @@ bool HasSystemTimezonePolicy() {
return false;
}
+bool IsTimezonePrefsManaged(const std::string& pref_name) {
+ DCHECK(pref_name == prefs::kUserTimezone ||
+ pref_name == prefs::kResolveTimezoneByGeolocation);
+
+ std::string policy_timezone;
+ if (chromeos::CrosSettings::Get()->GetString(chromeos::kSystemTimezonePolicy,
+ &policy_timezone) &&
+ !policy_timezone.empty()) {
+ return true;
+ }
+
+ const PrefService* local_state = g_browser_process->local_state();
+ if (!local_state->IsManagedPreference(
+ prefs::kSystemTimezoneAutomaticDetectionPolicy))
+ return false;
stevenjb 2017/05/16 17:16:57 nit: {}
Alexander Alekseev 2017/05/19 11:25:29 Done.
+
+ int resolve_policy_value =
+ local_state->GetInteger(prefs::kSystemTimezoneAutomaticDetectionPolicy);
+
+ switch (resolve_policy_value) {
+ case enterprise_management::SystemTimezoneProto::USERS_DECIDE:
+ return false;
+ case enterprise_management::SystemTimezoneProto::DISABLED:
+ // This only disables resolving.
+ return pref_name == prefs::kResolveTimezoneByGeolocation;
+ case enterprise_management::SystemTimezoneProto::IP_ONLY:
+ // fall-through
stevenjb 2017/05/16 17:16:56 nit: 'fall-through' comment really isn't necessary
Alexander Alekseev 2017/05/19 11:25:29 Done.
+ case enterprise_management::SystemTimezoneProto::SEND_WIFI_ACCESS_POINTS:
+ // fall-through
+ case enterprise_management::SystemTimezoneProto::SEND_ALL_LOCATION_INFO:
+ return true;
+ }
+ // Default for unknown policy value.
+ NOTREACHED() << "Unrecognized policy value: " << resolve_policy_value;
+ return true;
+}
+
void ApplyTimeZone(const TimeZoneResponseData* timezone) {
if (!g_browser_process->platform_part()
->GetTimezoneResolverManager()
@@ -195,8 +235,63 @@ void ApplyTimeZone(const TimeZoneResponseData* timezone) {
VLOG(1) << "Refresh TimeZone: setting timezone to '" << timezone->timeZoneId
<< "'";
- chromeos::system::TimezoneSettings::GetInstance()->SetTimezoneFromID(
- base::UTF8ToUTF16(timezone->timeZoneId));
+ const user_manager::UserManager* user_manager =
+ user_manager::UserManager::Get();
+ const user_manager::User* primary_user = user_manager->GetPrimaryUser();
+
+ if (primary_user) {
+ Profile* profile = ProfileHelper::Get()->GetProfileByUser(primary_user);
+ profile->GetPrefs()->SetString(prefs::kUserTimezone,
+ timezone->timeZoneId);
+ // Preferences will automatically change system timezone because user is
+ // primary.
stevenjb 2017/05/16 17:16:57 Better, but I'm still unclear where/how "preferenc
Alexander Alekseev 2017/05/19 11:25:29 From the point of view of English language, "pref"
+ } else {
+ SetSigninScreenTimezone(timezone->timeZoneId,
+ true /* set_system_timezone */);
+ }
+ }
+}
+
+void UpdateSystemTimezone(Profile* profile) {
+ if (IsTimezonePrefsManaged(prefs::kUserTimezone)) {
+ VLOG(1) << "Ignoring user timezone change, because timezone is enterprise "
+ "managed.";
+ return;
+ }
+
+ const user_manager::UserManager* user_manager =
+ user_manager::UserManager::Get();
+ const user_manager::User* user =
+ ProfileHelper::Get()->GetUserByProfile(profile);
+
+ const AccountId owner(user_manager->GetOwnerAccountId());
+ const bool user_is_owner =
+ owner.is_valid() && (owner == user->GetAccountId());
+
+ const std::string value =
+ profile->GetPrefs()->GetString(prefs::kUserTimezone);
+ if (user_is_owner)
+ SetSigninScreenTimezone(value, false /* set_system_timezone */);
stevenjb 2017/05/16 17:16:57 Is this the only place we call SetSigninScreenTime
Alexander Alekseev 2017/05/19 11:25:29 Done.
+
+ if (user_manager->GetPrimaryUser() == user)
+ CrosSettings::Get()->SetString(kSystemTimezone, value);
+}
+
+void SetSigninScreenTimezone(const std::string& timezone,
+ bool set_system_timezone) {
+ if (timezone.empty())
+ return;
+
+ g_browser_process->local_state()->SetString(prefs::kSigninScreenTimezone,
+ timezone);
+
+ if (set_system_timezone) {
stevenjb 2017/05/16 17:16:56 nit: if (!set_system_timezone) return;
Alexander Alekseev 2017/05/19 11:25:29 This line has been removed.
+ std::string current_timezone_id;
+ CrosSettings::Get()->GetString(kSystemTimezone, &current_timezone_id);
+ if (current_timezone_id != timezone) {
+ system::TimezoneSettings::GetInstance()->SetTimezoneFromID(
+ base::UTF8ToUTF16(timezone));
+ }
}
}

Powered by Google App Engine
This is Rietveld 408576698