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

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

Issue 1837893003: ChromeOS: Refactor TimeZoneResolver, add TimeZoneResolverManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review. 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
(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 (TimeZoneResolverShouldBeRunning())
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 TimeZoneResolverShouldBeRunning();
102 }
103
104 bool TimeZoneResolverManager::TimeZoneResolverShouldBeRunning() {
105 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
106 chromeos::switches::kDisableTimeZoneTrackingOption)) {
107 return false;
108 }
109 ServiceConfiguration result = GetServiceConfigurationFromPolicy();
110
111 if (result == UNSPECIFIED) {
112 if (primary_user_prefs_) {
113 result = GetServiceConfigurationFromUserPrefs(primary_user_prefs_);
114 } else {
115 // We are on a signin page.
116 result = GetServiceConfigurationForSigninScreen();
117 }
118 }
119 return result == SHOULD_START;
120 }
121
122 } // namespace system
123 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/system/timezone_resolver_manager.h ('k') | chrome/browser/chromeos/system/timezone_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698