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/ui/webui/settings/chromeos/date_time_handler.h" | |
6 | |
7 #include "base/command_line.h" | |
8 #include "chrome/browser/browser_process.h" | |
9 #include "chrome/browser/chromeos/policy/proto/chrome_device_policy.pb.h" | |
10 #include "chrome/browser/chromeos/system/timezone_util.h" | |
11 #include "chrome/common/pref_names.h" | |
12 #include "chromeos/chromeos_switches.h" | |
13 #include "components/prefs/pref_service.h" | |
14 #include "content/public/browser/web_ui.h" | |
15 #include "content/public/browser/web_ui_data_source.h" | |
16 | |
17 namespace chromeos { | |
18 namespace settings { | |
19 | |
20 namespace { | |
21 | |
22 // Returns whether the system's automatic time zone detection setting is | |
23 // managed, which may override the user's setting. | |
24 bool IsSystemTimezoneAutomaticDetectionManaged() { | |
25 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
26 switches::kDisableSystemTimezoneAutomaticDetectionPolicy)) { | |
27 return false; | |
28 } | |
29 return g_browser_process->local_state()->IsManagedPreference( | |
30 prefs::kSystemTimezoneAutomaticDetectionPolicy); | |
31 } | |
32 | |
33 // Returns the system's current automatic time zone detection policy value, | |
34 // which corresponds to the SystemTimezoneProto's AutomaticTimezoneDetectionType | |
35 // enum and determines whether the user's setting will be overridden. | |
36 int GetSystemTimezoneAutomaticDetectionPolicyValue() { | |
37 DCHECK(IsSystemTimezoneAutomaticDetectionManaged()); | |
38 | |
39 return g_browser_process->local_state()->GetInteger( | |
40 prefs::kSystemTimezoneAutomaticDetectionPolicy); | |
41 } | |
42 | |
43 } // namespace | |
44 | |
45 DateTimeHandler::DateTimeHandler() {} | |
46 | |
47 DateTimeHandler::~DateTimeHandler() {} | |
48 | |
49 DateTimeHandler* DateTimeHandler::Create( | |
50 content::WebUIDataSource* html_source) { | |
51 html_source->AddBoolean("systemTimeZoneManaged", | |
52 chromeos::system::HasSystemTimezonePolicy()); | |
53 | |
54 bool system_time_zone_automatic_detection_managed = | |
55 IsSystemTimezoneAutomaticDetectionManaged(); | |
56 html_source->AddBoolean("systemTimeZoneDetectionManaged", | |
57 system_time_zone_automatic_detection_managed); | |
58 if (system_time_zone_automatic_detection_managed) { | |
59 html_source->AddInteger("systemTimeZoneDetectionPolicyValue", | |
60 GetSystemTimezoneAutomaticDetectionPolicyValue()); | |
61 } | |
62 | |
63 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | |
64 chromeos::switches::kDisableTimeZoneTrackingOption)) { | |
65 html_source->AddBoolean("hideTimeZoneDetection", true); | |
dpapad
2016/10/06 18:01:14
How about always setting this boolean, so that you
michaelpg
2016/10/06 18:22:50
There's enough precedence in the codebase for "opt
| |
66 } | |
67 | |
68 return new DateTimeHandler; | |
69 } | |
70 | |
71 void DateTimeHandler::RegisterMessages() { | |
72 // TODO(michaelpg): Add time zone message handlers. | |
73 } | |
74 | |
75 void DateTimeHandler::OnJavascriptAllowed() { | |
76 // TODO(michaelpg): Add policy observers. | |
77 } | |
78 | |
79 void DateTimeHandler::OnJavascriptDisallowed() { | |
80 // TODO(michaelpg): Remove policy observers. | |
81 } | |
82 | |
83 } // namespace settings | |
84 } // namespace chromeos | |
OLD | NEW |