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

Side by Side 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 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"
10 #include "chrome/browser/chromeos/preferences.h" 11 #include "chrome/browser/chromeos/preferences.h"
11 #include "chrome/browser/chromeos/system/timezone_util.h" 12 #include "chrome/browser/chromeos/system/timezone_util.h"
12 #include "chrome/common/pref_names.h" 13 #include "chrome/common/pref_names.h"
13 #include "chromeos/chromeos_switches.h" 14 #include "chromeos/chromeos_switches.h"
14 #include "components/prefs/pref_service.h" 15 #include "components/prefs/pref_service.h"
15 16
16 namespace chromeos { 17 namespace chromeos {
17 namespace system { 18 namespace system {
18 19
19 namespace { 20 namespace {
20 21
21 // This is the result of several methods calculating configured 22 // This is the result of several methods calculating configured
22 // time zone resolve processes. 23 // time zone resolve processes.
23 enum ServiceConfiguration { 24 enum ServiceConfiguration {
24 UNSPECIFIED = 0, // Try another configuration source. 25 UNSPECIFIED = 0, // Try another configuration source.
25 SHOULD_START = 1, // This source requires service Start. 26 SHOULD_START = 1, // This source requires service Start.
26 SHOULD_STOP = 2, // This source requires service Stop. 27 SHOULD_STOP = 2, // This source requires service Stop.
27 }; 28 };
28 29
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::SystemTimezoneAutomaticDetectionProto::
50 USERS_DECIDE:
51 return UNSPECIFIED;
52 case enterprise_management::SystemTimezoneAutomaticDetectionProto::DISABLED:
53 return SHOULD_STOP;
54 case enterprise_management::SystemTimezoneAutomaticDetectionProto::IP_ONLY:
55 return SHOULD_START;
56 case enterprise_management::SystemTimezoneAutomaticDetectionProto::
57 SEND_WIFI_ACCESS_POINTS:
58 return SHOULD_START;
59 }
60 // Default for unknown policy value.
61 NOTREACHED() << "Unrecognized policy value: " << policy_value;
62 return SHOULD_STOP;
63 }
64
29 // Stops TimezoneResolver if SystemTimezonePolicy is applied. 65 // Stops TimezoneResolver if SystemTimezonePolicy is applied.
30 // Returns SHOULD_* if timezone resolver status is controlled by this policy. 66 // Returns SHOULD_* if timezone resolver status is controlled by this policy.
31 ServiceConfiguration GetServiceConfigurationFromSystemTimezonePolicy() { 67 ServiceConfiguration GetServiceConfigurationFromSystemTimezonePolicy() {
32 if (!HasSystemTimezonePolicy()) 68 if (!HasSystemTimezonePolicy())
33 return UNSPECIFIED; 69 return UNSPECIFIED;
34 70
35 return SHOULD_STOP; 71 return SHOULD_STOP;
36 } 72 }
37 73
38 // Starts or stops TimezoneResolver if required by policy. 74 // Starts or stops TimezoneResolver if required by policy.
39 // Returns true if timezone resolver status is controlled by policy. 75 // Returns true if timezone resolver status is controlled by policy.
40 ServiceConfiguration GetServiceConfigurationFromPolicy() { 76 ServiceConfiguration GetServiceConfigurationFromPolicy() {
41 ServiceConfiguration result = 77 ServiceConfiguration result =
42 GetServiceConfigurationFromSystemTimezonePolicy(); 78 GetServiceConfigurationFromSystemTimezonePolicy();
43 79
44 if (result != UNSPECIFIED) 80 if (result != UNSPECIFIED)
45 return result; 81 return result;
46 82
83 result = GetServiceConfigurationFromAutomaticDetectionPolicy();
47 return result; 84 return result;
48 } 85 }
49 86
50 // Returns service configuration for the user. 87 // Returns service configuration for the user.
51 ServiceConfiguration GetServiceConfigurationFromUserPrefs( 88 ServiceConfiguration GetServiceConfigurationFromUserPrefs(
52 PrefService* user_prefs) { 89 PrefService* user_prefs) {
53 const bool value = 90 const bool value =
54 user_prefs->GetBoolean(prefs::kResolveTimezoneByGeolocation); 91 user_prefs->GetBoolean(prefs::kResolveTimezoneByGeolocation);
55 if (value) 92 if (value)
56 return SHOULD_START; 93 return SHOULD_START;
(...skipping 14 matching lines...) Expand all
71 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoginUser)) 108 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoginUser))
72 return SHOULD_STOP; 109 return SHOULD_STOP;
73 110
74 return SHOULD_START; 111 return SHOULD_START;
75 } 112 }
76 113
77 } // anonymous namespace. 114 } // anonymous namespace.
78 115
79 TimeZoneResolverManager::TimeZoneResolverManager() 116 TimeZoneResolverManager::TimeZoneResolverManager()
80 : primary_user_prefs_(nullptr) { 117 : primary_user_prefs_(nullptr) {
118 local_state_pref_change_registrar_.Init(g_browser_process->local_state());
119 local_state_pref_change_registrar_.Add(
120 prefs::kSystemTimezoneAutomaticDetectionPolicy,
121 base::Bind(
122 &::chromeos::system::TimeZoneResolverManager::UpdateTimezoneResolver,
123 base::Unretained(this)));
81 } 124 }
82 125
83 TimeZoneResolverManager::~TimeZoneResolverManager() {} 126 TimeZoneResolverManager::~TimeZoneResolverManager() {}
84 127
85 void TimeZoneResolverManager::SetPrimaryUserPrefs(PrefService* pref_service) { 128 void TimeZoneResolverManager::SetPrimaryUserPrefs(PrefService* pref_service) {
86 primary_user_prefs_ = pref_service; 129 primary_user_prefs_ = pref_service;
87 } 130 }
88 131
89 bool TimeZoneResolverManager::ShouldSendWiFiGeolocationData() { 132 bool TimeZoneResolverManager::ShouldSendWiFiGeolocationData() {
90 return false; 133 PrefService* local_state = g_browser_process->local_state();
134 const bool is_managed = local_state->IsManagedPreference(
135 prefs::kSystemTimezoneAutomaticDetectionPolicy);
136 if (!is_managed)
137 return false;
138
139 int policy_value =
140 local_state->GetInteger(prefs::kSystemTimezoneAutomaticDetectionPolicy);
141
142 DCHECK(policy_value <=
143 enterprise_management::SystemTimezoneAutomaticDetectionProto::
144 AutomaticTimezoneDetectionType_MAX);
145
146 return policy_value ==
147 enterprise_management::SystemTimezoneAutomaticDetectionProto::
148 SEND_WIFI_ACCESS_POINTS;
91 } 149 }
92 150
93 void TimeZoneResolverManager::UpdateTimezoneResolver() { 151 void TimeZoneResolverManager::UpdateTimezoneResolver() {
94 if (TimeZoneResolverShouldBeRunning()) 152 if (TimeZoneResolverShouldBeRunning())
95 g_browser_process->platform_part()->GetTimezoneResolver()->Start(); 153 g_browser_process->platform_part()->GetTimezoneResolver()->Start();
96 else 154 else
97 g_browser_process->platform_part()->GetTimezoneResolver()->Stop(); 155 g_browser_process->platform_part()->GetTimezoneResolver()->Stop();
98 } 156 }
99 157
100 bool TimeZoneResolverManager::ShouldApplyResolvedTimezone() { 158 bool TimeZoneResolverManager::ShouldApplyResolvedTimezone() {
(...skipping 13 matching lines...) Expand all
114 } else { 172 } else {
115 // We are on a signin page. 173 // We are on a signin page.
116 result = GetServiceConfigurationForSigninScreen(); 174 result = GetServiceConfigurationForSigninScreen();
117 } 175 }
118 } 176 }
119 return result == SHOULD_START; 177 return result == SHOULD_START;
120 } 178 }
121 179
122 } // namespace system 180 } // namespace system
123 } // namespace chromeos 181 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698