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

Side by Side Diff: chrome/browser/chromeos/system/timezone_resolver_manager.cc

Issue 1836433003: ChromeOS: Add SystemTimezoneAutomaticDetection policy. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
(Empty)
1 // Copyright 2016 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 #include "chrome/browser/chromeos/system/timezone_resolver_manager.h"
6
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "chrome/browser/browser_process.h"
10 #include "chrome/browser/chromeos/preferences.h"
11 #include "chrome/browser/chromeos/system/timezone_util.h"
12 #include "chrome/common/pref_names.h"
13 #include "chromeos/chromeos_switches.h"
14 #include "components/prefs/pref_service.h"
15
16 namespace chromeos {
17 namespace system {
18
19 namespace {
20
21 // This is the result of several methods calculating configured
22 // time zone resolve process.
stevenjb 2016/03/28 23:23:17 nit: processes
Alexander Alekseev 2016/03/29 00:29:25 Done.
23 enum ServiceConfiguration {
24 UNSPECIFIED = 0, // Try another configuration source.
25 SHOULD_START = 1, // This source requires service Start.
26 SHOULD_STOP = 2, // This source requires service Stop.
27 };
28
29 // Starts or stops TimezoneResolver if required by
30 // SystemTimezoneAutomaticDetectionPolicy.
31 // Returns SHOULD_* if timezone resolver status is controlled by this policy.
32 ServiceConfiguration GetServiceConfigurationFromAutomaticDetectionPolicy() {
33 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
34 chromeos::switches::kEnableSystemTimezoneAutomaticDetectionPolicy)) {
35 return UNSPECIFIED;
36 }
37
38 PrefService* local_state = g_browser_process->local_state();
39 const bool is_managed = local_state->IsManagedPreference(
40 prefs::kSystemTimezoneAutomaticDetectionPolicy);
41 if (!is_managed)
42 return UNSPECIFIED;
43
44 int policy_value =
45 local_state->GetInteger(prefs::kSystemTimezoneAutomaticDetectionPolicy);
46
47 DCHECK(policy_value <
48 ResolveDeviceTimezoneByGeolocationPolicyValues::NUM_ELEMENTS);
stevenjb 2016/03/28 23:23:17 Instead, before the default return add: NOTREACHED
Alexander Alekseev 2016/03/29 00:29:25 Done.
49
50 if (policy_value ==
51 ResolveDeviceTimezoneByGeolocationPolicyValues::USERS_DECIDE) {
52 return UNSPECIFIED;
53 }
54
55 if (policy_value ==
56 ResolveDeviceTimezoneByGeolocationPolicyValues::DISABLED) {
57 return SHOULD_STOP;
58 } else if (policy_value ==
59 ResolveDeviceTimezoneByGeolocationPolicyValues::IP_ONLY) {
60 return SHOULD_START;
61 } else if (policy_value == ResolveDeviceTimezoneByGeolocationPolicyValues::
62 SEND_WIFI_ACCESS_POINTS) {
63 return SHOULD_START;
64 }
65 // Default for unknown policy value.
66 return SHOULD_STOP;
67 }
68
69 // Stops TimezoneResolver if SystemTimezonePolicy is applied.
70 // Returns SHOULD_* if timezone resolver status is controlled by this policy.
71 ServiceConfiguration GetServiceConfigurationFromSystemTimezonePolicy() {
72 if (!HasSystemTimezonePolicy())
73 return UNSPECIFIED;
74
75 return SHOULD_STOP;
76 }
77
78 // Starts or stops TimezoneResolver if required by policy.
79 // Returns true if timezone resolver status is controlled by policy.
80 ServiceConfiguration GetServiceConfigurationFromPolicy() {
81 ServiceConfiguration result =
82 GetServiceConfigurationFromSystemTimezonePolicy();
83
84 if (result != UNSPECIFIED)
85 return result;
86
87 result = GetServiceConfigurationFromAutomaticDetectionPolicy();
88 return result;
89 }
90
91 // Returns service configuration for the user.
92 ServiceConfiguration GetServiceConfigurationFromUserPrefs(
93 PrefService* user_prefs) {
94 const bool value =
95 user_prefs->GetBoolean(prefs::kResolveTimezoneByGeolocation);
96 if (value) {
97 return SHOULD_START;
98 }
stevenjb 2016/03/28 23:23:17 nit: no {}
Alexander Alekseev 2016/03/29 00:29:25 Done.
99 return SHOULD_STOP;
100 }
101
102 // Returns service configuration for the signin screen.
103 ServiceConfiguration GetServiceConfigurationForSigninScreen() {
104 if (!g_browser_process->local_state()->GetBoolean(
105 prefs::kResolveDeviceTimezoneByGeolocation)) {
106 return SHOULD_START;
107 }
108
109 // Do not start resolver if we are inside active user session.
110 // If user preferences permit, it will be started on preferences
111 // initialization.
112 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoginUser))
113 return SHOULD_STOP;
114
115 return SHOULD_START;
116 }
117
118 } // anonymous namespace.
119
120 TimeZoneResolverManager::TimeZoneResolverManager()
121 : primary_user_prefs_(nullptr) {
122 local_state_pref_change_registrar_.Init(g_browser_process->local_state());
123 local_state_pref_change_registrar_.Add(
124 prefs::kSystemTimezoneAutomaticDetectionPolicy,
125 base::Bind(
126 &::chromeos::system::TimeZoneResolverManager::UpdateTimezoneResolver,
127 base::Unretained(this)));
128 }
129
130 TimeZoneResolverManager::~TimeZoneResolverManager() {}
131
132 void TimeZoneResolverManager::SetPrimaryUserPrefs(PrefService* pref_service) {
133 primary_user_prefs_ = pref_service;
134 }
135
136 bool TimeZoneResolverManager::ShouldSendWiFiGeolocationData() {
137 PrefService* local_state = g_browser_process->local_state();
138 const bool is_managed = local_state->IsManagedPreference(
139 prefs::kSystemTimezoneAutomaticDetectionPolicy);
140 if (!is_managed)
141 return false;
142
143 int policy_value =
144 local_state->GetInteger(prefs::kSystemTimezoneAutomaticDetectionPolicy);
145
146 DCHECK(policy_value <
147 ResolveDeviceTimezoneByGeolocationPolicyValues::NUM_ELEMENTS);
148
149 return policy_value == ResolveDeviceTimezoneByGeolocationPolicyValues::
150 SEND_WIFI_ACCESS_POINTS;
151 }
152
153 void TimeZoneResolverManager::UpdateTimezoneResolver() {
154 if (IsTimeZoneResolverShouldBeRunnig()) {
155 g_browser_process->platform_part()->GetTimezoneResolver()->Start();
156 } else {
157 g_browser_process->platform_part()->GetTimezoneResolver()->Stop();
158 }
stevenjb 2016/03/28 23:23:17 nit: no {}
Alexander Alekseev 2016/03/29 00:29:25 Done.
159 }
160
161 bool TimeZoneResolverManager::IfShouldApplyResolvedTimezone() {
162 return IsTimeZoneResolverShouldBeRunnig();
163 }
164
165 bool TimeZoneResolverManager::IsTimeZoneResolverShouldBeRunnig() {
166 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
167 chromeos::switches::kDisableTimeZoneTrackingOption)) {
168 return false;
169 }
170 ServiceConfiguration result;
171
172 result = GetServiceConfigurationFromPolicy();
173
174 if (result == UNSPECIFIED) {
175 if (primary_user_prefs_) {
176 result = GetServiceConfigurationFromUserPrefs(primary_user_prefs_);
177 } else {
178 // We are on a signin page.
179 result = GetServiceConfigurationForSigninScreen();
180 }
181 }
182 return result == SHOULD_START;
183 }
184
185 } // namespace system
186 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698