Chromium Code Reviews| Index: chrome/browser/ui/webui/chromeos/login/shutdown_policy_observer.cc |
| diff --git a/chrome/browser/ui/webui/chromeos/login/shutdown_policy_observer.cc b/chrome/browser/ui/webui/chromeos/login/shutdown_policy_observer.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6e0ee70b06a84da31048adbec029419308b7fd14 |
| --- /dev/null |
| +++ b/chrome/browser/ui/webui/chromeos/login/shutdown_policy_observer.cc |
| @@ -0,0 +1,66 @@ |
| +// Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/webui/chromeos/login/shutdown_policy_observer.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/bind_helpers.h" |
|
bartfab (slow)
2014/12/08 16:49:45
Nit: Not used.
cschuet (SLOW)
2014/12/08 18:57:04
Done.
|
| +#include "chromeos/settings/cros_settings_names.h" |
| +#include "chromeos/settings/cros_settings_provider.h" |
| + |
| +namespace chromeos { |
| + |
| +ShutdownPolicyObserver::ShutdownPolicyObserver(CrosSettings* cros_settings, |
| + Delegate* delegate) |
| + : cros_settings_(cros_settings), delegate_(nullptr), weak_factory_(this) { |
| + delegate_ = delegate; |
|
bartfab (slow)
2014/12/08 16:49:45
Nit: Move this to the initialization one line abov
cschuet (SLOW)
2014/12/08 18:57:04
Done.
|
| + if (delegate_) { |
| + shutdown_policy_subscription_ = cros_settings_->AddSettingsObserver( |
| + kShutdownIsReboot, |
| + base::Bind(&ShutdownPolicyObserver::OnShutdownPolicyChanged, |
| + weak_factory_.GetWeakPtr())); |
| + } else { |
| + shutdown_policy_subscription_.reset(); |
|
bartfab (slow)
2014/12/08 16:49:45
This is unnecessary. Since we are in the construct
cschuet (SLOW)
2014/12/08 18:57:04
Done.
|
| + } |
| +} |
| + |
| +ShutdownPolicyObserver::~ShutdownPolicyObserver() { |
| +} |
| + |
| +void ShutdownPolicyObserver::Shutdown() { |
| + shutdown_policy_subscription_.reset(); |
| + delegate_ = nullptr; |
| +} |
| + |
| +void ShutdownPolicyObserver::OnShutdownPolicyChanged() { |
| + CrosSettingsProvider::TrustedStatus status = |
| + cros_settings_->PrepareTrustedValues( |
| + base::Bind(&ShutdownPolicyObserver::OnShutdownPolicyChanged, |
| + weak_factory_.GetWeakPtr())); |
| + if (status != CrosSettingsProvider::TRUSTED) |
| + return; |
| + |
| + // Get the updated policy. |
| + bool shutdown_is_reboot = false; |
| + cros_settings_->GetBoolean(kShutdownIsReboot, &shutdown_is_reboot); |
| + if (delegate_) |
| + delegate_->OnShutdownPolicyChanged(shutdown_is_reboot); |
| +} |
| + |
| +void ShutdownPolicyObserver::CheckIfShutdownIsReboot( |
|
bartfab (slow)
2014/12/08 16:49:45
You can extract the logic shared by OnShutdownPoli
cschuet (SLOW)
2014/12/08 18:57:04
Done.
|
| + const ShutdownIsRebootCallback& callback) { |
| + CrosSettingsProvider::TrustedStatus status = |
| + cros_settings_->PrepareTrustedValues( |
| + base::Bind(&ShutdownPolicyObserver::CheckIfShutdownIsReboot, |
| + weak_factory_.GetWeakPtr(), callback)); |
| + if (status != CrosSettingsProvider::TRUSTED) |
| + return; |
| + |
| + // Get the updated policy. |
| + bool shutdown_is_reboot = false; |
| + cros_settings_->GetBoolean(kShutdownIsReboot, &shutdown_is_reboot); |
| + callback.Run(shutdown_is_reboot); |
|
bartfab (slow)
2014/12/08 16:49:45
Nit: #include "base/callback.h"
cschuet (SLOW)
2014/12/08 18:57:04
Done.
|
| +} |
| + |
| +} // namespace chromeos |