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

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.cc

Issue 2849823003: ChromeOS: implement per-user time zone preferences. (Closed)
Patch Set: Fixed tests. Created 3 years, 7 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
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
(...skipping 30 matching lines...) Expand all
41 #include "content/public/browser/notification_service.h" 41 #include "content/public/browser/notification_service.h"
42 #include "content/public/browser/web_ui.h" 42 #include "content/public/browser/web_ui.h"
43 #include "ui/base/l10n/l10n_util.h" 43 #include "ui/base/l10n/l10n_util.h"
44 44
45 namespace chromeos { 45 namespace chromeos {
46 namespace options { 46 namespace options {
47 47
48 namespace { 48 namespace {
49 49
50 // List of settings that should be changeable by all users. 50 // List of settings that should be changeable by all users.
51 const char* kNonPrivilegedSettings[] = { 51 const char* kReadOnlySettings[] = {
52 kSystemTimezone 52 kSystemTimezone
53 }; 53 };
54 54
55 // List of settings that should only be changeable by the primary user. 55 // List of settings that should only be changeable by the primary user.
56 const char* kPrimaryUserSettings[] = { 56 const char* kPrimaryUserSettings[] = {
57 prefs::kWakeOnWifiDarkConnect, 57 prefs::kWakeOnWifiDarkConnect,
58 prefs::kUserTimezone,
59 prefs::kResolveTimezoneByGeolocation
58 }; 60 };
59 61
60 // Returns true if |pref| can be controlled (e.g. by policy or owner). 62 // Returns true if |pref| can be controlled (e.g. by policy or owner).
61 bool IsSettingPrivileged(const std::string& pref) { 63 bool IsSettingWritable(const std::string& pref) {
62 const char** end = kNonPrivilegedSettings + arraysize(kNonPrivilegedSettings); 64 const char** end = kReadOnlySettings + arraysize(kReadOnlySettings);
63 return std::find(kNonPrivilegedSettings, end, pref) == end; 65 return std::find(kReadOnlySettings, end, pref) == end;
64 } 66 }
65 67
66 // Returns true if |pref| is shared (controlled by the primary user). 68 // Returns true if |pref| is shared (controlled by the primary user).
67 bool IsSettingShared(const std::string& pref) { 69 bool IsSettingShared(const std::string& pref) {
68 const char** end = kPrimaryUserSettings + arraysize(kPrimaryUserSettings); 70 const char** end = kPrimaryUserSettings + arraysize(kPrimaryUserSettings);
69 return std::find(kPrimaryUserSettings, end, pref) != end; 71 return std::find(kPrimaryUserSettings, end, pref) != end;
70 } 72 }
71 73
72 // Creates a user info dictionary to be stored in the |ListValue| that is 74 // Creates a user info dictionary to be stored in the |ListValue| that is
73 // passed to Javascript for the |kAccountsPrefUsers| preference. 75 // passed to Javascript for the |kAccountsPrefUsers| preference.
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 return value; 195 return value;
194 base::DictionaryValue* dict; 196 base::DictionaryValue* dict;
195 if (!value->GetAsDictionary(&dict) || dict->HasKey("controlledBy")) 197 if (!value->GetAsDictionary(&dict) || dict->HasKey("controlledBy"))
196 return value; 198 return value;
197 Profile* primary_profile = ProfileHelper::Get()->GetProfileByUser( 199 Profile* primary_profile = ProfileHelper::Get()->GetProfileByUser(
198 user_manager::UserManager::Get()->GetPrimaryUser()); 200 user_manager::UserManager::Get()->GetPrimaryUser());
199 if (!primary_profile) 201 if (!primary_profile)
200 return value; 202 return value;
201 dict->SetString("controlledBy", "shared"); 203 dict->SetString("controlledBy", "shared");
202 dict->SetBoolean("disabled", true); 204 dict->SetBoolean("disabled", true);
203 dict->SetBoolean("value", primary_profile->GetPrefs()->GetBoolean( 205 const PrefService::Preference* pref =
204 pref_name)); 206 primary_profile->GetPrefs()->FindPreference(pref_name);
207 dict->Set("value", base::MakeUnique<base::Value>(*pref->GetValue()));
205 return value; 208 return value;
206 } 209 }
207 210
208 const base::Value* pref_value = CrosSettings::Get()->GetPref(pref_name); 211 const base::Value* pref_value = CrosSettings::Get()->GetPref(pref_name);
209 if (!pref_value) 212 if (!pref_value)
210 return base::MakeUnique<base::Value>(); 213 return base::MakeUnique<base::Value>();
211 214
212 // Decorate pref value as CoreOptionsHandler::CreateValueForPref() does. 215 // Decorate pref value as CoreOptionsHandler::CreateValueForPref() does.
213 // TODO(estade): seems that this should replicate CreateValueForPref less. 216 // TODO(estade): seems that this should replicate CreateValueForPref less.
214 auto dict = base::MakeUnique<base::DictionaryValue>(); 217 auto dict = base::MakeUnique<base::DictionaryValue>();
215 if (pref_name == kAccountsPrefUsers) 218 if (pref_name == kAccountsPrefUsers)
216 dict->Set("value", CreateUsersWhitelist(pref_value)); 219 dict->Set("value", CreateUsersWhitelist(pref_value));
217 else 220 else
218 dict->Set("value", base::MakeUnique<base::Value>(*pref_value)); 221 dict->Set("value", base::MakeUnique<base::Value>(*pref_value));
219 222
220 std::string controlled_by; 223 std::string controlled_by;
221 if (IsSettingPrivileged(pref_name)) { 224 policy::BrowserPolicyConnectorChromeOS* connector =
222 policy::BrowserPolicyConnectorChromeOS* connector = 225 g_browser_process->platform_part()->browser_policy_connector_chromeos();
223 g_browser_process->platform_part()->browser_policy_connector_chromeos(); 226 if (connector->IsEnterpriseManaged())
224 if (connector->IsEnterpriseManaged()) 227 controlled_by = "policy";
225 controlled_by = "policy"; 228 else if (!ProfileHelper::IsOwnerProfile(profile))
226 else if (!ProfileHelper::IsOwnerProfile(profile)) 229 controlled_by = "owner";
227 controlled_by = "owner";
228 }
229 dict->SetBoolean("disabled", !controlled_by.empty());
230 if (!controlled_by.empty()) 230 if (!controlled_by.empty())
231 dict->SetString("controlledBy", controlled_by); 231 dict->SetString("controlledBy", controlled_by);
232
233 // Read-only setting is always disabled.
234 dict->SetBoolean("disabled",
235 !controlled_by.empty() || !IsSettingWritable(pref_name));
232 return std::move(dict); 236 return std::move(dict);
233 } 237 }
234 238
235 void CoreChromeOSOptionsHandler::ObservePref(const std::string& pref_name) { 239 void CoreChromeOSOptionsHandler::ObservePref(const std::string& pref_name) {
236 if (proxy_cros_settings_parser::IsProxyPref(pref_name)) { 240 if (proxy_cros_settings_parser::IsProxyPref(pref_name)) {
237 // We observe those all the time. 241 // We observe those all the time.
238 return; 242 return;
239 } 243 }
240 if (!CrosSettings::IsCrosSettings(pref_name)) 244 if (!CrosSettings::IsCrosSettings(pref_name))
241 return ::options::CoreOptionsHandler::ObservePref(pref_name); 245 return ::options::CoreOptionsHandler::ObservePref(pref_name);
(...skipping 14 matching lines...) Expand all
256 proxy_cros_settings_parser::SetProxyPrefValue( 260 proxy_cros_settings_parser::SetProxyPrefValue(
257 network_guid_, pref_name, value, GetUiProxyConfigService()); 261 network_guid_, pref_name, value, GetUiProxyConfigService());
258 base::Value proxy_type(pref_name); 262 base::Value proxy_type(pref_name);
259 web_ui()->CallJavascriptFunctionUnsafe( 263 web_ui()->CallJavascriptFunctionUnsafe(
260 "options.internet.DetailsInternetPage.updateProxySettings", proxy_type); 264 "options.internet.DetailsInternetPage.updateProxySettings", proxy_type);
261 ProcessUserMetric(value, metric); 265 ProcessUserMetric(value, metric);
262 return; 266 return;
263 } 267 }
264 if (!CrosSettings::IsCrosSettings(pref_name)) 268 if (!CrosSettings::IsCrosSettings(pref_name))
265 return ::options::CoreOptionsHandler::SetPref(pref_name, value, metric); 269 return ::options::CoreOptionsHandler::SetPref(pref_name, value, metric);
270 if (!IsSettingWritable(pref_name)) {
271 NOTREACHED() << pref_name;
272 return;
273 }
266 OwnerSettingsServiceChromeOS* service = 274 OwnerSettingsServiceChromeOS* service =
267 OwnerSettingsServiceChromeOS::FromWebUI(web_ui()); 275 OwnerSettingsServiceChromeOS::FromWebUI(web_ui());
268 if (service && service->HandlesSetting(pref_name)) 276 if (service && service->HandlesSetting(pref_name))
269 service->Set(pref_name, *value); 277 service->Set(pref_name, *value);
270 else 278 else
271 CrosSettings::Get()->Set(pref_name, *value); 279 CrosSettings::Get()->Set(pref_name, *value);
272 280
273 ProcessUserMetric(value, metric); 281 ProcessUserMetric(value, metric);
274 } 282 }
275 283
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 network_guid_, proxy_cros_settings_parser::kProxySettings[i], 426 network_guid_, proxy_cros_settings_parser::kProxySettings[i],
419 GetUiProxyConfigService(), &value); 427 GetUiProxyConfigService(), &value);
420 DCHECK(value); 428 DCHECK(value);
421 DispatchPrefChangeNotification( 429 DispatchPrefChangeNotification(
422 proxy_cros_settings_parser::kProxySettings[i], std::move(value)); 430 proxy_cros_settings_parser::kProxySettings[i], std::move(value));
423 } 431 }
424 } 432 }
425 433
426 } // namespace options 434 } // namespace options
427 } // namespace chromeos 435 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698