OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/user_cros_settings_provider.h" | 5 #include "chrome/browser/chromeos/user_cros_settings_provider.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <set> | 8 #include <set> |
9 | 9 |
| 10 #include "base/bind.h" |
| 11 #include "base/callback.h" |
10 #include "base/hash_tables.h" | 12 #include "base/hash_tables.h" |
11 #include "base/logging.h" | 13 #include "base/logging.h" |
12 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
13 #include "base/string_util.h" | 15 #include "base/string_util.h" |
14 #include "base/task.h" | 16 #include "base/task.h" |
15 #include "base/values.h" | 17 #include "base/values.h" |
16 #include "chrome/browser/browser_process.h" | 18 #include "chrome/browser/browser_process.h" |
17 #include "chrome/browser/chromeos/cros/cros_library.h" | 19 #include "chrome/browser/chromeos/cros/cros_library.h" |
18 #include "chrome/browser/chromeos/cros/login_library.h" | 20 #include "chrome/browser/chromeos/cros/login_library.h" |
19 #include "chrome/browser/chromeos/cros/network_library.h" | 21 #include "chrome/browser/chromeos/cros/network_library.h" |
(...skipping 29 matching lines...) Expand all Loading... |
49 | 51 |
50 const char* kStringSettings[] = { | 52 const char* kStringSettings[] = { |
51 kDeviceOwner, | 53 kDeviceOwner, |
52 kReleaseChannel | 54 kReleaseChannel |
53 }; | 55 }; |
54 | 56 |
55 const char* kListSettings[] = { | 57 const char* kListSettings[] = { |
56 kAccountsPrefUsers | 58 kAccountsPrefUsers |
57 }; | 59 }; |
58 | 60 |
| 61 // Only write the property if the owner is the current logged on user. |
| 62 void StartStorePropertyOpIfOwner(const std::string& name, |
| 63 const std::string& value, |
| 64 SignedSettingsHelper::Callback* callback) { |
| 65 if (OwnershipService::GetSharedInstance()->CurrentUserIsOwner()) { |
| 66 BrowserThread::PostTask(BrowserThread::UI, |
| 67 FROM_HERE, |
| 68 base::Bind( |
| 69 &SignedSettingsHelper::StartStorePropertyOp, |
| 70 base::Unretained(SignedSettingsHelper::Get()), |
| 71 name, |
| 72 value, |
| 73 callback)); |
| 74 } |
| 75 } |
| 76 |
59 bool IsControlledBooleanSetting(const std::string& pref_path) { | 77 bool IsControlledBooleanSetting(const std::string& pref_path) { |
60 // TODO(nkostylev): Using std::find for 4 value array generates this warning | 78 // TODO(nkostylev): Using std::find for 4 value array generates this warning |
61 // in chroot stl_algo.h:231: error: array subscript is above array bounds. | 79 // in chroot stl_algo.h:231: error: array subscript is above array bounds. |
62 // GCC 4.4.3 | 80 // GCC 4.4.3 |
63 return (pref_path == kAccountsPrefAllowNewUser) || | 81 return (pref_path == kAccountsPrefAllowNewUser) || |
64 (pref_path == kAccountsPrefAllowGuest) || | 82 (pref_path == kAccountsPrefAllowGuest) || |
65 (pref_path == kAccountsPrefShowUserNamesOnSignIn) || | 83 (pref_path == kAccountsPrefShowUserNamesOnSignIn) || |
66 (pref_path == kSignedDataRoamingEnabled) || | 84 (pref_path == kSignedDataRoamingEnabled) || |
67 (pref_path == kStatsReportingPref); | 85 (pref_path == kStatsReportingPref); |
68 } | 86 } |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 } | 334 } |
317 } else if (path == kStatsReportingPref) { | 335 } else if (path == kStatsReportingPref) { |
318 bool stats_consent = (use_value == USE_VALUE_SUPPLIED) ? value : false; | 336 bool stats_consent = (use_value == USE_VALUE_SUPPLIED) ? value : false; |
319 // TODO(pastarmovj): Remove this once migration is not needed anymore. | 337 // TODO(pastarmovj): Remove this once migration is not needed anymore. |
320 // If the value is not set we should try to migrate legacy consent file. | 338 // If the value is not set we should try to migrate legacy consent file. |
321 if (use_value == USE_VALUE_DEFAULT) { | 339 if (use_value == USE_VALUE_DEFAULT) { |
322 // Loading consent file state causes us to do blocking IO on UI thread. | 340 // Loading consent file state causes us to do blocking IO on UI thread. |
323 // Temporarily allow it until we fix http://crbug.com/62626 | 341 // Temporarily allow it until we fix http://crbug.com/62626 |
324 base::ThreadRestrictions::ScopedAllowIO allow_io; | 342 base::ThreadRestrictions::ScopedAllowIO allow_io; |
325 stats_consent = GoogleUpdateSettings::GetCollectStatsConsent(); | 343 stats_consent = GoogleUpdateSettings::GetCollectStatsConsent(); |
326 // Store this value if possible. | 344 // Only store settings if the owner is logged on, otherwise the write |
327 SignedSettingsHelper::Get()->StartStorePropertyOp( | 345 // will fail, triggering another read and we'll end up in an infinite |
328 path, stats_consent ? "true" : "false", this); | 346 // loop. Owner check needs to be done on the FILE thread. |
| 347 BrowserThread::PostTask(BrowserThread::FILE, |
| 348 FROM_HERE, |
| 349 base::Bind(&StartStorePropertyOpIfOwner, path, |
| 350 stats_consent ? "true" : "false", |
| 351 this)); |
329 UpdateCacheBool(path, stats_consent, USE_VALUE_SUPPLIED); | 352 UpdateCacheBool(path, stats_consent, USE_VALUE_SUPPLIED); |
330 LOG(WARNING) << "No metrics policy set will revert to checking " | 353 LOG(WARNING) << "No metrics policy set will revert to checking " |
331 << "consent file which is " | 354 << "consent file which is " |
332 << (stats_consent ? "on." : "off."); | 355 << (stats_consent ? "on." : "off."); |
333 } | 356 } |
334 // TODO(pastarmovj): Remove this once we don't need to regenerate the | 357 // TODO(pastarmovj): Remove this once we don't need to regenerate the |
335 // consent file for the GUID anymore. | 358 // consent file for the GUID anymore. |
336 VLOG(1) << "Metrics policy is being set to : " << stats_consent | 359 VLOG(1) << "Metrics policy is being set to : " << stats_consent |
337 << "(reason : " << use_value << ")"; | 360 << "(reason : " << use_value << ")"; |
338 OptionsUtil::ResolveMetricsReportingEnabled(stats_consent); | 361 OptionsUtil::ResolveMetricsReportingEnabled(stats_consent); |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 if (cached_whitelist_update->Remove(email_value, NULL)) | 687 if (cached_whitelist_update->Remove(email_value, NULL)) |
665 prefs->ScheduleSavePersistentPrefs(); | 688 prefs->ScheduleSavePersistentPrefs(); |
666 } | 689 } |
667 | 690 |
668 // static | 691 // static |
669 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { | 692 void UserCrosSettingsProvider::UpdateCachedOwner(const std::string& email) { |
670 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); | 693 UpdateCacheString(kDeviceOwner, email, USE_VALUE_SUPPLIED); |
671 } | 694 } |
672 | 695 |
673 } // namespace chromeos | 696 } // namespace chromeos |
OLD | NEW |