Chromium Code Reviews| 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" | |
|
bartfab (slow)
2014/12/08 16:49:45
Nit: Not used.
cschuet (SLOW)
2014/12/08 18:57:04
Done.
| |
| 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; | |
|
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.
| |
| 18 if (delegate_) { | |
| 19 shutdown_policy_subscription_ = cros_settings_->AddSettingsObserver( | |
| 20 kShutdownIsReboot, | |
| 21 base::Bind(&ShutdownPolicyObserver::OnShutdownPolicyChanged, | |
| 22 weak_factory_.GetWeakPtr())); | |
| 23 } else { | |
| 24 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.
| |
| 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_is_reboot = false; | |
| 46 cros_settings_->GetBoolean(kShutdownIsReboot, &shutdown_is_reboot); | |
| 47 if (delegate_) | |
| 48 delegate_->OnShutdownPolicyChanged(shutdown_is_reboot); | |
| 49 } | |
| 50 | |
| 51 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.
| |
| 52 const ShutdownIsRebootCallback& callback) { | |
| 53 CrosSettingsProvider::TrustedStatus status = | |
| 54 cros_settings_->PrepareTrustedValues( | |
| 55 base::Bind(&ShutdownPolicyObserver::CheckIfShutdownIsReboot, | |
| 56 weak_factory_.GetWeakPtr(), callback)); | |
| 57 if (status != CrosSettingsProvider::TRUSTED) | |
| 58 return; | |
| 59 | |
| 60 // Get the updated policy. | |
| 61 bool shutdown_is_reboot = false; | |
| 62 cros_settings_->GetBoolean(kShutdownIsReboot, &shutdown_is_reboot); | |
| 63 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.
| |
| 64 } | |
| 65 | |
| 66 } // namespace chromeos | |
| OLD | NEW |