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

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: 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 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 processes.
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 if (policy_value ==
48 ResolveDeviceTimezoneByGeolocationPolicyValues::USERS_DECIDE) {
49 return UNSPECIFIED;
50 }
51
52 if (policy_value ==
53 ResolveDeviceTimezoneByGeolocationPolicyValues::DISABLED) {
54 return SHOULD_STOP;
55 } else if (policy_value ==
56 ResolveDeviceTimezoneByGeolocationPolicyValues::IP_ONLY) {
57 return SHOULD_START;
58 } else if (policy_value == ResolveDeviceTimezoneByGeolocationPolicyValues::
59 SEND_WIFI_ACCESS_POINTS) {
60 return SHOULD_START;
61 }
62 // Default for unknown policy value.
63 NOTREACHED() << "Unrecognized policy value: " << policy_value;
64 return SHOULD_STOP;
65 }
66
67 // Stops TimezoneResolver if SystemTimezonePolicy is applied.
68 // Returns SHOULD_* if timezone resolver status is controlled by this policy.
69 ServiceConfiguration GetServiceConfigurationFromSystemTimezonePolicy() {
70 if (!HasSystemTimezonePolicy())
71 return UNSPECIFIED;
72
73 return SHOULD_STOP;
74 }
75
76 // Starts or stops TimezoneResolver if required by policy.
77 // Returns true if timezone resolver status is controlled by policy.
78 ServiceConfiguration GetServiceConfigurationFromPolicy() {
79 ServiceConfiguration result =
80 GetServiceConfigurationFromSystemTimezonePolicy();
81
82 if (result != UNSPECIFIED)
83 return result;
84
85 result = GetServiceConfigurationFromAutomaticDetectionPolicy();
86 return result;
87 }
88
89 // Returns service configuration for the user.
90 ServiceConfiguration GetServiceConfigurationFromUserPrefs(
91 PrefService* user_prefs) {
92 const bool value =
93 user_prefs->GetBoolean(prefs::kResolveTimezoneByGeolocation);
94 if (value)
95 return SHOULD_START;
96
97 return SHOULD_STOP;
98 }
99
100 // Returns service configuration for the signin screen.
101 ServiceConfiguration GetServiceConfigurationForSigninScreen() {
102 if (!g_browser_process->local_state()->GetBoolean(
103 prefs::kResolveDeviceTimezoneByGeolocation)) {
104 return SHOULD_START;
105 }
106
107 // Do not start resolver if we are inside active user session.
108 // If user preferences permit, it will be started on preferences
109 // initialization.
110 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoginUser))
111 return SHOULD_STOP;
112
113 return SHOULD_START;
114 }
115
116 } // anonymous namespace.
117
118 TimeZoneResolverManager::TimeZoneResolverManager()
119 : primary_user_prefs_(nullptr) {
120 local_state_pref_change_registrar_.Init(g_browser_process->local_state());
121 local_state_pref_change_registrar_.Add(
122 prefs::kSystemTimezoneAutomaticDetectionPolicy,
123 base::Bind(
124 &::chromeos::system::TimeZoneResolverManager::UpdateTimezoneResolver,
125 base::Unretained(this)));
126 }
127
128 TimeZoneResolverManager::~TimeZoneResolverManager() {}
129
130 void TimeZoneResolverManager::SetPrimaryUserPrefs(PrefService* pref_service) {
131 primary_user_prefs_ = pref_service;
132 }
133
134 bool TimeZoneResolverManager::ShouldSendWiFiGeolocationData() {
135 PrefService* local_state = g_browser_process->local_state();
136 const bool is_managed = local_state->IsManagedPreference(
137 prefs::kSystemTimezoneAutomaticDetectionPolicy);
138 if (!is_managed)
139 return false;
140
141 int policy_value =
142 local_state->GetInteger(prefs::kSystemTimezoneAutomaticDetectionPolicy);
143
144 DCHECK(policy_value <
145 ResolveDeviceTimezoneByGeolocationPolicyValues::NUM_ELEMENTS);
146
147 return policy_value == ResolveDeviceTimezoneByGeolocationPolicyValues::
148 SEND_WIFI_ACCESS_POINTS;
149 }
150
151 void TimeZoneResolverManager::UpdateTimezoneResolver() {
152 if (IsTimeZoneResolverShouldBeRunnig())
153 g_browser_process->platform_part()->GetTimezoneResolver()->Start();
154 else
155 g_browser_process->platform_part()->GetTimezoneResolver()->Stop();
156 }
157
158 bool TimeZoneResolverManager::ShouldApplyResolvedTimezone() {
159 return IsTimeZoneResolverShouldBeRunnig();
160 }
161
162 bool TimeZoneResolverManager::IsTimeZoneResolverShouldBeRunnig() {
163 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
164 chromeos::switches::kDisableTimeZoneTrackingOption)) {
165 return false;
166 }
167 ServiceConfiguration result;
168
169 result = GetServiceConfigurationFromPolicy();
170
171 if (result == UNSPECIFIED) {
172 if (primary_user_prefs_) {
173 result = GetServiceConfigurationFromUserPrefs(primary_user_prefs_);
174 } else {
175 // We are on a signin page.
176 result = GetServiceConfigurationForSigninScreen();
177 }
178 }
179 return result == SHOULD_START;
180 }
181
182 } // namespace system
183 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/system/timezone_resolver_manager.h ('k') | chrome/browser/chromeos/system/timezone_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698