OLD | NEW |
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::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 |
29 // Stops TimezoneResolver if SystemTimezonePolicy is applied. | 63 // Stops TimezoneResolver if SystemTimezonePolicy is applied. |
30 // Returns SHOULD_* if timezone resolver status is controlled by this policy. | 64 // Returns SHOULD_* if timezone resolver status is controlled by this policy. |
31 ServiceConfiguration GetServiceConfigurationFromSystemTimezonePolicy() { | 65 ServiceConfiguration GetServiceConfigurationFromSystemTimezonePolicy() { |
32 if (!HasSystemTimezonePolicy()) | 66 if (!HasSystemTimezonePolicy()) |
33 return UNSPECIFIED; | 67 return UNSPECIFIED; |
34 | 68 |
35 return SHOULD_STOP; | 69 return SHOULD_STOP; |
36 } | 70 } |
37 | 71 |
38 // Starts or stops TimezoneResolver if required by policy. | 72 // Starts or stops TimezoneResolver if required by policy. |
39 // Returns true if timezone resolver status is controlled by policy. | 73 // Returns true if timezone resolver status is controlled by policy. |
40 ServiceConfiguration GetServiceConfigurationFromPolicy() { | 74 ServiceConfiguration GetServiceConfigurationFromPolicy() { |
41 ServiceConfiguration result = | 75 ServiceConfiguration result = |
42 GetServiceConfigurationFromSystemTimezonePolicy(); | 76 GetServiceConfigurationFromSystemTimezonePolicy(); |
43 | 77 |
44 if (result != UNSPECIFIED) | 78 if (result != UNSPECIFIED) |
45 return result; | 79 return result; |
46 | 80 |
| 81 result = GetServiceConfigurationFromAutomaticDetectionPolicy(); |
47 return result; | 82 return result; |
48 } | 83 } |
49 | 84 |
50 // Returns service configuration for the user. | 85 // Returns service configuration for the user. |
51 ServiceConfiguration GetServiceConfigurationFromUserPrefs( | 86 ServiceConfiguration GetServiceConfigurationFromUserPrefs( |
52 PrefService* user_prefs) { | 87 PrefService* user_prefs) { |
53 const bool value = | 88 const bool value = |
54 user_prefs->GetBoolean(prefs::kResolveTimezoneByGeolocation); | 89 user_prefs->GetBoolean(prefs::kResolveTimezoneByGeolocation); |
55 if (value) | 90 if (value) |
56 return SHOULD_START; | 91 return SHOULD_START; |
(...skipping 14 matching lines...) Expand all Loading... |
71 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoginUser)) | 106 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoginUser)) |
72 return SHOULD_STOP; | 107 return SHOULD_STOP; |
73 | 108 |
74 return SHOULD_START; | 109 return SHOULD_START; |
75 } | 110 } |
76 | 111 |
77 } // anonymous namespace. | 112 } // anonymous namespace. |
78 | 113 |
79 TimeZoneResolverManager::TimeZoneResolverManager() | 114 TimeZoneResolverManager::TimeZoneResolverManager() |
80 : primary_user_prefs_(nullptr) { | 115 : 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))); |
81 } | 122 } |
82 | 123 |
83 TimeZoneResolverManager::~TimeZoneResolverManager() {} | 124 TimeZoneResolverManager::~TimeZoneResolverManager() {} |
84 | 125 |
85 void TimeZoneResolverManager::SetPrimaryUserPrefs(PrefService* pref_service) { | 126 void TimeZoneResolverManager::SetPrimaryUserPrefs(PrefService* pref_service) { |
86 primary_user_prefs_ = pref_service; | 127 primary_user_prefs_ = pref_service; |
87 } | 128 } |
88 | 129 |
89 bool TimeZoneResolverManager::ShouldSendWiFiGeolocationData() { | 130 bool TimeZoneResolverManager::ShouldSendWiFiGeolocationData() { |
90 return false; | 131 PrefService* local_state = g_browser_process->local_state(); |
| 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; |
91 } | 145 } |
92 | 146 |
93 void TimeZoneResolverManager::UpdateTimezoneResolver() { | 147 void TimeZoneResolverManager::UpdateTimezoneResolver() { |
94 if (TimeZoneResolverShouldBeRunning()) | 148 if (TimeZoneResolverShouldBeRunning()) |
95 g_browser_process->platform_part()->GetTimezoneResolver()->Start(); | 149 g_browser_process->platform_part()->GetTimezoneResolver()->Start(); |
96 else | 150 else |
97 g_browser_process->platform_part()->GetTimezoneResolver()->Stop(); | 151 g_browser_process->platform_part()->GetTimezoneResolver()->Stop(); |
98 } | 152 } |
99 | 153 |
100 bool TimeZoneResolverManager::ShouldApplyResolvedTimezone() { | 154 bool TimeZoneResolverManager::ShouldApplyResolvedTimezone() { |
101 return TimeZoneResolverShouldBeRunning(); | 155 return TimeZoneResolverShouldBeRunning(); |
102 } | 156 } |
103 | 157 |
| 158 bool TimeZoneResolverManager::TimeZoneResolverShouldBeRunningForTests() { |
| 159 return TimeZoneResolverShouldBeRunning(); |
| 160 } |
| 161 |
104 bool TimeZoneResolverManager::TimeZoneResolverShouldBeRunning() { | 162 bool TimeZoneResolverManager::TimeZoneResolverShouldBeRunning() { |
105 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 163 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
106 chromeos::switches::kDisableTimeZoneTrackingOption)) { | 164 chromeos::switches::kDisableTimeZoneTrackingOption)) { |
107 return false; | 165 return false; |
108 } | 166 } |
109 ServiceConfiguration result = GetServiceConfigurationFromPolicy(); | 167 ServiceConfiguration result = GetServiceConfigurationFromPolicy(); |
110 | 168 |
111 if (result == UNSPECIFIED) { | 169 if (result == UNSPECIFIED) { |
112 if (primary_user_prefs_) { | 170 if (primary_user_prefs_) { |
113 result = GetServiceConfigurationFromUserPrefs(primary_user_prefs_); | 171 result = GetServiceConfigurationFromUserPrefs(primary_user_prefs_); |
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 |
OLD | NEW |