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

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

Issue 9355044: Added KioskModeAppPack proto. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased 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"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/threading/thread_restrictions.h" 13 #include "base/threading/thread_restrictions.h"
14 #include "base/values.h" 14 #include "base/values.h"
15 #include "chrome/browser/browser_process.h" 15 #include "chrome/browser/browser_process.h"
16 #include "chrome/browser/chromeos/cros/cros_library.h" 16 #include "chrome/browser/chromeos/cros/cros_library.h"
17 #include "chrome/browser/chromeos/cros/network_library.h" 17 #include "chrome/browser/chromeos/cros/network_library.h"
18 #include "chrome/browser/chromeos/cros_settings.h" 18 #include "chrome/browser/chromeos/cros_settings.h"
19 #include "chrome/browser/chromeos/cros_settings_names.h" 19 #include "chrome/browser/chromeos/cros_settings_names.h"
20 #include "chrome/browser/chromeos/login/ownership_service.h" 20 #include "chrome/browser/chromeos/login/ownership_service.h"
21 #include "chrome/browser/chromeos/login/signed_settings_cache.h" 21 #include "chrome/browser/chromeos/login/signed_settings_cache.h"
22 #include "chrome/browser/chromeos/login/signed_settings_helper.h"
22 #include "chrome/browser/chromeos/login/user_manager.h" 23 #include "chrome/browser/chromeos/login/user_manager.h"
24 #include "chrome/browser/policy/app_pack_updater.h"
23 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h" 25 #include "chrome/browser/policy/proto/chrome_device_policy.pb.h"
24 #include "chrome/browser/prefs/pref_value_map.h"
25 #include "chrome/browser/ui/options/options_util.h" 26 #include "chrome/browser/ui/options/options_util.h"
26 #include "chrome/common/chrome_notification_types.h" 27 #include "chrome/common/chrome_notification_types.h"
27 #include "chrome/installer/util/google_update_settings.h" 28 #include "chrome/installer/util/google_update_settings.h"
28 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
30 30
31 using google::protobuf::RepeatedPtrField; 31 using google::protobuf::RepeatedPtrField;
32 32
33 namespace em = enterprise_management; 33 namespace em = enterprise_management;
34 34
35 namespace chromeos { 35 namespace chromeos {
36 36
37 namespace { 37 namespace {
38 38
39 const char* kBooleanSettings[] = { 39 // List of settings handled by the DeviceSettingsProvider.
40 const char* kKnownSettings[] = {
41 kAccountsPrefAllowGuest,
40 kAccountsPrefAllowNewUser, 42 kAccountsPrefAllowNewUser,
41 kAccountsPrefAllowGuest, 43 kAccountsPrefEphemeralUsersEnabled,
42 kAccountsPrefShowUserNamesOnSignIn, 44 kAccountsPrefShowUserNamesOnSignIn,
43 kAccountsPrefEphemeralUsersEnabled, 45 kAccountsPrefUsers,
46 kAppPack,
47 kDeviceOwner,
48 kReleaseChannel,
49 kReportDeviceActivityTimes,
50 kReportDeviceBootMode,
51 kReportDeviceVersionInfo,
52 kSettingProxyEverywhere,
44 kSignedDataRoamingEnabled, 53 kSignedDataRoamingEnabled,
45 kStatsReportingPref, 54 kStatsReportingPref,
46 kReportDeviceVersionInfo,
47 kReportDeviceActivityTimes,
48 kReportDeviceBootMode
49 };
50
51 const char* kStringSettings[] = {
52 kDeviceOwner,
53 kReleaseChannel,
54 kSettingProxyEverywhere
55 };
56
57 const char* kListSettings[] = {
58 kAccountsPrefUsers
59 }; 55 };
60 56
61 // Upper bound for number of retries to fetch a signed setting. 57 // Upper bound for number of retries to fetch a signed setting.
62 static const int kNumRetriesLimit = 9; 58 static const int kNumRetriesLimit = 9;
63 59
64 // Legacy policy file location. Used to detect migration from pre v12 ChormeOS. 60 // Legacy policy file location. Used to detect migration from pre v12 ChromeOS.
65 const char kLegacyPolicyFile[] = "/var/lib/whitelist/preferences"; 61 const char kLegacyPolicyFile[] = "/var/lib/whitelist/preferences";
66 62
67 bool IsControlledBooleanSetting(const std::string& pref_path) {
68 const char** end = kBooleanSettings + arraysize(kBooleanSettings);
69 return std::find(kBooleanSettings, end, pref_path) != end;
70 }
71
72 bool IsControlledStringSetting(const std::string& pref_path) {
73 const char** end = kStringSettings + arraysize(kStringSettings);
74 return std::find(kStringSettings, end, pref_path) != end;
75 }
76
77 bool IsControlledListSetting(const std::string& pref_path) {
78 const char** end = kListSettings + arraysize(kListSettings);
79 return std::find(kListSettings, end, pref_path) != end;
80 }
81
82 bool IsControlledSetting(const std::string& pref_path) { 63 bool IsControlledSetting(const std::string& pref_path) {
83 return (IsControlledBooleanSetting(pref_path) || 64 const char** end = kKnownSettings + arraysize(kKnownSettings);
84 IsControlledStringSetting(pref_path) || 65 return std::find(kKnownSettings, end, pref_path) != end;
85 IsControlledListSetting(pref_path));
86 } 66 }
87 67
88 bool HasOldMetricsFile() { 68 bool HasOldMetricsFile() {
89 // TODO(pastarmovj): Remove this once migration is not needed anymore. 69 // TODO(pastarmovj): Remove this once migration is not needed anymore.
90 // If the value is not set we should try to migrate legacy consent file. 70 // If the value is not set we should try to migrate legacy consent file.
91 // Loading consent file state causes us to do blocking IO on UI thread. 71 // Loading consent file state causes us to do blocking IO on UI thread.
92 // Temporarily allow it until we fix http://crbug.com/62626 72 // Temporarily allow it until we fix http://crbug.com/62626
93 base::ThreadRestrictions::ScopedAllowIO allow_io; 73 base::ThreadRestrictions::ScopedAllowIO allow_io;
94 return GoogleUpdateSettings::GetCollectStatsConsent(); 74 return GoogleUpdateSettings::GetCollectStatsConsent();
95 } 75 }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } else if (prop == kAccountsPrefEphemeralUsersEnabled) { 267 } else if (prop == kAccountsPrefEphemeralUsersEnabled) {
288 em::EphemeralUsersEnabledProto* ephemeral_users_enabled = 268 em::EphemeralUsersEnabledProto* ephemeral_users_enabled =
289 pol.mutable_ephemeral_users_enabled(); 269 pol.mutable_ephemeral_users_enabled();
290 bool ephemeral_users_enabled_value = false; 270 bool ephemeral_users_enabled_value = false;
291 if (value->GetAsBoolean(&ephemeral_users_enabled_value)) 271 if (value->GetAsBoolean(&ephemeral_users_enabled_value))
292 ephemeral_users_enabled->set_ephemeral_users_enabled( 272 ephemeral_users_enabled->set_ephemeral_users_enabled(
293 ephemeral_users_enabled_value); 273 ephemeral_users_enabled_value);
294 else 274 else
295 NOTREACHED(); 275 NOTREACHED();
296 } else { 276 } else {
297 // kReportDeviceVersionInfo, kReportDeviceActivityTimes, and 277 // The remaining settings don't support Set(), since they are not
298 // kReportDeviceBootMode do not support being set in the policy, since 278 // intended to be customizable by the user:
299 // they are not intended to be user-controlled. 279 // kAppPack
280 // kReportDeviceVersionInfo
281 // kReportDeviceActivityTimes
282 // kReportDeviceBootMode
300 NOTREACHED(); 283 NOTREACHED();
301 } 284 }
302 data.set_policy_value(pol.SerializeAsString()); 285 data.set_policy_value(pol.SerializeAsString());
303 // Set the cache to the updated value. 286 // Set the cache to the updated value.
304 policy_ = data; 287 policy_ = data;
305 UpdateValuesCache(); 288 UpdateValuesCache();
306 289
307 if (!signed_settings_cache::Store(data, g_browser_process->local_state())) 290 if (!signed_settings_cache::Store(data, g_browser_process->local_state()))
308 LOG(ERROR) << "Couldn't store to the temp storage."; 291 LOG(ERROR) << "Couldn't store to the temp storage.";
309 292
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 pol.device_reporting().report_version_info()); 417 pol.device_reporting().report_version_info());
435 } 418 }
436 // TODO(dubroy): Re-add device activity time policy here when the UI 419 // TODO(dubroy): Re-add device activity time policy here when the UI
437 // to notify the user has been implemented (http://crosbug.com/26252). 420 // to notify the user has been implemented (http://crosbug.com/26252).
438 if (pol.device_reporting().has_report_boot_mode()) { 421 if (pol.device_reporting().has_report_boot_mode()) {
439 new_values_cache.SetBoolean(kReportDeviceBootMode, 422 new_values_cache.SetBoolean(kReportDeviceBootMode,
440 pol.device_reporting().report_boot_mode()); 423 pol.device_reporting().report_boot_mode());
441 } 424 }
442 } 425 }
443 426
427 if (pol.has_app_pack()) {
428 typedef RepeatedPtrField<em::AppPackEntryProto> proto_type;
429 base::ListValue* list = new base::ListValue;
430 const proto_type& app_pack = pol.app_pack().app_pack();
431 for (proto_type::const_iterator it = app_pack.begin();
432 it != app_pack.end(); ++it) {
433 base::DictionaryValue* entry = new base::DictionaryValue;
434 if (it->has_extension_id()) {
435 entry->SetString(policy::AppPackUpdater::kExtensionId,
436 it->extension_id());
437 }
438 if (it->has_update_url())
439 entry->SetString(policy::AppPackUpdater::kUpdateUrl, it->update_url());
440 if (it->has_key_checksum()) {
441 entry->SetString(policy::AppPackUpdater::kKeyChecksum,
442 it->key_checksum());
443 }
444 list->Append(entry);
445 }
446 new_values_cache.SetValue(kAppPack, list);
447 }
448
444 // Collect all notifications but send them only after we have swapped the 449 // Collect all notifications but send them only after we have swapped the
445 // cache so that if somebody actually reads the cache will be already valid. 450 // cache so that if somebody actually reads the cache will be already valid.
446 std::vector<std::string> notifications; 451 std::vector<std::string> notifications;
447 // Go through the new values and verify in the old ones. 452 // Go through the new values and verify in the old ones.
448 PrefValueMap::iterator iter = new_values_cache.begin(); 453 PrefValueMap::iterator iter = new_values_cache.begin();
449 for (; iter != new_values_cache.end(); ++iter) { 454 for (; iter != new_values_cache.end(); ++iter) {
450 const base::Value* old_value; 455 const base::Value* old_value;
451 if (!values_cache_.GetValue(iter->first, &old_value) || 456 if (!values_cache_.GetValue(iter->first, &old_value) ||
452 !old_value->Equals(iter->second)) { 457 !old_value->Equals(iter->second)) {
453 notifications.push_back(iter->first); 458 notifications.push_back(iter->first);
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 Reload(); 650 Reload();
646 return; 651 return;
647 } 652 }
648 LOG(ERROR) << "No retries left"; 653 LOG(ERROR) << "No retries left";
649 break; 654 break;
650 } 655 }
651 } 656 }
652 } 657 }
653 658
654 } // namespace chromeos 659 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/device_settings_provider.h ('k') | chrome/browser/policy/app_pack_updater.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698