OLD | NEW |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 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 | 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/ui/webui/chromeos/login/shutdown_policy_observer.h" | 5 #include "chrome/browser/chromeos/settings/shutdown_policy_handler.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
9 #include "chromeos/settings/cros_settings_names.h" | 9 #include "chromeos/settings/cros_settings_names.h" |
10 #include "chromeos/settings/cros_settings_provider.h" | 10 #include "chromeos/settings/cros_settings_provider.h" |
11 | 11 |
12 namespace chromeos { | 12 namespace chromeos { |
13 | 13 |
14 ShutdownPolicyObserver::ShutdownPolicyObserver(CrosSettings* cros_settings, | 14 ShutdownPolicyHandler::ShutdownPolicyHandler(CrosSettings* cros_settings, |
15 Delegate* delegate) | 15 Delegate* delegate) |
16 : cros_settings_(cros_settings), delegate_(delegate), weak_factory_(this) { | 16 : cros_settings_(cros_settings), delegate_(delegate), weak_factory_(this) { |
17 if (delegate_) { | 17 if (delegate_) { |
18 shutdown_policy_subscription_ = cros_settings_->AddSettingsObserver( | 18 shutdown_policy_subscription_ = cros_settings_->AddSettingsObserver( |
19 kRebootOnShutdown, | 19 kRebootOnShutdown, |
20 base::Bind(&ShutdownPolicyObserver::OnShutdownPolicyChanged, | 20 base::Bind(&ShutdownPolicyHandler::OnShutdownPolicyChanged, |
21 weak_factory_.GetWeakPtr())); | 21 weak_factory_.GetWeakPtr())); |
22 } | 22 } |
23 } | 23 } |
24 | 24 |
25 ShutdownPolicyObserver::~ShutdownPolicyObserver() { | 25 ShutdownPolicyHandler::~ShutdownPolicyHandler() { |
26 } | 26 } |
27 | 27 |
28 void ShutdownPolicyObserver::Shutdown() { | 28 void ShutdownPolicyHandler::Shutdown() { |
29 shutdown_policy_subscription_.reset(); | 29 shutdown_policy_subscription_.reset(); |
30 delegate_ = nullptr; | 30 delegate_ = nullptr; |
31 } | 31 } |
32 | 32 |
33 void ShutdownPolicyObserver::CallDelegate(bool reboot_on_shutdown) { | 33 void ShutdownPolicyHandler::CallDelegate(bool reboot_on_shutdown) { |
34 if (delegate_) | 34 if (delegate_) |
35 delegate_->OnShutdownPolicyChanged(reboot_on_shutdown); | 35 delegate_->OnShutdownPolicyChanged(reboot_on_shutdown); |
36 } | 36 } |
37 | 37 |
38 void ShutdownPolicyObserver::OnShutdownPolicyChanged() { | 38 void ShutdownPolicyHandler::OnShutdownPolicyChanged() { |
39 CheckIfRebootOnShutdown(base::Bind(&ShutdownPolicyObserver::CallDelegate, | 39 CheckIfRebootOnShutdown(base::Bind(&ShutdownPolicyHandler::CallDelegate, |
40 weak_factory_.GetWeakPtr())); | 40 weak_factory_.GetWeakPtr())); |
41 } | 41 } |
42 | 42 |
43 void ShutdownPolicyObserver::CheckIfRebootOnShutdown( | 43 void ShutdownPolicyHandler::CheckIfRebootOnShutdown( |
44 const RebootOnShutdownCallback& callback) { | 44 const RebootOnShutdownCallback& callback) { |
45 CrosSettingsProvider::TrustedStatus status = | 45 CrosSettingsProvider::TrustedStatus status = |
46 cros_settings_->PrepareTrustedValues( | 46 cros_settings_->PrepareTrustedValues( |
47 base::Bind(&ShutdownPolicyObserver::CheckIfRebootOnShutdown, | 47 base::Bind(&ShutdownPolicyHandler::CheckIfRebootOnShutdown, |
48 weak_factory_.GetWeakPtr(), callback)); | 48 weak_factory_.GetWeakPtr(), callback)); |
49 if (status != CrosSettingsProvider::TRUSTED) | 49 if (status != CrosSettingsProvider::TRUSTED) |
50 return; | 50 return; |
51 | 51 |
52 // Get the updated policy. | 52 // Get the updated policy. |
53 bool reboot_on_shutdown = false; | 53 bool reboot_on_shutdown = false; |
54 cros_settings_->GetBoolean(kRebootOnShutdown, &reboot_on_shutdown); | 54 cros_settings_->GetBoolean(kRebootOnShutdown, &reboot_on_shutdown); |
55 callback.Run(reboot_on_shutdown); | 55 callback.Run(reboot_on_shutdown); |
56 } | 56 } |
57 | 57 |
58 } // namespace chromeos | 58 } // namespace chromeos |
OLD | NEW |