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 base::DictionaryValue dict; |
| 60 dict.SetInteger("systemTimeZoneDetectionPolicyValue", |
| 61 GetSystemTimezoneAutomaticDetectionPolicyValue()); |
| 62 html_source->AddLocalizedStrings(dict); |
| 63 } |
| 64 |
| 65 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 66 chromeos::switches::kDisableTimeZoneTrackingOption)) { |
| 67 html_source->AddBoolean("hideTimeZoneDetection", true); |
| 68 } |
| 69 |
| 70 return new DateTimeHandler; |
| 71 } |
| 72 |
| 73 void DateTimeHandler::RegisterMessages() { |
| 74 // TODO(michaelpg): Add time zone message handlers. |
| 75 } |
| 76 |
| 77 void DateTimeHandler::OnJavascriptAllowed() { |
| 78 // TODO(michaelpg): Add policy observers. |
| 79 } |
| 80 |
| 81 void DateTimeHandler::OnJavascriptDisallowed() { |
| 82 // TODO(michaelpg): Remove policy observers. |
| 83 } |
| 84 |
| 85 } // namespace settings |
| 86 } // namespace chromeos |
OLD | NEW |