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/preferences.h" | 10 #include "chrome/browser/chromeos/preferences.h" |
11 #include "chrome/browser/chromeos/system/timezone_util.h" | 11 #include "chrome/browser/chromeos/system/timezone_util.h" |
12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
13 #include "chromeos/chromeos_switches.h" | 13 #include "chromeos/chromeos_switches.h" |
14 #include "components/prefs/pref_service.h" | 14 #include "components/prefs/pref_service.h" |
15 | 15 |
16 namespace chromeos { | 16 namespace chromeos { |
17 namespace system { | 17 namespace system { |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 // This is the result of several methods calculating configured | 21 // This is the result of several methods calculating configured |
22 // time zone resolve processes. | 22 // time zone resolve processes. |
23 enum ServiceConfiguration { | 23 enum ServiceConfiguration { |
24 UNSPECIFIED = 0, // Try another configuration source. | 24 UNSPECIFIED = 0, // Try another configuration source. |
25 SHOULD_START = 1, // This source requires service Start. | 25 SHOULD_START = 1, // This source requires service Start. |
26 SHOULD_STOP = 2, // This source requires service Stop. | 26 SHOULD_STOP = 2, // This source requires service Stop. |
27 }; | 27 }; |
28 | 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 |
29 // Stops TimezoneResolver if SystemTimezonePolicy is applied. | 67 // Stops TimezoneResolver if SystemTimezonePolicy is applied. |
30 // Returns SHOULD_* if timezone resolver status is controlled by this policy. | 68 // Returns SHOULD_* if timezone resolver status is controlled by this policy. |
31 ServiceConfiguration GetServiceConfigurationFromSystemTimezonePolicy() { | 69 ServiceConfiguration GetServiceConfigurationFromSystemTimezonePolicy() { |
32 if (!HasSystemTimezonePolicy()) | 70 if (!HasSystemTimezonePolicy()) |
33 return UNSPECIFIED; | 71 return UNSPECIFIED; |
34 | 72 |
35 return SHOULD_STOP; | 73 return SHOULD_STOP; |
36 } | 74 } |
37 | 75 |
38 // Starts or stops TimezoneResolver if required by policy. | 76 // Starts or stops TimezoneResolver if required by policy. |
39 // Returns true if timezone resolver status is controlled by policy. | 77 // Returns true if timezone resolver status is controlled by policy. |
40 ServiceConfiguration GetServiceConfigurationFromPolicy() { | 78 ServiceConfiguration GetServiceConfigurationFromPolicy() { |
41 ServiceConfiguration result = | 79 ServiceConfiguration result = |
42 GetServiceConfigurationFromSystemTimezonePolicy(); | 80 GetServiceConfigurationFromSystemTimezonePolicy(); |
43 | 81 |
44 if (result != UNSPECIFIED) | 82 if (result != UNSPECIFIED) |
45 return result; | 83 return result; |
46 | 84 |
| 85 result = GetServiceConfigurationFromAutomaticDetectionPolicy(); |
47 return result; | 86 return result; |
48 } | 87 } |
49 | 88 |
50 // Returns service configuration for the user. | 89 // Returns service configuration for the user. |
51 ServiceConfiguration GetServiceConfigurationFromUserPrefs( | 90 ServiceConfiguration GetServiceConfigurationFromUserPrefs( |
52 PrefService* user_prefs) { | 91 PrefService* user_prefs) { |
53 const bool value = | 92 const bool value = |
54 user_prefs->GetBoolean(prefs::kResolveTimezoneByGeolocation); | 93 user_prefs->GetBoolean(prefs::kResolveTimezoneByGeolocation); |
55 if (value) | 94 if (value) |
56 return SHOULD_START; | 95 return SHOULD_START; |
(...skipping 14 matching lines...) Expand all Loading... |
71 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoginUser)) | 110 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoginUser)) |
72 return SHOULD_STOP; | 111 return SHOULD_STOP; |
73 | 112 |
74 return SHOULD_START; | 113 return SHOULD_START; |
75 } | 114 } |
76 | 115 |
77 } // anonymous namespace. | 116 } // anonymous namespace. |
78 | 117 |
79 TimeZoneResolverManager::TimeZoneResolverManager() | 118 TimeZoneResolverManager::TimeZoneResolverManager() |
80 : primary_user_prefs_(nullptr) { | 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))); |
81 } | 126 } |
82 | 127 |
83 TimeZoneResolverManager::~TimeZoneResolverManager() {} | 128 TimeZoneResolverManager::~TimeZoneResolverManager() {} |
84 | 129 |
85 void TimeZoneResolverManager::SetPrimaryUserPrefs(PrefService* pref_service) { | 130 void TimeZoneResolverManager::SetPrimaryUserPrefs(PrefService* pref_service) { |
86 primary_user_prefs_ = pref_service; | 131 primary_user_prefs_ = pref_service; |
87 } | 132 } |
88 | 133 |
89 bool TimeZoneResolverManager::ShouldSendWiFiGeolocationData() { | 134 bool TimeZoneResolverManager::ShouldSendWiFiGeolocationData() { |
90 return false; | 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; |
91 } | 149 } |
92 | 150 |
93 void TimeZoneResolverManager::UpdateTimezoneResolver() { | 151 void TimeZoneResolverManager::UpdateTimezoneResolver() { |
94 if (IsTimeZoneResolverShouldBeRunnig()) | 152 if (IsTimeZoneResolverShouldBeRunnig()) |
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 15 matching lines...) Expand all Loading... |
116 } else { | 174 } else { |
117 // We are on a signin page. | 175 // We are on a signin page. |
118 result = GetServiceConfigurationForSigninScreen(); | 176 result = GetServiceConfigurationForSigninScreen(); |
119 } | 177 } |
120 } | 178 } |
121 return result == SHOULD_START; | 179 return result == SHOULD_START; |
122 } | 180 } |
123 | 181 |
124 } // namespace system | 182 } // namespace system |
125 } // namespace chromeos | 183 } // namespace chromeos |
OLD | NEW |