OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/policy/remote_commands/device_command_reboot_j
ob.h" | 5 #include "chrome/browser/chromeos/policy/remote_commands/device_command_reboot_j
ob.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/single_thread_task_runner.h" |
12 #include "base/sys_info.h" | 13 #include "base/sys_info.h" |
| 14 #include "base/thread_task_runner_handle.h" |
13 #include "base/time/time.h" | 15 #include "base/time/time.h" |
14 #include "chromeos/dbus/power_manager_client.h" | 16 #include "chromeos/dbus/power_manager_client.h" |
15 #include "policy/proto/device_management_backend.pb.h" | 17 #include "policy/proto/device_management_backend.pb.h" |
16 | 18 |
17 namespace policy { | 19 namespace policy { |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 // Determines the time, measured from the time of issue, after which the command | 23 // Determines the time, measured from the time of issue, after which the command |
22 // queue will consider this command expired if the command has not been started. | 24 // queue will consider this command expired if the command has not been started. |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 // boot time of the system. | 57 // boot time of the system. |
56 const base::TimeDelta uptime = | 58 const base::TimeDelta uptime = |
57 base::TimeDelta::FromMilliseconds(base::SysInfo::Uptime()); | 59 base::TimeDelta::FromMilliseconds(base::SysInfo::Uptime()); |
58 const base::Time boot_time = base::Time::Now() - uptime; | 60 const base::Time boot_time = base::Time::Now() - uptime; |
59 const base::TimeDelta delta = boot_time - issued_time(); | 61 const base::TimeDelta delta = boot_time - issued_time(); |
60 // If the reboot command was issued before the system booted, we inform the | 62 // If the reboot command was issued before the system booted, we inform the |
61 // server that the reboot succeeded. Otherwise, the reboot must still be | 63 // server that the reboot succeeded. Otherwise, the reboot must still be |
62 // performed and we invoke it. |kMinimumUptimeInMinutes| defines a lower limit | 64 // performed and we invoke it. |kMinimumUptimeInMinutes| defines a lower limit |
63 // on the uptime to avoid uninterruptable reboot loops. | 65 // on the uptime to avoid uninterruptable reboot loops. |
64 if (delta > base::TimeDelta()) { | 66 if (delta > base::TimeDelta()) { |
65 succeeded_callback.Run(nullptr); | 67 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 68 FROM_HERE, base::Bind(succeeded_callback, nullptr)); |
66 return; | 69 return; |
67 } | 70 } |
68 | 71 |
69 const base::TimeDelta kZeroTimeDelta; | 72 const base::TimeDelta kZeroTimeDelta; |
70 reboot_timer_.Start( | 73 reboot_timer_.Start( |
71 FROM_HERE, | 74 FROM_HERE, |
72 std::max(base::TimeDelta::FromMinutes(kMinimumUptimeInMinutes) - uptime, | 75 std::max(base::TimeDelta::FromMinutes(kMinimumUptimeInMinutes) - uptime, |
73 kZeroTimeDelta), | 76 kZeroTimeDelta), |
74 base::Bind(&DeviceCommandRebootJob::Reboot, | 77 base::Bind(&DeviceCommandRebootJob::Reboot, |
75 weak_ptr_factory_.GetWeakPtr())); | 78 weak_ptr_factory_.GetWeakPtr())); |
76 } | 79 } |
77 | 80 |
78 void DeviceCommandRebootJob::TerminateImpl() { | 81 void DeviceCommandRebootJob::TerminateImpl() { |
79 weak_ptr_factory_.InvalidateWeakPtrs(); | 82 weak_ptr_factory_.InvalidateWeakPtrs(); |
80 } | 83 } |
81 | 84 |
82 base::TimeDelta DeviceCommandRebootJob::GetCommmandTimeout() const { | 85 base::TimeDelta DeviceCommandRebootJob::GetCommmandTimeout() const { |
83 return base::TimeDelta::FromMinutes(kMinimumUptimeInMinutes); | 86 return base::TimeDelta::FromMinutes(kMinimumUptimeInMinutes); |
84 } | 87 } |
85 | 88 |
86 void DeviceCommandRebootJob::Reboot() const { | 89 void DeviceCommandRebootJob::Reboot() const { |
87 power_manager_client_->RequestRestart(); | 90 power_manager_client_->RequestRestart(); |
88 } | 91 } |
89 | 92 |
90 } // namespace policy | 93 } // namespace policy |
OLD | NEW |