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

Side by Side Diff: chrome/browser/chromeos/device_settings_provider.cc

Issue 9423043: Add the protobufs for the set of session timeout policies planned for the kiosk mode. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated the protobuf according to the discussion and added client side binding. Created 8 years, 10 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 | Annotate | Revision Log
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/chromeos/device_settings_provider.h" 5 #include "chrome/browser/chromeos/device_settings_provider.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 27 matching lines...) Expand all
38 38
39 // List of settings handled by the DeviceSettingsProvider. 39 // List of settings handled by the DeviceSettingsProvider.
40 const char* kKnownSettings[] = { 40 const char* kKnownSettings[] = {
41 kAccountsPrefAllowGuest, 41 kAccountsPrefAllowGuest,
42 kAccountsPrefAllowNewUser, 42 kAccountsPrefAllowNewUser,
43 kAccountsPrefEphemeralUsersEnabled, 43 kAccountsPrefEphemeralUsersEnabled,
44 kAccountsPrefShowUserNamesOnSignIn, 44 kAccountsPrefShowUserNamesOnSignIn,
45 kAccountsPrefUsers, 45 kAccountsPrefUsers,
46 kAppPack, 46 kAppPack,
47 kDeviceOwner, 47 kDeviceOwner,
48 kIdleLogoutTimeout,
49 kIdleLogoutWarningDuration,
48 kReleaseChannel, 50 kReleaseChannel,
49 kReportDeviceActivityTimes, 51 kReportDeviceActivityTimes,
50 kReportDeviceBootMode, 52 kReportDeviceBootMode,
51 kReportDeviceVersionInfo, 53 kReportDeviceVersionInfo,
54 kScreenSaverExtensionId,
55 kScreenSaverTimeout,
52 kSettingProxyEverywhere, 56 kSettingProxyEverywhere,
53 kSignedDataRoamingEnabled, 57 kSignedDataRoamingEnabled,
54 kStatsReportingPref, 58 kStatsReportingPref,
55 }; 59 };
56 60
57 // Upper bound for number of retries to fetch a signed setting. 61 // Upper bound for number of retries to fetch a signed setting.
58 static const int kNumRetriesLimit = 9; 62 static const int kNumRetriesLimit = 9;
59 63
60 // Legacy policy file location. Used to detect migration from pre v12 ChromeOS. 64 // Legacy policy file location. Used to detect migration from pre v12 ChromeOS.
61 const char kLegacyPolicyFile[] = "/var/lib/whitelist/preferences"; 65 const char kLegacyPolicyFile[] = "/var/lib/whitelist/preferences";
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 em::EphemeralUsersEnabledProto* ephemeral_users_enabled = 272 em::EphemeralUsersEnabledProto* ephemeral_users_enabled =
269 pol.mutable_ephemeral_users_enabled(); 273 pol.mutable_ephemeral_users_enabled();
270 bool ephemeral_users_enabled_value = false; 274 bool ephemeral_users_enabled_value = false;
271 if (value->GetAsBoolean(&ephemeral_users_enabled_value)) 275 if (value->GetAsBoolean(&ephemeral_users_enabled_value))
272 ephemeral_users_enabled->set_ephemeral_users_enabled( 276 ephemeral_users_enabled->set_ephemeral_users_enabled(
273 ephemeral_users_enabled_value); 277 ephemeral_users_enabled_value);
274 else 278 else
275 NOTREACHED(); 279 NOTREACHED();
276 } else { 280 } else {
277 // The remaining settings don't support Set(), since they are not 281 // The remaining settings don't support Set(), since they are not
278 // intended to be customizable by the user: 282 // intended to be customizable by the user yet:
Mattias Nissler (ping if slow) 2012/03/01 19:58:10 The yet is not accurate. Put it in parens at least
pastarmovj 2012/03/05 17:02:55 Done.
279 // kAppPack 283 // kAppPack
284 // kIdleLogoutTimeout,
285 // kIdleLogoutWarningDuration,
280 // kReportDeviceVersionInfo 286 // kReportDeviceVersionInfo
281 // kReportDeviceActivityTimes 287 // kReportDeviceActivityTimes
282 // kReportDeviceBootMode 288 // kReportDeviceBootMode
289 // kScreenSaverExtensionId,
290 // kScreenSaverTimeout,
291
283 NOTREACHED(); 292 NOTREACHED();
284 } 293 }
285 data.set_policy_value(pol.SerializeAsString()); 294 data.set_policy_value(pol.SerializeAsString());
286 // Set the cache to the updated value. 295 // Set the cache to the updated value.
287 policy_ = data; 296 policy_ = data;
288 UpdateValuesCache(); 297 UpdateValuesCache();
289 298
290 if (!signed_settings_cache::Store(data, g_browser_process->local_state())) 299 if (!signed_settings_cache::Store(data, g_browser_process->local_state()))
291 LOG(ERROR) << "Couldn't store to the temp storage."; 300 LOG(ERROR) << "Couldn't store to the temp storage.";
292 301
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 void DeviceSettingsProvider::UpdateValuesCache() { 334 void DeviceSettingsProvider::UpdateValuesCache() {
326 const em::PolicyData data = policy(); 335 const em::PolicyData data = policy();
327 PrefValueMap new_values_cache; 336 PrefValueMap new_values_cache;
328 337
329 if (data.has_username() && !data.has_request_token()) 338 if (data.has_username() && !data.has_request_token())
330 new_values_cache.SetString(kDeviceOwner, data.username()); 339 new_values_cache.SetString(kDeviceOwner, data.username());
331 340
332 em::ChromeDeviceSettingsProto pol; 341 em::ChromeDeviceSettingsProto pol;
333 pol.ParseFromString(data.policy_value()); 342 pol.ParseFromString(data.policy_value());
334 343
344 // --------------------
345 // Boolean Policies
346 // --------------------
Mattias Nissler (ping if slow) 2012/03/01 19:58:10 Instead of doing this, how about actually breaking
pastarmovj 2012/03/05 17:02:55 Done.
347
335 // For all our boolean settings the following is applicable: 348 // For all our boolean settings the following is applicable:
336 // true is default permissive value and false is safe prohibitive value. 349 // true is default permissive value and false is safe prohibitive value.
337 // Exceptions: 350 // Exceptions:
338 // kSignedDataRoamingEnabled has a default value of false. 351 // kSignedDataRoamingEnabled has a default value of false.
339 // kAccountsPrefEphemeralUsersEnabled has a default value of false. 352 // kAccountsPrefEphemeralUsersEnabled has a default value of false.
340 if (pol.has_allow_new_users() && 353 if (pol.has_allow_new_users() &&
341 pol.allow_new_users().has_allow_new_users() && 354 pol.allow_new_users().has_allow_new_users() &&
342 pol.allow_new_users().allow_new_users()) { 355 pol.allow_new_users().allow_new_users()) {
343 // New users allowed, user_whitelist() ignored. 356 // New users allowed, user_whitelist() ignored.
344 new_values_cache.SetBoolean(kAccountsPrefAllowNewUser, true); 357 new_values_cache.SetBoolean(kAccountsPrefAllowNewUser, true);
(...skipping 26 matching lines...) Expand all
371 pol.has_data_roaming_enabled() && 384 pol.has_data_roaming_enabled() &&
372 pol.data_roaming_enabled().has_data_roaming_enabled() && 385 pol.data_roaming_enabled().has_data_roaming_enabled() &&
373 pol.data_roaming_enabled().data_roaming_enabled()); 386 pol.data_roaming_enabled().data_roaming_enabled());
374 387
375 new_values_cache.SetBoolean( 388 new_values_cache.SetBoolean(
376 kAccountsPrefEphemeralUsersEnabled, 389 kAccountsPrefEphemeralUsersEnabled,
377 pol.has_ephemeral_users_enabled() && 390 pol.has_ephemeral_users_enabled() &&
378 pol.ephemeral_users_enabled().has_ephemeral_users_enabled() && 391 pol.ephemeral_users_enabled().has_ephemeral_users_enabled() &&
379 pol.ephemeral_users_enabled().ephemeral_users_enabled()); 392 pol.ephemeral_users_enabled().ephemeral_users_enabled());
380 393
394 if (pol.has_device_reporting()) {
395 if (pol.device_reporting().has_report_version_info()) {
396 new_values_cache.SetBoolean(kReportDeviceVersionInfo,
397 pol.device_reporting().report_version_info());
398 }
399 // TODO(dubroy): Re-add device activity time policy here when the UI
400 // to notify the user has been implemented (http://crosbug.com/26252).
401 if (pol.device_reporting().has_report_boot_mode()) {
402 new_values_cache.SetBoolean(kReportDeviceBootMode,
403 pol.device_reporting().report_boot_mode());
404 }
405 }
406
407 if (pol.has_metrics_enabled()) {
408 new_values_cache.SetBoolean(kStatsReportingPref,
409 pol.metrics_enabled().metrics_enabled());
410 } else {
411 new_values_cache.SetBoolean(kStatsReportingPref, HasOldMetricsFile());
412 }
413
414 // --------------------
415 // Integer Policies
416 // --------------------
417
418 if (pol.has_screen_saver() &&
419 pol.screen_saver().has_screen_saver_timeout()) {
420 new_values_cache.SetInteger(kScreenSaverTimeout,
421 pol.screen_saver().screen_saver_timeout());
422 }
423
424 if (pol.has_forced_logout_timeouts() &&
425 pol.forced_logout_timeouts().has_idle_logout_timeout()) {
426 new_values_cache.SetInteger(
427 kIdleLogoutTimeout,
428 pol.forced_logout_timeouts().idle_logout_timeout());
429 }
430
431 if (pol.has_forced_logout_timeouts() &&
432 pol.forced_logout_timeouts().has_idle_logout_warning_duration()) {
433 new_values_cache.SetInteger(
434 kIdleLogoutWarningDuration,
435 pol.forced_logout_timeouts().idle_logout_warning_duration());
436 }
437
438 // --------------------
439 // String Policies
440 // --------------------
441
381 // TODO(cmasone): NOTIMPLEMENTED() once http://crosbug.com/13052 is fixed. 442 // TODO(cmasone): NOTIMPLEMENTED() once http://crosbug.com/13052 is fixed.
382 std::string serialized; 443 std::string serialized;
383 if (pol.has_device_proxy_settings() && 444 if (pol.has_device_proxy_settings() &&
384 pol.device_proxy_settings().SerializeToString(&serialized)) { 445 pol.device_proxy_settings().SerializeToString(&serialized)) {
385 new_values_cache.SetString(kSettingProxyEverywhere, serialized); 446 new_values_cache.SetString(kSettingProxyEverywhere, serialized);
386 } 447 }
387 448
388 if (!pol.has_release_channel() || 449 if (!pol.has_release_channel() ||
389 !pol.release_channel().has_release_channel()) { 450 !pol.release_channel().has_release_channel()) {
390 // Default to an invalid channel (will be ignored). 451 // Default to an invalid channel (will be ignored).
391 new_values_cache.SetString(kReleaseChannel, ""); 452 new_values_cache.SetString(kReleaseChannel, "");
392 } else { 453 } else {
393 new_values_cache.SetString(kReleaseChannel, 454 new_values_cache.SetString(kReleaseChannel,
394 pol.release_channel().release_channel()); 455 pol.release_channel().release_channel());
395 } 456 }
396 457
397 if (pol.has_metrics_enabled()) { 458 if (pol.has_screen_saver() &&
398 new_values_cache.SetBoolean(kStatsReportingPref, 459 pol.screen_saver().has_screen_saver_extension_id()) {
399 pol.metrics_enabled().metrics_enabled()); 460 new_values_cache.SetString(kScreenSaverExtensionId,
400 } else { 461 pol.screen_saver().screen_saver_extension_id());
401 new_values_cache.SetBoolean(kStatsReportingPref, HasOldMetricsFile());
402 } 462 }
403 463
464 // --------------------
465 // List Policies
466 // --------------------
404 base::ListValue* list = new base::ListValue(); 467 base::ListValue* list = new base::ListValue();
405 const em::UserWhitelistProto& whitelist_proto = pol.user_whitelist(); 468 const em::UserWhitelistProto& whitelist_proto = pol.user_whitelist();
406 const RepeatedPtrField<std::string>& whitelist = 469 const RepeatedPtrField<std::string>& whitelist =
407 whitelist_proto.user_whitelist(); 470 whitelist_proto.user_whitelist();
408 for (RepeatedPtrField<std::string>::const_iterator it = whitelist.begin(); 471 for (RepeatedPtrField<std::string>::const_iterator it = whitelist.begin();
409 it != whitelist.end(); ++it) { 472 it != whitelist.end(); ++it) {
410 list->Append(base::Value::CreateStringValue(*it)); 473 list->Append(base::Value::CreateStringValue(*it));
411 } 474 }
412 new_values_cache.SetValue(kAccountsPrefUsers, list); 475 new_values_cache.SetValue(kAccountsPrefUsers, list);
413 476
414 if (pol.has_device_reporting()) {
415 if (pol.device_reporting().has_report_version_info()) {
416 new_values_cache.SetBoolean(kReportDeviceVersionInfo,
417 pol.device_reporting().report_version_info());
418 }
419 // TODO(dubroy): Re-add device activity time policy here when the UI
420 // to notify the user has been implemented (http://crosbug.com/26252).
421 if (pol.device_reporting().has_report_boot_mode()) {
422 new_values_cache.SetBoolean(kReportDeviceBootMode,
423 pol.device_reporting().report_boot_mode());
424 }
425 }
426
427 if (pol.has_app_pack()) { 477 if (pol.has_app_pack()) {
428 typedef RepeatedPtrField<em::AppPackEntryProto> proto_type; 478 typedef RepeatedPtrField<em::AppPackEntryProto> proto_type;
429 base::ListValue* list = new base::ListValue; 479 base::ListValue* list = new base::ListValue;
430 const proto_type& app_pack = pol.app_pack().app_pack(); 480 const proto_type& app_pack = pol.app_pack().app_pack();
431 for (proto_type::const_iterator it = app_pack.begin(); 481 for (proto_type::const_iterator it = app_pack.begin();
432 it != app_pack.end(); ++it) { 482 it != app_pack.end(); ++it) {
433 base::DictionaryValue* entry = new base::DictionaryValue; 483 base::DictionaryValue* entry = new base::DictionaryValue;
434 if (it->has_extension_id()) { 484 if (it->has_extension_id()) {
435 entry->SetString(policy::AppPackUpdater::kExtensionId, 485 entry->SetString(policy::AppPackUpdater::kExtensionId,
436 it->extension_id()); 486 it->extension_id());
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 Reload(); 700 Reload();
651 return; 701 return;
652 } 702 }
653 LOG(ERROR) << "No retries left"; 703 LOG(ERROR) << "No retries left";
654 break; 704 break;
655 } 705 }
656 } 706 }
657 } 707 }
658 708
659 } // namespace chromeos 709 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698