| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/ui/webui/chromeos/login/shutdown_policy_observer.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" |
| 9 #include "chromeos/settings/cros_settings_names.h" |
| 10 #include "chromeos/settings/cros_settings_provider.h" |
| 11 |
| 12 namespace chromeos { |
| 13 |
| 14 ShutdownPolicyObserver::ShutdownPolicyObserver(CrosSettings* cros_settings, |
| 15 Delegate* delegate) |
| 16 : cros_settings_(cros_settings), delegate_(nullptr), weak_factory_(this) { |
| 17 delegate_ = delegate; |
| 18 if (delegate_) { |
| 19 shutdown_policy_subscription_ = cros_settings_->AddSettingsObserver( |
| 20 kShutdownAllowed, |
| 21 base::Bind(&ShutdownPolicyObserver::OnShutdownPolicyChanged, |
| 22 weak_factory_.GetWeakPtr())); |
| 23 } else { |
| 24 shutdown_policy_subscription_.reset(); |
| 25 } |
| 26 } |
| 27 |
| 28 ShutdownPolicyObserver::~ShutdownPolicyObserver() { |
| 29 } |
| 30 |
| 31 void ShutdownPolicyObserver::Shutdown() { |
| 32 shutdown_policy_subscription_.reset(); |
| 33 delegate_ = nullptr; |
| 34 } |
| 35 |
| 36 void ShutdownPolicyObserver::OnShutdownPolicyChanged() { |
| 37 CrosSettingsProvider::TrustedStatus status = |
| 38 cros_settings_->PrepareTrustedValues( |
| 39 base::Bind(&ShutdownPolicyObserver::OnShutdownPolicyChanged, |
| 40 weak_factory_.GetWeakPtr())); |
| 41 if (status != CrosSettingsProvider::TRUSTED) |
| 42 return; |
| 43 |
| 44 // Get the updated policy. |
| 45 bool shutdown_allowed = true; |
| 46 cros_settings_->GetBoolean(kShutdownAllowed, &shutdown_allowed); |
| 47 if (delegate_) |
| 48 delegate_->OnShutdownPolicyChanged(shutdown_allowed); |
| 49 } |
| 50 |
| 51 void ShutdownPolicyObserver::CheckIfShutdownAllowed( |
| 52 const ShutdownAllowedCallback& callback) { |
| 53 CrosSettingsProvider::TrustedStatus status = |
| 54 cros_settings_->PrepareTrustedValues( |
| 55 base::Bind(&ShutdownPolicyObserver::CheckIfShutdownAllowed, |
| 56 weak_factory_.GetWeakPtr(), callback)); |
| 57 if (status != CrosSettingsProvider::TRUSTED) |
| 58 return; |
| 59 |
| 60 // Get the updated policy. |
| 61 bool shutdown_allowed = true; |
| 62 cros_settings_->GetBoolean(kShutdownAllowed, &shutdown_allowed); |
| 63 callback.Run(shutdown_allowed); |
| 64 } |
| 65 |
| 66 } // namespace chromeos |
| OLD | NEW |