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

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

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

Powered by Google App Engine
This is Rietveld 408576698