OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/webui/options/chromeos/core_chromeos_options_handler .h" | 5 #include "chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler .h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
20 #include "base/threading/thread_task_runner_handle.h" | 20 #include "base/threading/thread_task_runner_handle.h" |
21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
23 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" | 23 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos.h" |
24 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" | 24 #include "chrome/browser/chromeos/ownership/owner_settings_service_chromeos_fact ory.h" |
25 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | 25 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
26 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 26 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
27 #include "chrome/browser/chromeos/proxy_cros_settings_parser.h" | 27 #include "chrome/browser/chromeos/proxy_cros_settings_parser.h" |
28 #include "chrome/browser/chromeos/settings/cros_settings.h" | 28 #include "chrome/browser/chromeos/settings/cros_settings.h" |
29 #include "chrome/browser/chromeos/system/timezone_util.h" | |
29 #include "chrome/browser/profiles/profile.h" | 30 #include "chrome/browser/profiles/profile.h" |
30 #include "chrome/browser/ui/ash/session_controller_client.h" | 31 #include "chrome/browser/ui/ash/session_controller_client.h" |
31 #include "chrome/browser/ui/webui/chromeos/ui_account_tweaks.h" | 32 #include "chrome/browser/ui/webui/chromeos/ui_account_tweaks.h" |
32 #include "chrome/browser/ui/webui/options/chromeos/accounts_options_handler.h" | 33 #include "chrome/browser/ui/webui/options/chromeos/accounts_options_handler.h" |
33 #include "chrome/common/pref_names.h" | 34 #include "chrome/common/pref_names.h" |
34 #include "chrome/grit/generated_resources.h" | 35 #include "chrome/grit/generated_resources.h" |
35 #include "chromeos/network/network_handler.h" | 36 #include "chromeos/network/network_handler.h" |
36 #include "chromeos/network/proxy/ui_proxy_config_service.h" | 37 #include "chromeos/network/proxy/ui_proxy_config_service.h" |
37 #include "components/onc/onc_pref_names.h" | 38 #include "components/onc/onc_pref_names.h" |
38 #include "components/prefs/pref_change_registrar.h" | 39 #include "components/prefs/pref_change_registrar.h" |
39 #include "components/proxy_config/proxy_config_pref_names.h" | 40 #include "components/proxy_config/proxy_config_pref_names.h" |
40 #include "components/user_manager/user_manager.h" | 41 #include "components/user_manager/user_manager.h" |
41 #include "content/public/browser/notification_service.h" | 42 #include "content/public/browser/notification_service.h" |
42 #include "content/public/browser/web_ui.h" | 43 #include "content/public/browser/web_ui.h" |
43 #include "ui/base/l10n/l10n_util.h" | 44 #include "ui/base/l10n/l10n_util.h" |
44 | 45 |
45 namespace chromeos { | 46 namespace chromeos { |
46 namespace options { | 47 namespace options { |
47 | 48 |
48 namespace { | 49 namespace { |
49 | 50 |
50 // List of settings that should be changeable by all users. | 51 // List of settings that should be changeable by all users. |
51 const char* kNonPrivilegedSettings[] = { | 52 const char* kReadOnlySettings[] = { |
michaelpg
2017/07/24 06:57:39
the name and comment don't match up here...
Alexander Alekseev
2017/07/29 06:10:16
Done.
| |
52 kSystemTimezone | 53 kSystemTimezone |
53 }; | 54 }; |
54 | 55 |
55 // List of settings that should only be changeable by the primary user. | 56 // List of settings that should only be changeable by the primary user. |
56 const char* kPrimaryUserSettings[] = { | 57 const char* kPrimaryUserSettings[] = { |
57 prefs::kWakeOnWifiDarkConnect, | 58 prefs::kWakeOnWifiDarkConnect, |
59 prefs::kUserTimezone, | |
60 prefs::kResolveTimezoneByGeolocation | |
58 }; | 61 }; |
59 | 62 |
60 // Returns true if |pref| can be controlled (e.g. by policy or owner). | 63 // Returns true if |pref| can be controlled (e.g. by policy or owner). |
61 bool IsSettingPrivileged(const std::string& pref) { | 64 bool IsSettingPrivileged(const std::string& pref) { |
62 const char** end = kNonPrivilegedSettings + arraysize(kNonPrivilegedSettings); | 65 if (!chromeos::system::PerUserTimezoneEnabled()) { |
63 return std::find(kNonPrivilegedSettings, end, pref) == end; | 66 return pref != kSystemTimezone; |
67 } | |
68 // All the other Cros Settings are controlled. | |
69 return true; | |
70 } | |
71 | |
72 // Returns true if |pref| is modifiable from UI. | |
73 bool IsSettingWritable(const std::string& pref) { | |
74 if (!system::PerUserTimezoneEnabled()) | |
75 return true; | |
76 | |
77 const char** end = kReadOnlySettings + arraysize(kReadOnlySettings); | |
78 return std::find(kReadOnlySettings, end, pref) == end; | |
64 } | 79 } |
65 | 80 |
66 // Returns true if |pref| is shared (controlled by the primary user). | 81 // Returns true if |pref| is shared (controlled by the primary user). |
67 bool IsSettingShared(const std::string& pref) { | 82 bool IsSettingShared(const std::string& pref) { |
68 const char** end = kPrimaryUserSettings + arraysize(kPrimaryUserSettings); | 83 const char** end = kPrimaryUserSettings + arraysize(kPrimaryUserSettings); |
69 return std::find(kPrimaryUserSettings, end, pref) != end; | 84 return std::find(kPrimaryUserSettings, end, pref) != end; |
70 } | 85 } |
71 | 86 |
72 // Creates a user info dictionary to be stored in the |ListValue| that is | 87 // Creates a user info dictionary to be stored in the |ListValue| that is |
73 // passed to Javascript for the |kAccountsPrefUsers| preference. | 88 // passed to Javascript for the |kAccountsPrefUsers| preference. |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 return value; | 208 return value; |
194 base::DictionaryValue* dict; | 209 base::DictionaryValue* dict; |
195 if (!value->GetAsDictionary(&dict) || dict->HasKey("controlledBy")) | 210 if (!value->GetAsDictionary(&dict) || dict->HasKey("controlledBy")) |
196 return value; | 211 return value; |
197 Profile* primary_profile = ProfileHelper::Get()->GetProfileByUser( | 212 Profile* primary_profile = ProfileHelper::Get()->GetProfileByUser( |
198 user_manager::UserManager::Get()->GetPrimaryUser()); | 213 user_manager::UserManager::Get()->GetPrimaryUser()); |
199 if (!primary_profile) | 214 if (!primary_profile) |
200 return value; | 215 return value; |
201 dict->SetString("controlledBy", "shared"); | 216 dict->SetString("controlledBy", "shared"); |
202 dict->SetBoolean("disabled", true); | 217 dict->SetBoolean("disabled", true); |
203 dict->SetBoolean("value", primary_profile->GetPrefs()->GetBoolean( | 218 if (system::PerUserTimezoneEnabled()) { |
204 pref_name)); | 219 const PrefService::Preference* pref = |
220 primary_profile->GetPrefs()->FindPreference(pref_name); | |
221 dict->Set("value", base::MakeUnique<base::Value>(*pref->GetValue())); | |
michaelpg
2017/07/24 06:57:39
Why does PerUserTimezoneEnabled() imply that whate
Alexander Alekseev
2017/07/29 06:10:16
Why? base::MakeUnique<base::Value>(*pref->GetValue
michaelpg
2017/08/02 19:31:28
You're right, I think I was confused.
| |
222 } else { | |
223 dict->SetBoolean("value", | |
224 primary_profile->GetPrefs()->GetBoolean(pref_name)); | |
225 } | |
205 return value; | 226 return value; |
206 } | 227 } |
207 | 228 |
208 const base::Value* pref_value = CrosSettings::Get()->GetPref(pref_name); | 229 const base::Value* pref_value = CrosSettings::Get()->GetPref(pref_name); |
209 if (!pref_value) | 230 if (!pref_value) |
210 return base::MakeUnique<base::Value>(); | 231 return base::MakeUnique<base::Value>(); |
211 | 232 |
212 // Decorate pref value as CoreOptionsHandler::CreateValueForPref() does. | 233 // Decorate pref value as CoreOptionsHandler::CreateValueForPref() does. |
213 // TODO(estade): seems that this should replicate CreateValueForPref less. | 234 // TODO(estade): seems that this should replicate CreateValueForPref less. |
214 auto dict = base::MakeUnique<base::DictionaryValue>(); | 235 auto dict = base::MakeUnique<base::DictionaryValue>(); |
215 if (pref_name == kAccountsPrefUsers) | 236 if (pref_name == kAccountsPrefUsers) |
216 dict->Set("value", CreateUsersWhitelist(pref_value)); | 237 dict->Set("value", CreateUsersWhitelist(pref_value)); |
217 else | 238 else |
218 dict->Set("value", base::MakeUnique<base::Value>(*pref_value)); | 239 dict->Set("value", base::MakeUnique<base::Value>(*pref_value)); |
219 | 240 |
220 std::string controlled_by; | 241 std::string controlled_by; |
221 if (IsSettingPrivileged(pref_name)) { | 242 if (system::PerUserTimezoneEnabled() || IsSettingPrivileged(pref_name)) { |
222 policy::BrowserPolicyConnectorChromeOS* connector = | 243 policy::BrowserPolicyConnectorChromeOS* connector = |
223 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | 244 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
224 if (connector->IsEnterpriseManaged()) | 245 if (connector->IsEnterpriseManaged()) |
225 controlled_by = "policy"; | 246 controlled_by = "policy"; |
226 else if (!ProfileHelper::IsOwnerProfile(profile)) | 247 else if (!ProfileHelper::IsOwnerProfile(profile)) |
227 controlled_by = "owner"; | 248 controlled_by = "owner"; |
228 } | 249 } |
229 dict->SetBoolean("disabled", !controlled_by.empty()); | |
230 if (!controlled_by.empty()) | 250 if (!controlled_by.empty()) |
231 dict->SetString("controlledBy", controlled_by); | 251 dict->SetString("controlledBy", controlled_by); |
252 | |
253 // Read-only setting is always disabled. | |
254 dict->SetBoolean("disabled", | |
255 !controlled_by.empty() || !IsSettingWritable(pref_name)); | |
232 return std::move(dict); | 256 return std::move(dict); |
233 } | 257 } |
234 | 258 |
235 void CoreChromeOSOptionsHandler::ObservePref(const std::string& pref_name) { | 259 void CoreChromeOSOptionsHandler::ObservePref(const std::string& pref_name) { |
236 if (proxy_cros_settings_parser::IsProxyPref(pref_name)) { | 260 if (proxy_cros_settings_parser::IsProxyPref(pref_name)) { |
237 // We observe those all the time. | 261 // We observe those all the time. |
238 return; | 262 return; |
239 } | 263 } |
240 if (!CrosSettings::IsCrosSettings(pref_name)) | 264 if (!CrosSettings::IsCrosSettings(pref_name)) |
241 return ::options::CoreOptionsHandler::ObservePref(pref_name); | 265 return ::options::CoreOptionsHandler::ObservePref(pref_name); |
(...skipping 14 matching lines...) Expand all Loading... | |
256 proxy_cros_settings_parser::SetProxyPrefValue( | 280 proxy_cros_settings_parser::SetProxyPrefValue( |
257 network_guid_, pref_name, value, GetUiProxyConfigService()); | 281 network_guid_, pref_name, value, GetUiProxyConfigService()); |
258 base::Value proxy_type(pref_name); | 282 base::Value proxy_type(pref_name); |
259 web_ui()->CallJavascriptFunctionUnsafe( | 283 web_ui()->CallJavascriptFunctionUnsafe( |
260 "options.internet.DetailsInternetPage.updateProxySettings", proxy_type); | 284 "options.internet.DetailsInternetPage.updateProxySettings", proxy_type); |
261 ProcessUserMetric(value, metric); | 285 ProcessUserMetric(value, metric); |
262 return; | 286 return; |
263 } | 287 } |
264 if (!CrosSettings::IsCrosSettings(pref_name)) | 288 if (!CrosSettings::IsCrosSettings(pref_name)) |
265 return ::options::CoreOptionsHandler::SetPref(pref_name, value, metric); | 289 return ::options::CoreOptionsHandler::SetPref(pref_name, value, metric); |
290 if (!IsSettingWritable(pref_name)) { | |
291 NOTREACHED() << pref_name; | |
292 return; | |
293 } | |
266 OwnerSettingsServiceChromeOS* service = | 294 OwnerSettingsServiceChromeOS* service = |
267 OwnerSettingsServiceChromeOS::FromWebUI(web_ui()); | 295 OwnerSettingsServiceChromeOS::FromWebUI(web_ui()); |
268 if (service && service->HandlesSetting(pref_name)) | 296 if (service && service->HandlesSetting(pref_name)) |
269 service->Set(pref_name, *value); | 297 service->Set(pref_name, *value); |
270 else | 298 else |
271 CrosSettings::Get()->Set(pref_name, *value); | 299 CrosSettings::Get()->Set(pref_name, *value); |
272 | 300 |
273 ProcessUserMetric(value, metric); | 301 ProcessUserMetric(value, metric); |
274 } | 302 } |
275 | 303 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 network_guid_, proxy_cros_settings_parser::kProxySettings[i], | 446 network_guid_, proxy_cros_settings_parser::kProxySettings[i], |
419 GetUiProxyConfigService(), &value); | 447 GetUiProxyConfigService(), &value); |
420 DCHECK(value); | 448 DCHECK(value); |
421 DispatchPrefChangeNotification( | 449 DispatchPrefChangeNotification( |
422 proxy_cros_settings_parser::kProxySettings[i], std::move(value)); | 450 proxy_cros_settings_parser::kProxySettings[i], std::move(value)); |
423 } | 451 } |
424 } | 452 } |
425 | 453 |
426 } // namespace options | 454 } // namespace options |
427 } // namespace chromeos | 455 } // namespace chromeos |
OLD | NEW |