OLD | NEW |
---|---|
(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 // Stops TimezoneResolver if SystemTimezonePolicy is applied. | |
30 // Returns SHOULD_* if timezone resolver status is controlled by this policy. | |
31 ServiceConfiguration GetServiceConfigurationFromSystemTimezonePolicy() { | |
32 if (!HasSystemTimezonePolicy()) | |
33 return UNSPECIFIED; | |
34 | |
35 return SHOULD_STOP; | |
36 } | |
37 | |
38 // Starts or stops TimezoneResolver if required by policy. | |
39 // Returns true if timezone resolver status is controlled by policy. | |
40 ServiceConfiguration GetServiceConfigurationFromPolicy() { | |
41 ServiceConfiguration result = | |
42 GetServiceConfigurationFromSystemTimezonePolicy(); | |
43 | |
44 if (result != UNSPECIFIED) | |
45 return result; | |
46 | |
47 return result; | |
48 } | |
49 | |
50 // Returns service configuration for the user. | |
51 ServiceConfiguration GetServiceConfigurationFromUserPrefs( | |
52 PrefService* user_prefs) { | |
53 const bool value = | |
54 user_prefs->GetBoolean(prefs::kResolveTimezoneByGeolocation); | |
55 if (value) | |
56 return SHOULD_START; | |
57 | |
58 return SHOULD_STOP; | |
59 } | |
60 | |
61 // Returns service configuration for the signin screen. | |
62 ServiceConfiguration GetServiceConfigurationForSigninScreen() { | |
63 if (!g_browser_process->local_state()->GetBoolean( | |
64 prefs::kResolveDeviceTimezoneByGeolocation)) { | |
65 return SHOULD_START; | |
66 } | |
67 | |
68 // Do not start resolver if we are inside active user session. | |
69 // If user preferences permit, it will be started on preferences | |
70 // initialization. | |
71 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kLoginUser)) | |
72 return SHOULD_STOP; | |
73 | |
74 return SHOULD_START; | |
75 } | |
76 | |
77 } // anonymous namespace. | |
78 | |
79 TimeZoneResolverManager::TimeZoneResolverManager() | |
80 : primary_user_prefs_(nullptr) { | |
81 } | |
82 | |
83 TimeZoneResolverManager::~TimeZoneResolverManager() {} | |
84 | |
85 void TimeZoneResolverManager::SetPrimaryUserPrefs(PrefService* pref_service) { | |
86 primary_user_prefs_ = pref_service; | |
87 } | |
88 | |
89 bool TimeZoneResolverManager::ShouldSendWiFiGeolocationData() { | |
90 return false; | |
91 } | |
92 | |
93 void TimeZoneResolverManager::UpdateTimezoneResolver() { | |
94 if (IsTimeZoneResolverShouldBeRunnig()) | |
95 g_browser_process->platform_part()->GetTimezoneResolver()->Start(); | |
96 else | |
97 g_browser_process->platform_part()->GetTimezoneResolver()->Stop(); | |
98 } | |
99 | |
100 bool TimeZoneResolverManager::ShouldApplyResolvedTimezone() { | |
101 return IsTimeZoneResolverShouldBeRunnig(); | |
102 } | |
103 | |
104 bool TimeZoneResolverManager::IsTimeZoneResolverShouldBeRunnig() { | |
105 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
106 chromeos::switches::kDisableTimeZoneTrackingOption)) { | |
107 return false; | |
108 } | |
109 ServiceConfiguration result; | |
110 | |
111 result = GetServiceConfigurationFromPolicy(); | |
stevenjb
2016/03/29 02:15:55
nit: ServiceConfiguration result = Get...();
Alexander Alekseev
2016/03/29 03:46:35
Done.
| |
112 | |
113 if (result == UNSPECIFIED) { | |
114 if (primary_user_prefs_) { | |
115 result = GetServiceConfigurationFromUserPrefs(primary_user_prefs_); | |
116 } else { | |
117 // We are on a signin page. | |
118 result = GetServiceConfigurationForSigninScreen(); | |
119 } | |
120 } | |
121 return result == SHOULD_START; | |
122 } | |
123 | |
124 } // namespace system | |
125 } // namespace chromeos | |
OLD | NEW |